pub struct TypeErrCtxt<'a, 'tcx> {
    pub infcx: &'a InferCtxt<'tcx>,
    pub typeck_results: Option<Ref<'a, TypeckResults<'tcx>>>,
    pub fallback_has_occurred: bool,
    pub normalize_fn_sig: Box<dyn Fn(Binder<'tcx, FnSig<'tcx>>) -> Binder<'tcx, FnSig<'tcx>> + 'a>,
    pub autoderef_steps: Box<dyn Fn(Ty<'tcx>) -> Vec<(Ty<'tcx>, Vec<Obligation<'tcx, Predicate<'tcx>>>)> + 'a>,
}
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_ctxt or FnCtxt::err_ctxt.

You must only create this if you intend to actually emit an error. This provides a lot of utility methods which should not be used during the happy path.

Fields§

§infcx: &'a InferCtxt<'tcx>§typeck_results: Option<Ref<'a, TypeckResults<'tcx>>>§fallback_has_occurred: bool§normalize_fn_sig: Box<dyn Fn(Binder<'tcx, FnSig<'tcx>>) -> Binder<'tcx, FnSig<'tcx>> + 'a>§autoderef_steps: Box<dyn Fn(Ty<'tcx>) -> Vec<(Ty<'tcx>, Vec<Obligation<'tcx, Predicate<'tcx>>>)> + 'a>

Trait Implementations§

source§

impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx>

source§

fn get_parent_trait_ref( &self, code: &ObligationCauseCode<'tcx> ) -> Option<(Ty<'tcx>, Option<Span>)>

Gets the parent trait chain start

source§

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

source§

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.

source§

fn error_implies(&self, cond: Predicate<'tcx>, error: Predicate<'tcx>) -> bool

source§

fn report_fulfillment_error(&self, error: &FulfillmentError<'tcx>)

source§

fn report_projection_error( &self, obligation: &PredicateObligation<'tcx>, error: &MismatchedProjectionTypes<'tcx> )

source§

fn maybe_detailed_projection_msg( &self, pred: ProjectionPredicate<'tcx>, normalized_ty: Term<'tcx>, expected_ty: Term<'tcx> ) -> Option<String>

source§

fn fuzzy_match_tys( &self, a: Ty<'tcx>, b: Ty<'tcx>, ignoring_lifetimes: bool ) -> Option<CandidateSimilarity>

source§

fn describe_closure(&self, kind: ClosureKind) -> &'static str

source§

fn find_similar_impl_candidates( &self, trait_pred: PolyTraitPredicate<'tcx> ) -> Vec<ImplCandidate<'tcx>>

source§

fn report_similar_impl_candidates( &self, impl_candidates: &[ImplCandidate<'tcx>], trait_ref: PolyTraitRef<'tcx>, body_def_id: LocalDefId, err: &mut Diagnostic, other: bool, param_env: ParamEnv<'tcx> ) -> bool

source§

fn report_similar_impl_candidates_for_root_obligation( &self, obligation: &PredicateObligation<'tcx>, trait_predicate: Binder<'tcx, TraitPredicate<'tcx>>, body_def_id: LocalDefId, err: &mut Diagnostic )

source§

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>

Creates a PredicateObligation with new_self_ty replacing the existing type in the trait_ref. Read more
source§

fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>)

source§

fn annotate_source_of_ambiguity( &self, err: &mut Diagnostic, ambiguities: &[Ambiguity], predicate: Predicate<'tcx> )

source§

fn note_obligation_cause( &self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx> )

source§

fn suggest_unsized_bound_if_applicable( &self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx> )

source§

fn maybe_suggest_unsized_generics( &self, err: &mut Diagnostic, span: Span, node: Node<'tcx> )

source§

fn maybe_indirection_for_unsized( &self, err: &mut Diagnostic, item: &Item<'tcx>, param: &GenericParam<'tcx> ) -> bool

source§

fn is_recursive_obligation( &self, obligated_types: &mut Vec<Ty<'tcx>>, cause_code: &ObligationCauseCode<'tcx> ) -> bool

source§

fn get_standard_error_message( &self, trait_predicate: &PolyTraitPredicate<'tcx>, message: Option<String>, predicate_is_const: bool, append_const_msg: Option<AppendConstMessage>, post_message: String ) -> String

source§

fn get_safe_transmute_error_and_reason( &self, obligation: PredicateObligation<'tcx>, trait_ref: PolyTraitRef<'tcx>, span: Span ) -> GetSafeTransmuteErrorAndReason

source§

fn add_tuple_trait_message( &self, obligation_cause_code: &ObligationCauseCode<'tcx>, err: &mut Diagnostic )

source§

fn try_to_add_help_message( &self, obligation: &PredicateObligation<'tcx>, trait_ref: PolyTraitRef<'tcx>, trait_predicate: &PolyTraitPredicate<'tcx>, err: &mut Diagnostic, span: Span, is_fn_trait: bool, suggested: bool, unsatisfied_const: bool )

source§

fn add_help_message_for_fn_trait( &self, trait_ref: PolyTraitRef<'tcx>, err: &mut Diagnostic, implemented_kind: ClosureKind, params: Binder<'tcx, Ty<'tcx>> )

source§

fn maybe_add_note_for_unsatisfied_const( &self, _obligation: &PredicateObligation<'tcx>, _trait_ref: PolyTraitRef<'tcx>, _trait_predicate: &PolyTraitPredicate<'tcx>, _err: &mut Diagnostic, _span: Span ) -> UnsatisfiedConst

source§

fn report_closure_error( &self, obligation: &PredicateObligation<'tcx>, closure_def_id: DefId, found_kind: ClosureKind, kind: ClosureKind ) -> DiagnosticBuilder<'tcx>

source§

fn report_type_parameter_mismatch_cyclic_type_error( &self, obligation: &PredicateObligation<'tcx>, found_trait_ref: Binder<'tcx, TraitRef<'tcx>>, expected_trait_ref: Binder<'tcx, TraitRef<'tcx>>, terr: TypeError<'tcx> ) -> DiagnosticBuilder<'tcx>

source§

fn report_opaque_type_auto_trait_leakage( &self, obligation: &PredicateObligation<'tcx>, def_id: DefId ) -> DiagnosticBuilder<'tcx>

source§

fn report_type_parameter_mismatch_error( &self, obligation: &PredicateObligation<'tcx>, span: Span, found_trait_ref: Binder<'tcx, TraitRef<'tcx>>, expected_trait_ref: Binder<'tcx, TraitRef<'tcx>> ) -> Option<DiagnosticBuilder<'tcx>>

source§

fn report_not_const_evaluatable_error( &self, obligation: &PredicateObligation<'tcx>, span: Span ) -> Option<DiagnosticBuilder<'tcx>>

source§

impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>

source§

fn describe_enclosure(&self, def_id: LocalDefId) -> Option<&'static str>

Used to set on_unimplemented’s ItemContext to be the enclosing (async) block/function/closure

source§

fn impl_similar_to( &self, trait_ref: PolyTraitRef<'tcx>, obligation: &PredicateObligation<'tcx> ) -> Option<(DefId, GenericArgsRef<'tcx>)>

source§

fn on_unimplemented_note( &self, trait_ref: PolyTraitRef<'tcx>, obligation: &PredicateObligation<'tcx> ) -> OnUnimplementedNote

source§

impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>

source§

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.

source§

fn get_closure_name( &self, def_id: DefId, err: &mut Diagnostic, msg: Cow<'static, 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.

source§

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.

source§

fn extract_callable_info( &self, body_id: LocalDefId, param_env: ParamEnv<'tcx>, found: Ty<'tcx> ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)>

Extracts information about a callable type for diagnostics. This is a heuristic – it doesn’t necessarily mean that a type is always callable, because the callable type must also be well-formed to be called.

source§

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.

source§

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.

source§

fn suggest_impl_trait( &self, err: &mut Diagnostic, 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.

source§

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 here

When 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 here

Returns true if an async-await specific note was added to the diagnostic.

source§

fn note_obligation_cause_for_async_await( &self, err: &mut Diagnostic, interior_or_upvar_span: CoroutineInteriorOrUpvar, is_async: bool, outer_coroutine: Option<DefId>, trait_pred: TraitPredicate<'tcx>, target_ty: Ty<'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.

source§

fn suggest_convert_to_slice( &self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, trait_ref: PolyTraitRef<'tcx>, candidate_impls: &[ImplCandidate<'tcx>], span: Span )

If the type that failed selection is an array or a reference to an array, but the trait is implemented for slices, suggest that the user converts the array into a slice.

source§

fn suggest_restricting_param_bound( &self, err: &mut Diagnostic, trait_pred: PolyTraitPredicate<'tcx>, associated_ty: Option<(&'static str, Ty<'tcx>)>, body_id: LocalDefId )

source§

fn check_for_binding_assigned_block_without_tail_expression( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, trait_pred: PolyTraitPredicate<'tcx> )

source§

fn suggest_add_clone_to_arg( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, trait_pred: PolyTraitPredicate<'tcx> ) -> bool

source§

fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, poly_trait_pred: PolyTraitPredicate<'tcx>, has_custom_message: bool ) -> bool

source§

fn suggest_borrowing_for_object_cast( &self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, self_ty: Ty<'tcx>, target_ty: Ty<'tcx> )

source§

fn suggest_remove_await( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic )

source§

fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, span: Span, trait_pred: PolyTraitPredicate<'tcx> ) -> bool

source§

fn return_type_span( &self, obligation: &PredicateObligation<'tcx> ) -> Option<Span>

source§

fn point_at_returns_when_relevant( &self, err: &mut DiagnosticBuilder<'tcx>, obligation: &PredicateObligation<'tcx> )

source§

fn report_closure_arg_mismatch( &self, span: Span, found_span: Option<Span>, found: PolyTraitRef<'tcx>, expected: PolyTraitRef<'tcx>, cause: &ObligationCauseCode<'tcx>, found_node: Option<Node<'_>>, param_env: ParamEnv<'tcx> ) -> DiagnosticBuilder<'tcx>

source§

fn note_conflicting_fn_args( &self, err: &mut Diagnostic, cause: &ObligationCauseCode<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, param_env: ParamEnv<'tcx> )

source§

fn note_conflicting_closure_bounds( &self, cause: &ObligationCauseCode<'tcx>, err: &mut DiagnosticBuilder<'tcx> )

source§

fn suggest_fully_qualified_path( &self, err: &mut Diagnostic, item_def_id: DefId, span: Span, trait_ref: DefId )

source§

fn note_obligation_cause_code<T>( &self, body_id: LocalDefId, 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: ToPredicate<'tcx>,

source§

fn suggest_await_before_try( &self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>, trait_pred: PolyTraitPredicate<'tcx>, span: Span )

Suggest to await before try: future? => future.await?
source§

fn suggest_floating_point_literal( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, trait_ref: &PolyTraitRef<'tcx> )

source§

fn suggest_derive( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, trait_pred: PolyTraitPredicate<'tcx> )

source§

fn suggest_dereferencing_index( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diagnostic, trait_pred: PolyTraitPredicate<'tcx> )

source§

fn note_function_argument_obligation( &self, body_id: LocalDefId, err: &mut Diagnostic, arg_hir_id: HirId, parent_code: &ObligationCauseCode<'tcx>, param_env: ParamEnv<'tcx>, failed_pred: Predicate<'tcx>, call_hir_id: HirId )

source§

fn suggest_option_method_if_applicable( &self, failed_pred: Predicate<'tcx>, param_env: ParamEnv<'tcx>, err: &mut Diagnostic, expr: &Expr<'_> )

source§

fn look_for_iterator_item_mistakes( &self, assocs_in_this_method: &[Option<(Span, (DefId, Ty<'tcx>))>], typeck_results: &TypeckResults<'tcx>, type_diffs: &[TypeError<'tcx>], param_env: ParamEnv<'tcx>, path_segment: &PathSegment<'_>, args: &[Expr<'_>], err: &mut Diagnostic )

source§

fn point_at_chain( &self, expr: &Expr<'_>, typeck_results: &TypeckResults<'tcx>, type_diffs: Vec<TypeError<'tcx>>, param_env: ParamEnv<'tcx>, err: &mut Diagnostic )

source§

fn probe_assoc_types_at_expr( &self, type_diffs: &[TypeError<'tcx>], span: Span, prev_ty: Ty<'tcx>, body_id: HirId, param_env: ParamEnv<'tcx> ) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>>

source§

fn explain_hrtb_projection( &self, diag: &mut Diagnostic, pred: PolyTraitPredicate<'tcx>, param_env: ParamEnv<'tcx>, cause: &ObligationCause<'tcx> )

source§

fn suggest_desugaring_async_fn_in_trait( &self, err: &mut Diagnostic, trait_ref: PolyTraitRef<'tcx> )

source§

impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx>

source§

fn report_overflow_error<T>( &self, predicate: &T, span: Span, suggest_increasing_limit: bool, mutate: impl FnOnce(&mut Diagnostic) ) -> !
where T: Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, '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.

source§

fn report_overflow_obligation<T>( &self, obligation: &Obligation<'tcx, T>, suggest_increasing_limit: bool ) -> !
where T: ToPredicate<'tcx> + Clone,

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.

source§

fn report_overflow_obligation_cycle( &self, cycle: &[PredicateObligation<'tcx>] ) -> !

Reports that a cycle was detected which led to overflow and halts compilation. This is equivalent to report_overflow_obligation 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).

source§

fn try_conversion_context( &self, obligation: &PredicateObligation<'tcx>, trait_ref: TraitRef<'tcx>, err: &mut Diagnostic ) -> bool

When the E of the resulting Result<T, E> in an expression foo().bar().baz()?, identify thoe method chain sub-expressions that could or could not have been annotated with ?.

source§

fn report_fulfillment_errors( &self, errors: Vec<FulfillmentError<'tcx>> ) -> ErrorGuaranteed

source§

fn build_overflow_error<T>( &self, predicate: &T, span: Span, suggest_increasing_limit: bool ) -> DiagnosticBuilder<'tcx>
where T: Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,

source§

fn suggest_new_overflow_limit(&self, err: &mut Diagnostic)

source§

fn report_overflow_no_abort( &self, obligation: PredicateObligation<'tcx> ) -> ErrorGuaranteed

source§

fn report_selection_error( &self, obligation: PredicateObligation<'tcx>, root_obligation: &PredicateObligation<'tcx>, error: &SelectionError<'tcx> )

The 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.
source§

fn emit_specialized_closure_kind_error( &self, obligation: &PredicateObligation<'tcx>, trait_ref: PolyTraitRef<'tcx> ) -> Option<ErrorGuaranteed>

source§

fn fn_arg_obligation(&self, obligation: &PredicateObligation<'tcx>) -> bool

source§

fn report_const_param_not_wf( &self, ty: Ty<'tcx>, obligation: &PredicateObligation<'tcx> ) -> DiagnosticBuilder<'tcx>

Auto 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>

§

impl<'a, 'tcx> !UnwindSafe for TypeErrCtxt<'a, 'tcx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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: 64 bytes