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

Gets the parent trait chain start

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

Returns true if the trait predicate may apply for some assignment to the type parameters.

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

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

When after several dereferencing, the reference satisfies the trait binding. This function provides dereference suggestion for this specific situation.

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.

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.

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.

Check if the trait bound is implemented for a different mutability and note it in the final error.

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.

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.

Unconditionally adds the diagnostic note described in maybe_note_obligation_cause_for_async_await’s documentation comment.

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

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.

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).

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. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion 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: 24 bytes