pub trait TypeErrCtxtExt<'tcx> {
Show 36 methods // Required methods fn suggest_restricting_param_bound( &self, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx>, associated_ty: Option<(&'static str, Ty<'tcx>)>, body_id: LocalDefId ); fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ) -> bool; fn get_closure_name( &self, def_id: DefId, err: &mut Diag<'_>, msg: Cow<'static, str> ) -> Option<Symbol>; fn suggest_fn_call( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ) -> bool; fn check_for_binding_assigned_block_without_tail_expression( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ); fn suggest_add_clone_to_arg( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ) -> bool; fn extract_callable_info( &self, body_id: LocalDefId, param_env: ParamEnv<'tcx>, found: Ty<'tcx> ) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)>; fn suggest_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, poly_trait_pred: PolyTraitPredicate<'tcx>, has_custom_message: bool ) -> bool; fn suggest_borrowing_for_object_cast( &self, err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, self_ty: Ty<'tcx>, target_ty: Ty<'tcx> ); fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ) -> bool; fn suggest_remove_await( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_> ); fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ); fn suggest_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, span: Span, trait_pred: PolyTraitPredicate<'tcx> ) -> bool; fn return_type_span( &self, obligation: &PredicateObligation<'tcx> ) -> Option<Span>; fn suggest_impl_trait( &self, err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_pred: PolyTraitPredicate<'tcx> ) -> bool; fn point_at_returns_when_relevant( &self, err: &mut Diag<'tcx>, obligation: &PredicateObligation<'tcx> ); fn report_closure_arg_mismatch( &self, span: Span, found_span: Option<Span>, found: TraitRef<'tcx>, expected: TraitRef<'tcx>, cause: &ObligationCauseCode<'tcx>, found_node: Option<Node<'_>>, param_env: ParamEnv<'tcx> ) -> Diag<'tcx>; fn note_conflicting_fn_args( &self, err: &mut Diag<'_>, cause: &ObligationCauseCode<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, param_env: ParamEnv<'tcx> ); fn note_conflicting_closure_bounds( &self, cause: &ObligationCauseCode<'tcx>, err: &mut Diag<'tcx> ); fn suggest_fully_qualified_path( &self, err: &mut Diag<'_>, item_def_id: DefId, span: Span, trait_ref: DefId ); fn maybe_note_obligation_cause_for_async_await<G: EmissionGuarantee>( &self, err: &mut Diag<'_, G>, obligation: &PredicateObligation<'tcx> ) -> bool; fn note_obligation_cause_for_async_await<G: EmissionGuarantee>( &self, err: &mut Diag<'_, G>, 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>> ); fn note_obligation_cause_code<G: EmissionGuarantee, T>( &self, body_id: LocalDefId, err: &mut Diag<'_, G>, 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>; fn suggest_await_before_try( &self, err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_pred: PolyTraitPredicate<'tcx>, span: Span ); fn suggest_floating_point_literal( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_ref: &PolyTraitRef<'tcx> ); fn suggest_derive( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ); fn suggest_dereferencing_index( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> ); fn note_function_argument_obligation<G: EmissionGuarantee>( &self, body_id: LocalDefId, err: &mut Diag<'_, G>, arg_hir_id: HirId, parent_code: &ObligationCauseCode<'tcx>, param_env: ParamEnv<'tcx>, failed_pred: Predicate<'tcx>, call_hir_id: HirId ); fn suggest_option_method_if_applicable<G: EmissionGuarantee>( &self, failed_pred: Predicate<'tcx>, param_env: ParamEnv<'tcx>, err: &mut Diag<'_, G>, expr: &Expr<'_> ); fn look_for_iterator_item_mistakes<G: EmissionGuarantee>( &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 Diag<'_, G> ); fn point_at_chain<G: EmissionGuarantee>( &self, expr: &Expr<'_>, typeck_results: &TypeckResults<'tcx>, type_diffs: Vec<TypeError<'tcx>>, param_env: ParamEnv<'tcx>, err: &mut Diag<'_, G> ); 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>))>>; fn suggest_convert_to_slice( &self, err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_ref: PolyTraitRef<'tcx>, candidate_impls: &[ImplCandidate<'tcx>], span: Span ); fn explain_hrtb_projection( &self, diag: &mut Diag<'_>, pred: PolyTraitPredicate<'tcx>, param_env: ParamEnv<'tcx>, cause: &ObligationCause<'tcx> ); fn suggest_desugaring_async_fn_in_trait( &self, err: &mut Diag<'_>, trait_ref: PolyTraitRef<'tcx> ); fn ty_kind_suggestion( &self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx> ) -> Option<String>;
}

Required Methods§

source

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

source

fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, 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 Diag<'_>, 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 Diag<'_>, 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 check_for_binding_assigned_block_without_tail_expression( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx> )

source

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

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_add_reference_to_arg( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, poly_trait_pred: PolyTraitPredicate<'tcx>, has_custom_message: bool ) -> bool

source

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

source

fn suggest_remove_reference( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, 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_remove_await( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_> )

source

fn suggest_change_mut( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, 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_semicolon_removal( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, span: Span, trait_pred: PolyTraitPredicate<'tcx> ) -> bool

source

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

source

fn suggest_impl_trait( &self, err: &mut Diag<'_>, 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 point_at_returns_when_relevant( &self, err: &mut Diag<'tcx>, obligation: &PredicateObligation<'tcx> )

source

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

source

fn note_conflicting_fn_args( &self, err: &mut Diag<'_>, 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 Diag<'tcx> )

source

fn suggest_fully_qualified_path( &self, err: &mut Diag<'_>, item_def_id: DefId, span: Span, trait_ref: DefId )

source

fn maybe_note_obligation_cause_for_async_await<G: EmissionGuarantee>( &self, err: &mut Diag<'_, G>, 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<G: EmissionGuarantee>( &self, err: &mut Diag<'_, G>, 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 note_obligation_cause_code<G: EmissionGuarantee, T>( &self, body_id: LocalDefId, err: &mut Diag<'_, G>, 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 Diag<'_>, obligation: &PredicateObligation<'tcx>, trait_pred: PolyTraitPredicate<'tcx>, span: Span )

source

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

source

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

source

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

source

fn note_function_argument_obligation<G: EmissionGuarantee>( &self, body_id: LocalDefId, err: &mut Diag<'_, G>, 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<G: EmissionGuarantee>( &self, failed_pred: Predicate<'tcx>, param_env: ParamEnv<'tcx>, err: &mut Diag<'_, G>, expr: &Expr<'_> )

source

fn look_for_iterator_item_mistakes<G: EmissionGuarantee>( &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 Diag<'_, G> )

source

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

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 suggest_convert_to_slice( &self, err: &mut Diag<'_>, 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 explain_hrtb_projection( &self, diag: &mut Diag<'_>, pred: PolyTraitPredicate<'tcx>, param_env: ParamEnv<'tcx>, cause: &ObligationCause<'tcx> )

source

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

source

fn ty_kind_suggestion( &self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx> ) -> Option<String>

Object Safety§

This trait is not object safe.

Implementors§

source§

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