pub trait TypeErrCtxtExt<'a, 'tcx> {
Show 39 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<'_>,
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<'a>;
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<'_>,
);
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: Upcast<TyCtxt<'tcx>, Predicate<'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>;
fn suggest_add_result_as_return_type(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
);
fn suggest_unsized_bound_if_applicable(
&self,
err: &mut Diag<'_>,
obligation: &PredicateObligation<'tcx>,
);
fn suggest_indirection_for_unsized(
&self,
err: &mut Diag<'_>,
item: &Item<'tcx>,
param: &GenericParam<'tcx>,
) -> bool;
}
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, )
sourcefn suggest_dereferences(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx>, ) -> bool
When after several dereferencing, the reference satisfies the trait bound. This function provides dereference suggestion for this specific situation.
sourcefn get_closure_name(
&self,
def_id: DefId,
err: &mut Diag<'_>,
msg: Cow<'static, str>,
) -> Option<Symbol>
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.
sourcefn suggest_fn_call(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
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 bound. If it would, suggest calling
it: bar(foo)
→ bar(foo())
. This case is very likely to be hit if foo
is async
.
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
sourcefn extract_callable_info(
&self,
body_id: LocalDefId,
param_env: ParamEnv<'tcx>,
found: Ty<'tcx>,
) -> Option<(DefIdOrName, Ty<'tcx>, Vec<Ty<'tcx>>)>
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.
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>, )
sourcefn suggest_remove_reference(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
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.
fn suggest_remove_await( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, )
sourcefn suggest_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
)
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.
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>
sourcefn suggest_impl_trait(
&self,
err: &mut Diag<'_>,
obligation: &PredicateObligation<'tcx>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
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.
fn point_at_returns_when_relevant( &self, err: &mut Diag<'_>, 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<'a>
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<'_>, )
fn suggest_fully_qualified_path( &self, err: &mut Diag<'_>, item_def_id: DefId, span: Span, trait_ref: DefId, )
sourcefn maybe_note_obligation_cause_for_async_await<G: EmissionGuarantee>(
&self,
err: &mut Diag<'_, G>,
obligation: &PredicateObligation<'tcx>,
) -> bool
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.
sourcefn 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_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.
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>, )
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>))>>
sourcefn suggest_convert_to_slice(
&self,
err: &mut Diag<'_>,
obligation: &PredicateObligation<'tcx>,
trait_ref: PolyTraitRef<'tcx>,
candidate_impls: &[ImplCandidate<'tcx>],
span: Span,
)
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.
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>
fn suggest_add_result_as_return_type( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx>, )
fn suggest_unsized_bound_if_applicable( &self, err: &mut Diag<'_>, obligation: &PredicateObligation<'tcx>, )
fn suggest_indirection_for_unsized( &self, err: &mut Diag<'_>, item: &Item<'tcx>, param: &GenericParam<'tcx>, ) -> bool
Object Safety§
Implementations on Foreign Types§
source§impl<'a, 'tcx> TypeErrCtxtExt<'a, 'tcx> for TypeErrCtxt<'a, 'tcx>
impl<'a, 'tcx> TypeErrCtxtExt<'a, 'tcx> for TypeErrCtxt<'a, 'tcx>
source§fn suggest_dereferences(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
fn suggest_dereferences( &self, obligation: &PredicateObligation<'tcx>, err: &mut Diag<'_>, trait_pred: PolyTraitPredicate<'tcx>, ) -> bool
When after several dereferencing, the reference satisfies the trait bound. 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>
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
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 bound. 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>>)>
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 Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
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_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
err: &mut Diag<'_>,
trait_pred: PolyTraitPredicate<'tcx>,
)
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_impl_trait(
&self,
err: &mut Diag<'_>,
obligation: &PredicateObligation<'tcx>,
trait_pred: PolyTraitPredicate<'tcx>,
) -> bool
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 maybe_note_obligation_cause_for_async_await<G: EmissionGuarantee>(
&self,
err: &mut Diag<'_, G>,
obligation: &PredicateObligation<'tcx>,
) -> bool
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>>,
)
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 suggest_convert_to_slice(
&self,
err: &mut Diag<'_>,
obligation: &PredicateObligation<'tcx>,
trait_ref: PolyTraitRef<'tcx>,
candidate_impls: &[ImplCandidate<'tcx>],
span: Span,
)
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.