Struct rustc_trait_selection::infer::error_reporting::TypeErrCtxt
source · pub struct TypeErrCtxt<'a, 'tcx> {
pub infcx: &'a InferCtxt<'tcx>,
pub typeck_results: Option<Ref<'a, TypeckResults<'tcx>>>,
}Expand description
A helper for building type related errors. The typeck_results
field is only populated during an in-progress typeck.
Get an instance by calling InferCtxt::err or FnCtxt::infer_err.
Fields
infcx: &'a InferCtxt<'tcx>typeck_results: Option<Ref<'a, TypeckResults<'tcx>>>Trait Implementations
sourceimpl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx>
impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx>
sourcefn get_parent_trait_ref(
&self,
code: &ObligationCauseCode<'tcx>
) -> Option<(String, Option<Span>)>
fn get_parent_trait_ref(
&self,
code: &ObligationCauseCode<'tcx>
) -> Option<(String, Option<Span>)>
Gets the parent trait chain start
sourcefn note_version_mismatch(
&self,
err: &mut Diagnostic,
trait_ref: &PolyTraitRef<'tcx>
) -> bool
fn note_version_mismatch(
&self,
err: &mut Diagnostic,
trait_ref: &PolyTraitRef<'tcx>
) -> bool
If the Self type of the unsatisfied trait trait_ref implements a trait
with the same path as trait_ref, a help message about
a probable version mismatch is added to err
sourcefn predicate_can_apply(
&self,
param_env: ParamEnv<'tcx>,
pred: PolyTraitPredicate<'tcx>
) -> bool
fn predicate_can_apply(
&self,
param_env: ParamEnv<'tcx>,
pred: PolyTraitPredicate<'tcx>
) -> bool
Returns true if the trait predicate may apply for some assignment
to the type parameters.
fn error_implies(&self, cond: Predicate<'tcx>, error: Predicate<'tcx>) -> bool
fn report_fulfillment_error(
&self,
error: &FulfillmentError<'tcx>,
body_id: Option<BodyId>,
fallback_has_occurred: bool
)
fn report_projection_error(
&self,
obligation: &PredicateObligation<'tcx>,
error: &MismatchedProjectionTypes<'tcx>
)
fn maybe_detailed_projection_msg(
&self,
pred: ProjectionPredicate<'tcx>,
normalized_ty: Term<'tcx>,
expected_ty: Term<'tcx>
) -> Option<String>
fn fuzzy_match_tys(
&self,
a: Ty<'tcx>,
b: Ty<'tcx>,
ignoring_lifetimes: bool
) -> Option<CandidateSimilarity>
fn describe_generator(&self, body_id: BodyId) -> Option<&'static str>
fn find_similar_impl_candidates(
&self,
trait_pred: PolyTraitPredicate<'tcx>
) -> Vec<ImplCandidate<'tcx>>
fn report_similar_impl_candidates(
&self,
impl_candidates: Vec<ImplCandidate<'tcx>>,
trait_ref: PolyTraitRef<'tcx>,
body_id: HirId,
err: &mut Diagnostic
) -> bool
sourcefn mk_trait_obligation_with_new_self_ty(
&self,
param_env: ParamEnv<'tcx>,
trait_ref_and_ty: Binder<'tcx, (TraitPredicate<'tcx>, Ty<'tcx>)>
) -> PredicateObligation<'tcx>
fn mk_trait_obligation_with_new_self_ty(
&self,
param_env: ParamEnv<'tcx>,
trait_ref_and_ty: Binder<'tcx, (TraitPredicate<'tcx>, Ty<'tcx>)>
) -> PredicateObligation<'tcx>
PredicateObligation with new_self_ty replacing the existing type in the
trait_ref. Read morefn maybe_report_ambiguity(
&self,
obligation: &PredicateObligation<'tcx>,
body_id: Option<BodyId>
)
fn annotate_source_of_ambiguity(
&self,
err: &mut Diagnostic,
impls: &[DefId],
predicate: Predicate<'tcx>
)
fn note_obligation_cause(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>
)
fn suggest_unsized_bound_if_applicable(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>
)
fn maybe_suggest_unsized_generics(
&self,
err: &mut Diagnostic,
span: Span,
node: Node<'tcx>
)
fn maybe_indirection_for_unsized(
&self,
err: &mut Diagnostic,
item: &Item<'tcx>,
param: &GenericParam<'tcx>
) -> bool
fn is_recursive_obligation(
&self,
obligated_types: &mut Vec<Ty<'tcx>>,
cause_code: &ObligationCauseCode<'tcx>
) -> bool
sourceimpl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>
sourcefn describe_enclosure(&self, hir_id: HirId) -> Option<&'static str>
fn describe_enclosure(&self, hir_id: HirId) -> Option<&'static str>
Used to set on_unimplemented’s ItemContext
to be the enclosing (async) block/function/closure
fn impl_similar_to(
&self,
trait_ref: PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>
) -> Option<(DefId, SubstsRef<'tcx>)>
fn on_unimplemented_note(
&self,
trait_ref: PolyTraitRef<'tcx>,
obligation: &PredicateObligation<'tcx>
) -> OnUnimplementedNote
sourceimpl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>
sourcefn suggest_dereferences(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
fn suggest_dereferences(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
When after several dereferencing, the reference satisfies the trait binding. This function provides dereference suggestion for this specific situation.
sourcefn get_closure_name(
&self,
def_id: DefId,
err: &mut Diagnostic,
msg: &str
) -> Option<Symbol>
fn get_closure_name(
&self,
def_id: DefId,
err: &mut Diagnostic,
msg: &str
) -> Option<Symbol>
Given a closure’s DefId, return the given name of the closure.
This doesn’t account for reassignments, but it’s only used for suggestions.
sourcefn suggest_fn_call(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
fn suggest_fn_call(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
We tried to apply the bound to an fn or closure. Check whether calling it would
evaluate to a type that would satisfy the trait binding. If it would, suggest calling
it: bar(foo) → bar(foo()). This case is very likely to be hit if foo is async.
sourcefn suggest_remove_reference(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
fn suggest_remove_reference(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
Whenever references are used by mistake, like for (i, e) in &vec.iter().enumerate(),
suggest removing these references until we reach a type that implements the trait.
sourcefn suggest_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
)
fn suggest_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
)
Check if the trait bound is implemented for a different mutability and note it in the final error.
sourcefn suggest_impl_trait(
&self,
err: &mut Diagnostic,
span: Span,
obligation: &PredicateObligation<'tcx>,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
fn suggest_impl_trait(
&self,
err: &mut Diagnostic,
span: Span,
obligation: &PredicateObligation<'tcx>,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
If all conditions are met to identify a returned dyn Trait, suggest using impl Trait if
applicable and signal that the error has been expanded appropriately and needs to be
emitted.
sourcefn maybe_note_obligation_cause_for_async_await(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>
) -> bool
fn maybe_note_obligation_cause_for_async_await(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>
) -> bool
Adds an async-await specific note to the diagnostic when the future does not implement an auto trait because of a captured type.
note: future does not implement `Qux` as this value is used across an await
--> $DIR/issue-64130-3-other.rs:17:5
|
LL | let x = Foo;
| - has type `Foo`
LL | baz().await;
| ^^^^^^^^^^^ await occurs here, with `x` maybe used later
LL | }
| - `x` is later dropped hereWhen the diagnostic does not implement Send or Sync specifically, then the diagnostic
is “replaced” with a different message and a more specific error.
error: future cannot be sent between threads safely
--> $DIR/issue-64130-2-send.rs:21:5
|
LL | fn is_send<T: Send>(t: T) { }
| ---- required by this bound in `is_send`
...
LL | is_send(bar());
| ^^^^^^^ future returned by `bar` is not send
|
= help: within `impl std::future::Future`, the trait `std::marker::Send` is not
implemented for `Foo`
note: future is not send as this value is used across an await
--> $DIR/issue-64130-2-send.rs:15:5
|
LL | let x = Foo;
| - has type `Foo`
LL | baz().await;
| ^^^^^^^^^^^ await occurs here, with `x` maybe used later
LL | }
| - `x` is later dropped hereReturns true if an async-await specific note was added to the diagnostic.
sourcefn note_obligation_cause_for_async_await(
&self,
err: &mut Diagnostic,
interior_or_upvar_span: GeneratorInteriorOrUpvar,
interior_extra_info: Option<(Option<Span>, Span, Option<HirId>, Option<Span>)>,
is_async: bool,
outer_generator: Option<DefId>,
trait_pred: TraitPredicate<'tcx>,
target_ty: Ty<'tcx>,
typeck_results: Option<&TypeckResults<'tcx>>,
obligation: &PredicateObligation<'tcx>,
next_code: Option<&ObligationCauseCode<'tcx>>
)
fn note_obligation_cause_for_async_await(
&self,
err: &mut Diagnostic,
interior_or_upvar_span: GeneratorInteriorOrUpvar,
interior_extra_info: Option<(Option<Span>, Span, Option<HirId>, Option<Span>)>,
is_async: bool,
outer_generator: Option<DefId>,
trait_pred: TraitPredicate<'tcx>,
target_ty: Ty<'tcx>,
typeck_results: Option<&TypeckResults<'tcx>>,
obligation: &PredicateObligation<'tcx>,
next_code: Option<&ObligationCauseCode<'tcx>>
)
Unconditionally adds the diagnostic note described in
maybe_note_obligation_cause_for_async_await’s documentation comment.
fn suggest_restricting_param_bound(
&self,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>,
associated_ty: Option<(&'static str, Ty<'tcx>)>,
body_id: HirId
)
fn suggest_add_reference_to_arg(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
poly_trait_pred: PolyTraitPredicate<'tcx>,
has_custom_message: bool
) -> bool
fn suggest_borrowing_for_object_cast(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
self_ty: Ty<'tcx>,
object_ty: Ty<'tcx>
)
fn suggest_remove_await(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic
)
fn suggest_semicolon_removal(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
span: Span,
trait_pred: PolyTraitPredicate<'tcx>
) -> bool
fn return_type_span(
&self,
obligation: &PredicateObligation<'tcx>
) -> Option<Span>
fn point_at_returns_when_relevant(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>
)
fn report_closure_arg_mismatch(
&self,
span: Span,
found_span: Option<Span>,
found: PolyTraitRef<'tcx>,
expected: PolyTraitRef<'tcx>,
cause: &ObligationCauseCode<'tcx>
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
fn note_conflicting_closure_bounds(
&self,
cause: &ObligationCauseCode<'tcx>,
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>
)
fn suggest_fully_qualified_path(
&self,
err: &mut Diagnostic,
item_def_id: DefId,
span: Span,
trait_ref: DefId
)
fn note_obligation_cause_code<T>(
&self,
err: &mut Diagnostic,
predicate: &T,
param_env: ParamEnv<'tcx>,
cause_code: &ObligationCauseCode<'tcx>,
obligated_types: &mut Vec<Ty<'tcx>>,
seen_requirements: &mut FxHashSet<DefId>
)where
T: Display,
sourcefn suggest_await_before_try(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
trait_pred: PolyTraitPredicate<'tcx>,
span: Span
)
fn suggest_await_before_try(
&self,
err: &mut Diagnostic,
obligation: &PredicateObligation<'tcx>,
trait_pred: PolyTraitPredicate<'tcx>,
span: Span
)
fn suggest_floating_point_literal(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_ref: &PolyTraitRef<'tcx>
)
fn suggest_derive(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
)
fn suggest_dereferencing_index(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diagnostic,
trait_pred: PolyTraitPredicate<'tcx>
)
sourceimpl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>
sourcefn report_overflow_error<T>(
&self,
obligation: &Obligation<'tcx, T>,
suggest_increasing_limit: bool
) -> !where
T: Display + TypeFoldable<'tcx>,
fn report_overflow_error<T>(
&self,
obligation: &Obligation<'tcx, T>,
suggest_increasing_limit: bool
) -> !where
T: Display + TypeFoldable<'tcx>,
Reports that an overflow has occurred and halts compilation. We halt compilation unconditionally because it is important that overflows never be masked – they basically represent computations whose result could not be truly determined and thus we can’t say if the program type checks or not – and they are unusual occurrences in any case.
sourcefn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> !
fn report_overflow_error_cycle(&self, cycle: &[PredicateObligation<'tcx>]) -> !
Reports that a cycle was detected which led to overflow and halts
compilation. This is equivalent to report_overflow_error except
that we can give a more helpful error message (and, in particular,
we do not suggest increasing the overflow limit, which is not
going to help).
fn report_fulfillment_errors(
&self,
errors: &[FulfillmentError<'tcx>],
body_id: Option<BodyId>,
fallback_has_occurred: bool
) -> ErrorGuaranteed
fn suggest_new_overflow_limit(&self, err: &mut Diagnostic)
sourcefn report_selection_error(
&self,
obligation: PredicateObligation<'tcx>,
root_obligation: &PredicateObligation<'tcx>,
error: &SelectionError<'tcx>,
fallback_has_occurred: bool
)
fn report_selection_error(
&self,
obligation: PredicateObligation<'tcx>,
root_obligation: &PredicateObligation<'tcx>,
error: &SelectionError<'tcx>,
fallback_has_occurred: bool
)
root_obligation parameter should be the root_obligation field
from a FulfillmentError. If no FulfillmentError is available,
then it should be the same as obligation. Read moreAuto Trait Implementations
impl<'a, 'tcx> !RefUnwindSafe for TypeErrCtxt<'a, 'tcx>
impl<'a, 'tcx> !Send for TypeErrCtxt<'a, 'tcx>
impl<'a, 'tcx> !Sync for TypeErrCtxt<'a, 'tcx>
impl<'a, 'tcx> Unpin for TypeErrCtxt<'a, 'tcx>where
'tcx: 'a,
impl<'a, 'tcx> !UnwindSafe for TypeErrCtxt<'a, 'tcx>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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: 24 bytes