Struct rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError
source · [−]pub struct NiceRegionError<'cx, 'tcx> {
infcx: &'cx InferCtxt<'cx, 'tcx>,
error: Option<RegionResolutionError<'tcx>>,
regions: Option<(Span, Region<'tcx>, Region<'tcx>)>,
}Fields
infcx: &'cx InferCtxt<'cx, 'tcx>error: Option<RegionResolutionError<'tcx>>regions: Option<(Span, Region<'tcx>, Region<'tcx>)>Implementations
Print the error message for lifetime errors when both the concerned regions are anonymous.
Consider a case where we have
fn foo(x: &mut Vec<&u8>, y: &u8) {
x.push(y);
}The example gives
fn foo(x: &mut Vec<&u8>, y: &u8) {
--- --- these references are declared with different lifetimes...
x.push(y);
^ ...but data from `y` flows into `x` hereIt has been extended for the case of structs too.
Consider the example
struct Ref<'a> { x: &'a u32 }fn foo(mut x: Vec<Ref>, y: Ref) {
--- --- these structs are declared with different lifetimes...
x.push(y);
^ ...but data from `y` flows into `x` here
}It will later be extended to trait objects.
fn suggest_adding_lifetime_params(
&self,
sub: Region<'tcx>,
ty_sup: &Ty<'_>,
ty_sub: &Ty<'_>,
err: &mut DiagnosticBuilder<'_>
)
When given a ConcreteFailure for a function with parameters containing a named region and
an anonymous region, emit an descriptive diagnostic error.
When given a ConcreteFailure for a function with arguments containing a named region and
an anonymous region, emit a descriptive diagnostic error.
fn try_report_trait_placeholder_mismatch(
&self,
vid: Option<Region<'tcx>>,
cause: &ObligationCause<'tcx>,
sub_placeholder: Option<Region<'tcx>>,
sup_placeholder: Option<Region<'tcx>>,
value_pairs: &ValuePairs<'tcx>
) -> Option<DiagnosticBuilder<'tcx>>
fn report_trait_placeholder_mismatch(
&self,
vid: Option<Region<'tcx>>,
cause: &ObligationCause<'tcx>,
sub_placeholder: Option<Region<'tcx>>,
sup_placeholder: Option<Region<'tcx>>,
trait_def_id: DefId,
expected_substs: SubstsRef<'tcx>,
actual_substs: SubstsRef<'tcx>
) -> DiagnosticBuilder<'tcx>
fn explain_actual_impl_that_was_found(
&self,
err: &mut DiagnosticBuilder<'_>,
sub_placeholder: Option<Region<'tcx>>,
sup_placeholder: Option<Region<'tcx>>,
has_sub: Option<usize>,
has_sup: Option<usize>,
expected_trait_ref: TraitRef<'tcx>,
actual_trait_ref: TraitRef<'tcx>,
vid: Option<Region<'tcx>>,
expected_has_vid: Option<usize>,
actual_has_vid: Option<usize>,
any_self_ty_has_vid: bool,
leading_ellipsis: bool
)
fn explain_actual_impl_that_was_found(
&self,
err: &mut DiagnosticBuilder<'_>,
sub_placeholder: Option<Region<'tcx>>,
sup_placeholder: Option<Region<'tcx>>,
has_sub: Option<usize>,
has_sup: Option<usize>,
expected_trait_ref: TraitRef<'tcx>,
actual_trait_ref: TraitRef<'tcx>,
vid: Option<Region<'tcx>>,
expected_has_vid: Option<usize>,
actual_has_vid: Option<usize>,
any_self_ty_has_vid: bool,
leading_ellipsis: bool
)
Add notes with details about the expected and actual trait refs, with attention to cases when placeholder regions are involved: either the trait or the self type containing them needs to be mentioned the closest to the placeholders. This makes the error messages read better, however at the cost of some complexity due to the number of combinations we have to deal with.
Print the error message for lifetime errors when the return type is a static impl Trait,
dyn Trait or if a method call on a trait object introduces a static requirement.
fn get_impl_ident_and_self_ty_from_trait(
&self,
def_id: DefId,
trait_objects: &FxHashSet<DefId>
) -> Option<(Ident, &'tcx Ty<'tcx>)>
fn find_impl_on_dyn_trait(
&self,
err: &mut DiagnosticBuilder<'_>,
ty: Ty<'_>,
ctxt: &UnifyReceiverContext<'tcx>
) -> bool
fn find_impl_on_dyn_trait(
&self,
err: &mut DiagnosticBuilder<'_>,
ty: Ty<'_>,
ctxt: &UnifyReceiverContext<'tcx>
) -> bool
When we call a method coming from an impl Foo for dyn Bar, dyn Bar introduces a default
'static obligation. Suggest relaxing that implicit bound.
fn suggest_constrain_dyn_trait_in_impl(
&self,
err: &mut DiagnosticBuilder<'_>,
found_dids: &FxHashSet<DefId>,
ident: Ident,
self_ty: &Ty<'_>
) -> bool
Print the error message for lifetime errors when the impl doesn’t conform to the trait.
pub(super) fn find_param_with_region(
&self,
anon_region: Region<'tcx>,
replace_region: Region<'tcx>
) -> Option<AnonymousParamInfo<'_>>
pub(super) fn is_return_type_anon(
&self,
scope_def_id: LocalDefId,
br: BoundRegionKind,
decl: &FnDecl<'_>
) -> Option<Span>
pub fn new_from_span(
infcx: &'cx InferCtxt<'cx, 'tcx>,
span: Span,
sub: Region<'tcx>,
sup: Region<'tcx>
) -> Self
Auto Trait Implementations
impl<'cx, 'tcx> !RefUnwindSafe for NiceRegionError
impl<'cx, 'tcx> !Send for NiceRegionError
impl<'cx, 'tcx> !Sync for NiceRegionError
impl<'cx, 'tcx> Unpin for NiceRegionError where
'tcx: 'cx,
impl<'cx, 'tcx> !UnwindSafe for NiceRegionError
Blanket Implementations
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 184 bytes