Struct rustc_middle::ty::context::TyCtxt[][src]

pub struct TyCtxt<'tcx> {
    gcx: &'tcx GlobalCtxt<'tcx>,
}
Expand description

The central data structure of the compiler. It stores references to the various arenas and also houses the results of the various compiler queries that have been performed. See the rustc dev guide for more details.

Fields

gcx: &'tcx GlobalCtxt<'tcx>

Implementations

Returns the DefId for a given LangItem. If not found, fatally aborts compilation.

Evaluates the stability of an item.

Returns EvalResult::Allow if the item is stable, or unstable but the corresponding #![feature] has been provided. Returns EvalResult::Deny which describes the offending unstable feature otherwise.

If id is Some(_), this function will also check if the item at def_id has been deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to id.

Checks if an item is stable or error out.

If the item defined by def_id is unstable and the corresponding #![feature] does not exist, emits an error.

This function will also check if the item is deprecated. If so, and id is not None, a deprecated lint attached to id will be emitted.

Like check_stability, except that we permit items to have custom behaviour for missing stability attributes (not necessarily just emit a bug!). This is necessary for default generic parameters, which only have stability attributes if they were added after the type on which they’re defined.

Evaluates a constant without providing any substitutions. This is useful to evaluate consts that can’t take any generic arguments like statics, const items or enum discriminants. If a generic parameter is used within the constant ErrorHandled::ToGeneric will be returned.

Resolves and evaluates a constant.

The constant can be located on a trait like <A as B>::C, in which case the given substitutions and environment are used to resolve the constant. Alternatively if the constant has generic parameters in scope the substitutions are used to evaluate the value of the constant. For example in fn foo<T>() { let _ = [0; bar::<T>()]; } the repeat count constant bar::<T>() requires a substitution for T, if the substitution for T is still too generic for the constant to be evaluated then Err(ErrorHandled::TooGeneric) is returned.

Evaluate a constant.

Evaluate a static’s initializer, returning the allocation of the initializer’s memory.

Evaluate anything constant-like, returning the allocation of the final memory.

Obtains a new allocation ID that can be referenced but does not yet have an allocation backing it.

Make sure to call set_alloc_id_memory or set_alloc_id_same_memory before returning such an AllocId from a query.

Reserves a new ID if this allocation has not been dedup-reserved before. Should only be used for function pointers and statics, we don’t want to dedup IDs for “real” memory!

Generates an AllocId for a static or return a cached one in case this function has been called on the same static before.

Generates an AllocId for a function. Depending on the function type, this might get deduplicated or assigned a new ID each time.

Interns the Allocation and return a new AllocId, even if there’s already an identical Allocation with a different AllocId. Statics with identical content will still point to the same Allocation, i.e., their data will be deduplicated through Allocation interning – but they are different places in memory and as such need different IDs.

Returns None in case the AllocId is dangling. An InterpretCx can still have a local Allocation for that AllocId, but having such an AllocId in a constant is illegal and will likely ICE. This function exists to allow const eval to detect the difference between evaluation- local dangling pointers and allocations in constants/statics.

Panics in case the AllocId is dangling. Since that is impossible for AllocIds in constants (as all constants must pass interning and validation that check for dangling ids), this function is frequently used throughout rustc, but should not be used within the miri engine.

Freezes an AllocId created with reserve by pointing it at an Allocation. Trying to call this function twice, even with the same Allocation will ICE the compiler.

Freezes an AllocId created with reserve by pointing it at an Allocation. May be called twice for the same (AllocId, Allocation) pair.

Shims which make dealing with WithOptConstParam easier.

For more information on why this is needed, consider looking at the docs for WithOptConstParam itself.

An associated type was expected and a different type was found.

We perform a few different checks to see what we can suggest:

  • In the current item, look for associated functions that return the expected type and suggest calling them. (Not a structured suggestion.)
  • If any of the item’s generic bounds can be constrained, we suggest constraining the associated type to the found type.
  • If the associated type has a default type and was expected inside of a trait, we mention that this is disallowed.
  • If all other things fail, and the error is not because of a mismatch between the trait and the impl, we provide a generic help to constrain the assoc type or call an assoc fn that returns the type.

When the expected impl Trait is not defined in the current item, it will come from a return type. This can occur when dealing with TryStream (#71035).

Given a slice of hir::GenericBounds, if any of them corresponds to the trait_ref requirement, provide a structured suggestion to constrain it to a given type ty.

is_bound_surely_present indicates whether we know the bound we’re looking for is inside bounds. If that’s the case then we can consider bounds containing only one trait bound as the one we’re looking for. This can help in cases where the associated type is defined on a supertrait of the one present in the bounds.

Given a span corresponding to a bound, provide a structured suggestion to set an associated type to a given type ty.

Folds the escaping and free regions in value using f, and sets skipped_regions to true if any late-bound region was found and skipped.

Invoke callback on every region appearing free in value.

Returns true if callback returns true for every region appearing free in value.

Returns true if callback returns true for some region appearing free in value.

Replaces all regions bound by the given Binder with the results returned by the closure; the closure is expected to return a free region (relative to this binder), and hence the binder is removed in the return type. The closure is invoked once for each unique BoundRegionKind; multiple references to the same BoundRegionKind will reuse the previous result. A map is returned at the end with each bound region and the free region that replaced it.

This method only replaces late bound regions and the result may still contain escaping bound types.

Replaces all escaping bound vars. The fld_r closure replaces escaping bound regions; the fld_t closure replaces escaping bound types and the fld_c closure replaces escaping bound consts.

Replaces all types or regions bound by the given Binder. The fld_r closure replaces bound regions while the fld_t closure replaces bound types.

Replaces any late-bound regions bound in value with free variants attached to all_outlive_scope.

Returns a set of all late-bound regions that are constrained by value, meaning that if we instantiate those LBR with variables and equate value with something else, those variables will also be equated.

Returns a set of all late-bound regions that appear in value anywhere.

Replaces any late-bound regions bound in value with 'erased. Useful in codegen but also method lookup and a few other places where precise region relationships are not required.

Rewrite any late-bound regions so that they are anonymous. Region numbers are assigned starting at 0 and increasing monotonically in the order traversed by the fold operation.

The chief purpose of this function is to canonicalize regions so that two FnSigs or TraitRefs which are equivalent up to region naming will become structurally identical. For example, for<'a, 'b> fn(&'a isize, &'b isize) and for<'a, 'b> fn(&'b isize, &'a isize) will become identical after anonymization.

Checks whether a type is visibly uninhabited from a particular module.

Example

enum Void {}
mod a {
    pub mod b {
        pub struct SecretlyUninhabited {
            _priv: !,
        }
    }
}

mod c {
    pub struct AlsoSecretlyUninhabited {
        _priv: Void,
    }
    mod d {
    }
}

struct Foo {
    x: a::b::SecretlyUninhabited,
    y: c::AlsoSecretlyUninhabited,
}

In this code, the type Foo will only be visibly uninhabited inside the modules b, c and d. This effects pattern-matching on Foo or types that contain Foo.

Example

let foo_result: Result<T, Foo> = ... ;
let Ok(t) = foo_result;

This code should only compile in modules where the uninhabitedness of Foo is visible.

Computes the layout of a type. Note that this implicitly executes in “reveal all” mode.

Erase the regions in value and then fully normalize all the types found within. The result will also have regions erased.

This is appropriate to use only after type-check: it assumes that normalization will succeed, for example.

If you have a Binder<'tcx, T>, you can do this to strip out the late-bound regions and then normalize the result, yielding up a T (with regions erased). This is appropriate when the binder is being instantiated at the call site.

N.B., currently, higher-ranked type bounds inhibit normalization. Therefore, each time we erase them in codegen, we need to normalize the contents.

Monomorphizes a type from the AST by first applying the in-scope substitutions and then normalizing any associated types.

Push onto out all the things that must outlive 'a for the condition ty0: 'a to hold. Note that ty0 must be a fully resolved type.

Returns a string identifying this DefId. This string is suitable for user output.

Returns a transparent wrapper for TyCtxt, which ensures queries are executed instead of just returning their results.

Returns a transparent wrapper for TyCtxt which uses span as the location of queries performed through it.

[query description - consider adding a doc-comment!] trigger a delay span bug

[query description - consider adding a doc-comment!] get the resolver outputs

Represents crate as a whole (as distinct from the top-level crate module). If you call hir_crate (e.g., indirectly by calling tcx.hir().krate()), we will have to assume that any change means that you need to be recompiled. This is because the hir_crate query gives you access to all other items. To avoid this fate, do not call tcx.hir().krate(); instead, prefer wrappers like tcx.visit_all_items_in_krate().

The indexed HIR. This can be conveniently accessed by tcx.hir(). Avoid calling this query directly.

The items in a module.

This can be conveniently accessed by tcx.hir().visit_item_likes_in_module. Avoid calling this query directly.

Gives access to the HIR node for the HIR owner key.

This can be conveniently accessed by methods on tcx.hir(). Avoid calling this query directly.

Gives access to the HIR node’s parent for the HIR owner key.

This can be conveniently accessed by methods on tcx.hir(). Avoid calling this query directly.

Gives access to the HIR nodes and bodies inside the HIR owner key.

This can be conveniently accessed by methods on tcx.hir(). Avoid calling this query directly.

Gives access to the HIR attributes inside the HIR owner key.

This can be conveniently accessed by methods on tcx.hir(). Avoid calling this query directly.

Computes the DefId of the corresponding const parameter in case the key is a const argument and returns None otherwise.

let a = foo::<7>();
//            ^ Calling `opt_const_param_of` for this argument,

fn foo<const N: usize>()
//           ^ returns this `DefId`.

fn bar() {
// ^ While calling `opt_const_param_of` for other bodies returns `None`.
}

Given the def_id of a const-generic parameter, computes the associated default const parameter. e.g. fn example<const N: usize=3> called on N would return 3.

Records the type of every item.

[query description - consider adding a doc-comment!] running analysis passes on this crate

Maps from the DefId of an item (trait/struct/enum/fn) to its associated generics.

Maps from the DefId of an item (trait/struct/enum/fn) to the predicates (where-clauses) that must be proven true in order to reference it. This is almost always the “predicates query” that you want.

predicates_of builds on predicates_defined_on – in fact, it is almost always the same as that query, except for the case of traits. For traits, predicates_of contains an additional Self: Trait<...> predicate that users don’t actually write. This reflects the fact that to invoke the trait (e.g., via Default::default) you must supply types that actually implement the trait. (However, this extra predicate gets in the way of some checks, which are intended to operate over only the actual where-clauses written by the user.)

Returns the list of bounds that can be used for SelectionCandidate::ProjectionCandidate(_) and ProjectionTyCandidate::TraitDef. Specifically this is the bounds written on the trait’s type definition, or those after the impl keyword

type X: Bound + 'lt
//      ^^^^^^^^^^^
impl Debug + Display
//   ^^^^^^^^^^^^^^^

key is the DefId of the associated type or opaque type.

Bounds from the parent (e.g. with nested impl trait) are not included.

Elaborated version of the predicates from explicit_item_bounds.

For example:

trait MyTrait {
    type MyAType: Eq + ?Sized;
}

explicit_item_bounds returns [<Self as MyTrait>::MyAType: Eq], and item_bounds returns

[
    <Self as Trait>::MyAType: Eq,
    <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
]

Bounds from the parent (e.g. with nested impl trait) are not included.

[query description - consider adding a doc-comment!] looking up the native libraries of a linked crate

[query description - consider adding a doc-comment!] computing the lint levels for items in this crate

[query description - consider adding a doc-comment!] parent module of tcx.def_path_str(key.to_def_id())

[query description - consider adding a doc-comment!] expansion that defined tcx.def_path_str(key)

[query description - consider adding a doc-comment!] checking if the crate is_panic_runtime

Fetch the THIR for a given body. If typeck for that body failed, returns an empty Thir.

Create a THIR tree for debugging.

Set of all the DefIds in this crate that have MIR associated with them. This includes all the body owners, but also things like struct constructors.

Maps DefId’s that have an associated mir::Body to the result of the MIR const-checking pass. This is the set of qualifs in the final value of a const.

[query description - consider adding a doc-comment!] const checking the const argument tcx.def_path_str(key.0.to_def_id())

Fetch the MIR for a given DefId right after it’s built - this includes unreachable code.

Fetch the MIR for a given DefId up till the point where it is ready for const qualification.

See the README for the mir module for details.

Try to build an abstract representation of the given constant.

Try to build an abstract representation of the given constant.

[query description - consider adding a doc-comment!] trying to unify the generic constants tcx.def_path_str(key.0.0.did) and tcx.def_path_str(key.1.0.did)

[query description - consider adding a doc-comment!] elaborating drops for tcx.def_path_str(key.did.to_def_id())

[query description - consider adding a doc-comment!] caching mir of tcx.def_path_str(key) for CTFE

[query description - consider adding a doc-comment!] MIR for CTFE of the const argument tcx.def_path_str(key.0.to_def_id())

[query description - consider adding a doc-comment!] processing if key.const_param_did.is_some() { "the const argument " } else { "" } tcx.def_path_str(key.did.to_def_id())

MIR after our optimization passes have run. This is MIR that is ready for codegen. This is also the only query that can fetch non-local MIR, at present.

Returns coverage summary info for a function, after executing the InstrumentCoverage MIR pass (assuming the -Zinstrument-coverage option is enabled).

Returns the name of the file that contains the function body, if instrumented for coverage.

Returns the CodeRegions for a function that has instrumented coverage, in case the function was optimized out before codegen, and before being added to the Coverage Map.

The DefId is the DefId of the containing MIR body. Promoteds do not have their own DefId. This function returns all promoteds in the specified body. The body references promoteds by the DefId and the mir::Promoted index. This is necessary, because after inlining a body may refer to promoteds from other bodies. In that case you still need to use the DefId of the original body.

[query description - consider adding a doc-comment!] optimizing promoted MIR for the const argument tcx.def_path_str(key.0.to_def_id())

Erases regions from ty to yield a new type. Normally you would just use tcx.erase_regions(value), however, which uses this query as a kind of cache.

[query description - consider adding a doc-comment!] wasm import module map

Maps from the DefId of an item (trait/struct/enum/fn) to the predicates (where-clauses) directly defined on it. This is equal to the explicit_predicates_of predicates plus the inferred_outlives_of predicates.

Returns everything that looks like a predicate written explicitly by the user on a trait item.

Traits are unusual, because predicates on associated types are converted into bounds on that type for backwards compatibility:

trait X where Self::U: Copy { type U; }

becomes

trait X { type U: Copy; }

explicit_predicates_of and explicit_item_bounds will then take the appropriate subsets of the predicates here.

Returns the predicates written explicitly by the user.

Returns the inferred outlives predicates (e.g., for struct Foo<'a, T> { x: &'a T }, this would return T: 'a).

Maps from the DefId of a trait to the list of super-predicates. This is a subset of the full list of predicates. We store these in a separate map because we must evaluate them even during type conversion, often before the full predicates are available (note that supertraits have additional acyclicity requirements).

The Option<Ident> is the name of an associated type. If it is None, then this query returns the full set of predicates. If Some<Ident>, then the query returns only the subset of super-predicates that reference traits that define the given associated type. This is used to avoid cycles in resolving types like T::Item.

To avoid cycles within the predicates of a single item we compute per-type-parameter predicates for resolving T::AssocTy.

[query description - consider adding a doc-comment!] computing trait definition for tcx.def_path_str(key)

[query description - consider adding a doc-comment!] computing ADT definition for tcx.def_path_str(key)

[query description - consider adding a doc-comment!] computing Drop impl for tcx.def_path_str(key)

[query description - consider adding a doc-comment!] computing Sized constraints for tcx.def_path_str(key)

[query description - consider adding a doc-comment!] computing drop-check constraints for tcx.def_path_str(key)

Returns true if this is a const fn, use the is_const_fn to know whether your crate actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might not have the feature gate active).

Do not call this function manually. It is only meant to cache the base data for the is_const_fn function.

Returns true if this is a const impl. Do not call this function manually.

This query caches the base data for the is_const_impl helper function, which also takes into account stability attributes (e.g., #[rustc_const_unstable]).

[query description - consider adding a doc-comment!] checking if the function is async: tcx.def_path_str(key)

Returns true if calls to the function may be promoted.

This is either because the function is e.g., a tuple-struct or tuple-variant constructor, or because it has the #[rustc_promotable] attribute. The attribute should be removed in the future in favour of some form of check which figures out whether the function does not inspect the bits of any of its arguments (so is essentially just a constructor function).

Returns true if this is a foreign item (i.e., linked via extern { ... }).

Returns Some(mutability) if the node pointed to by def_id is a static item.

Returns Some(generator_kind) if the node pointed to by def_id is a generator.

Gets a map with the variance of every item; use item_variance instead.

Maps from the DefId of a type or region parameter to its (inferred) variance.

Maps from thee DefId of a type to its (inferred) outlives.

Maps from an impl/trait DefId to a list of the DefId`s of its items.

Maps from a trait item to the trait item “descriptor”.

Collects the associated items defined on a trait or impl.

Given an impl_id, return the trait it implements. Return None if this is an inherent impl.

[query description - consider adding a doc-comment!] computing implementation polarity of tcx.def_path_str(impl_id)

[query description - consider adding a doc-comment!] computing Self type wrt issue #33140 tcx.def_path_str(key)

Maps a DefId of a type to a list of its inherent impls. Contains implementations of methods that are inherent to a type. Methods in these implementations don’t need to be exported.

The result of unsafety-checking this LocalDefId.

[query description - consider adding a doc-comment!] unsafety-checking the const argument tcx.def_path_str(key.0.to_def_id())

Unsafety-check this LocalDefId with THIR unsafeck. This should be used with -Zthir-unsafeck.

[query description - consider adding a doc-comment!] unsafety-checking the const argument tcx.def_path_str(key.0.to_def_id())

HACK: when evaluated, this reports a “unsafe derive on repr(packed)” error.

Unsafety checking is executed for each method separately, but we only want to emit this error once per derive. As there are some impls with multiple methods, we use a query for deduplication.

The signature of functions.

[query description - consider adding a doc-comment!] linting describe_as_module(key, tcx)

Checks the attributes in the module.

[query description - consider adding a doc-comment!] checking for unstable API usage in describe_as_module(key, tcx)

Checks the const bodies in the module for illegal operations (e.g. if or loop).

Checks the loops in the module.

[query description - consider adding a doc-comment!] checking naked functions in describe_as_module(key, tcx)

[query description - consider adding a doc-comment!] checking item types in describe_as_module(key, tcx)

[query description - consider adding a doc-comment!] checking privacy in describe_as_module(key, tcx)

[query description - consider adding a doc-comment!] checking intrinsics in describe_as_module(key, tcx)

[query description - consider adding a doc-comment!] checking liveness of variables in describe_as_module(key, tcx)

[query description - consider adding a doc-comment!] checking that impls are well-formed in describe_as_module(key, tcx)

[query description - consider adding a doc-comment!] collecting item types in describe_as_module(key, tcx)

Caches CoerceUnsized kinds for impls on custom types.

[query description - consider adding a doc-comment!] type-checking all item bodies

[query description - consider adding a doc-comment!] type-checking tcx.def_path_str(key.to_def_id())

[query description - consider adding a doc-comment!] type-checking the const argument tcx.def_path_str(key.0.to_def_id())

[query description - consider adding a doc-comment!] type-checking tcx.def_path_str(key.to_def_id())

[query description - consider adding a doc-comment!] used_trait_imports tcx.def_path_str(key.to_def_id())

[query description - consider adding a doc-comment!] checking whether tcx.def_path_str(def_id) has a body

[query description - consider adding a doc-comment!] coherence checking all impls of trait tcx.def_path_str(def_id)

Borrow-checks the function body. If this is a closure, returns additional requirements that the closure’s creator must verify.

[query description - consider adding a doc-comment!] borrow-checking the const argument tcx.def_path_str(key.0.to_def_id())

Gets a complete map from all types to their inherent impls. Not meant to be used directly outside of coherence.

Checks all types in the crate for overlap in their inherent impls. Reports errors. Not meant to be used directly outside of coherence.

Check whether the function has any recursion that could cause the inliner to trigger a cycle. Returns the call stack causing the cycle. The call stack does not contain the current function, just all intermediate functions.

Obtain all the calls into other local functions

Evaluates a constant and returns the computed allocation.

Do not use this directly, use the tcx.eval_static_initializer wrapper.

Evaluates const items or anonymous constants (such as enum variant explicit discriminants or array lengths) into a representation suitable for the type system and const generics.

Do not use this directly, use one of the following wrappers: tcx.const_eval_poly, tcx.const_eval_resolve, tcx.const_eval_instance, or tcx.const_eval_global_id.

Convert an evaluated constant to a type level constant or return None if that is not possible.

Destructure a constant ADT or array into its variant index and its field values.

Dereference a constant reference or raw pointer and turn the result into a constant again.

[query description - consider adding a doc-comment!] get a &core::panic::Location referring to a span

[query description - consider adding a doc-comment!] converting literal to const

[query description - consider adding a doc-comment!] match-checking tcx.def_path_str(key)

Performs part of the privacy check and computes “access levels”.

[query description - consider adding a doc-comment!] checking for private elements in public interfaces

[query description - consider adding a doc-comment!] reachability

Per-body region::ScopeTree. The DefId should be the owner DefId for the body; in the case of closures, this will be redirected to the enclosing function.

[query description - consider adding a doc-comment!] generating MIR shim for tcx.def_path_str(key.def_id())

The symbol_name query provides the symbol name for calling a given instance from the local crate. In particular, it will also look up the correct symbol name of instances from upstream crates.

[query description - consider adding a doc-comment!] looking up definition kind of tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] looking up span for tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] looking up span for tcx.def_path_str(def_id) ’s identifier

[query description - consider adding a doc-comment!] looking up stability of tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] looking up const stability of tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] computing should_inherit_track_caller of tcx.def_path_str(def_id)

pub fn lookup_deprecation_entry(
    self,
    key: impl IntoQueryParam<DefId>
) -> lookup_deprecation_entry<'tcx>

[query description - consider adding a doc-comment!] checking whether tcx.def_path_str(def_id) is deprecated

[query description - consider adding a doc-comment!] collecting attributes of tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] computing codegen attributes of tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] looking up function parameter names for tcx.def_path_str(def_id)

Gets the rendered value of the specified constant or associated constant. Used by rustdoc.

[query description - consider adding a doc-comment!] computing specialization parent impl of tcx.def_path_str(def_id)

Given an associated_item, find the trait it belongs to. Return None if the DefId is not an associated item.

[query description - consider adding a doc-comment!] checking if item has ctfe mir available: tcx.def_path_str(key)

[query description - consider adding a doc-comment!] checking if item has mir available: tcx.def_path_str(key)

[query description - consider adding a doc-comment!] finding all vtable entries for trait tcx.def_path_str(key.def_id())

[query description - consider adding a doc-comment!] checking if tcx.def_path_str(key.1.def_id()) fulfills its obligations

Return all impl blocks in the current crate.

To allow caching this between crates, you must pass in LOCAL_CRATE as the crate number. Passing in any other crate will cause an ICE.

Given a trait trait_id, return all known impl blocks.

[query description - consider adding a doc-comment!] building specialization graph of trait tcx.def_path_str(trait_id)

[query description - consider adding a doc-comment!] determine object safety of trait tcx.def_path_str(trait_id)

Gets the ParameterEnvironment for a given item; this environment will be in “user-facing” mode, meaning that it is suitable for type-checking etc, and it does not normalize specializable associated types. This is almost always what you want, unless you are doing MIR optimizations, in which case you might want to use reveal_all() method to change modes.

Like param_env, but returns the ParamEnv in Reveal::All mode. Prefer this over tcx.param_env(def_id).with_reveal_all_normalized(tcx), as this method is more efficient.

Trait selection queries. These are best used by invoking ty.is_copy_modulo_regions(), ty.is_copy(), etc, since that will prune the environment where possible.

Query backing TyS::is_sized.

Query backing TyS::is_freeze.

Query backing TyS::is_unpin.

Query backing TyS::needs_drop.

Query backing TyS::has_significant_drop_raw.

Query backing TyS::is_structural_eq_shallow.

This is only correct for ADTs. Call is_structural_eq_shallow to handle all types correctly.

A list of types where the ADT requires drop if and only if any of those types require drop. If the ADT is known to always need drop then Err(AlwaysRequiresDrop) is returned.

A list of types where the ADT requires drop if and only if any of those types has significant drop. A type marked with the attribute rustc_insignificant_dtor is considered to not be significant. A drop is significant if it is implemented by the user or does anything that will have any observable behavior (other than freeing up memory). If the ADT is known to have a significant destructor then Err(AlwaysRequiresDrop) is returned.

[query description - consider adding a doc-comment!] computing layout of env.value

[query description - consider adding a doc-comment!] dylib dependency formats of crate

[query description - consider adding a doc-comment!] get the linkage format of all dependencies

[query description - consider adding a doc-comment!] checking if the crate is_compiler_builtins

[query description - consider adding a doc-comment!] checking if the crate has_global_allocator

[query description - consider adding a doc-comment!] checking if the crate has_panic_handler

[query description - consider adding a doc-comment!] query a crate is #![profiler_runtime]

[query description - consider adding a doc-comment!] query a crate’s configured panic strategy

[query description - consider adding a doc-comment!] test whether a crate has #![no_builtins]

[query description - consider adding a doc-comment!] query a crate’s symbol mangling version

[query description - consider adding a doc-comment!] getting crate’s ExternCrateData

[query description - consider adding a doc-comment!] computing whether impls specialize one another

[query description - consider adding a doc-comment!] traits in scope at a block

[query description - consider adding a doc-comment!] looking up items exported by tcx.def_path_str(def_id.to_def_id())

[query description - consider adding a doc-comment!] looking up whether tcx.def_path_str(def_id) is a default impl

[query description - consider adding a doc-comment!] looking up whether tcx.def_path_str(def_id) is a const impl

[query description - consider adding a doc-comment!] checking that tcx.def_path_str(key.to_def_id()) is well-formed

[query description - consider adding a doc-comment!] checking that tcx.def_path_str(key.to_def_id()) is well-formed

[query description - consider adding a doc-comment!] checking that tcx.def_path_str(key.to_def_id()) is well-formed

[query description - consider adding a doc-comment!] looking up the exported symbols of a crate

[query description - consider adding a doc-comment!] checking whether tcx.def_path_str(def_id) is an exported symbol

[query description - consider adding a doc-comment!] checking whether tcx.def_path_str(def_id.to_def_id()) is reachable from outside the crate

The entire set of monomorphizations the local crate can safely link to because they are exported from upstream crates. Do not depend on this directly, as its value changes anytime a monomorphization gets added or removed in any upstream crate. Instead use the narrower upstream_monomorphizations_for, upstream_drop_glue_for, or, even better, Instance::upstream_monomorphization().

Returns the set of upstream monomorphizations available for the generic function identified by the given def_id. The query makes sure to make a stable selection if the same monomorphization is available in multiple upstream crates.

You likely want to call Instance::upstream_monomorphization() instead of invoking this query directly.

Returns the upstream crate that exports drop-glue for the given type (substs is expected to be a single-item list containing the type one wants drop-glue for).

This is a subset of upstream_monomorphizations_for in order to increase dep-tracking granularity. Otherwise adding or removing any type with drop-glue in any upstream crate would invalidate all functions calling drop-glue of an upstream type.

You likely want to call Instance::upstream_monomorphization() instead of invoking this query directly.

NOTE: This query could easily be extended to also support other common functions that have are large set of monomorphizations (like Clone::clone for example).

[query description - consider adding a doc-comment!] looking up the foreign modules of a linked crate

Identifies the entry-point (e.g., the main function) for a given crate, returning None if there is no entry point (such as for library crates).

[query description - consider adding a doc-comment!] looking up the plugin registrar for a crate

[query description - consider adding a doc-comment!] looking up the derive registrar for a crate

[query description - consider adding a doc-comment!] looking up the hash a crate

[query description - consider adding a doc-comment!] looking up the hash of a host version of a crate

[query description - consider adding a doc-comment!] looking up the extra filename for a crate

[query description - consider adding a doc-comment!] looking up the paths for extern crates

Given a crate and a trait, look up all impls of that trait in the crate. Return (impl_id, self_ty).

Given a crate, look up all trait impls in that crate. Return (impl_id, self_ty).

[query description - consider adding a doc-comment!] is_dllimport_foreign_item( tcx.def_path_str(def_id) )

[query description - consider adding a doc-comment!] is_statically_included_foreign_item( tcx.def_path_str(def_id) )

[query description - consider adding a doc-comment!] native_library_kind( tcx.def_path_str(def_id) )

Does lifetime resolution, but does not descend into trait items. This should only be used for resolving lifetimes of on trait definitions, and is used to avoid cycles. Importantly, resolve_lifetimes still visits the same lifetimes and is responsible for diagnostics. See `rustc_resolve::late::lifetimes for details.

Does lifetime resolution on items. Importantly, we can’t resolve lifetimes directly on things like trait methods, because of trait params. See `rustc_resolve::late::lifetimes for details.

[query description - consider adding a doc-comment!] looking up a named region

[query description - consider adding a doc-comment!] testing if a region is late bound

For a given item (like a struct), gets the default lifetimes to be used for each parameter if a trait object were to be passed for that parameter. For example, for struct Foo<'a, T, U>, this would be ['static, 'static]. For struct Foo<'a, T: 'a, U>, this would instead be ['a, 'static].

[query description - consider adding a doc-comment!] looking up late bound vars

[query description - consider adding a doc-comment!] finds the lifetime scope for an HirId of a PathSegment

[query description - consider adding a doc-comment!] computing visibility of tcx.def_path_str(def_id)

Computes the set of modules from which this type is visibly uninhabited. To check whether a type is uninhabited at all (not just from a given module), you could check whether the forest is empty.

[query description - consider adding a doc-comment!] fetching what a dependency looks like

[query description - consider adding a doc-comment!] fetching what a crate is named

[query description - consider adding a doc-comment!] collecting child items of tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] computing crate imported by tcx.def_path_str(def_id.to_def_id())

[query description - consider adding a doc-comment!] calculating the lib features map

[query description - consider adding a doc-comment!] calculating the lib features defined in a crate

Returns the lang items defined in another crate by loading it from metadata.

Returns all diagnostic items defined in all crates.

Returns the lang items defined in another crate by loading it from metadata.

Returns the diagnostic items defined in a crate.

[query description - consider adding a doc-comment!] calculating the missing lang items in a crate

[query description - consider adding a doc-comment!] calculating the visible parent map

[query description - consider adding a doc-comment!] calculating trimmed def paths

[query description - consider adding a doc-comment!] seeing if we’re missing an extern crate item for this crate

[query description - consider adding a doc-comment!] looking at the source for a crate

[query description - consider adding a doc-comment!] generating a postorder list of CrateNums

Returns whether or not the crate with CrateNum ‘cnum’ is marked as a private dependency

[query description - consider adding a doc-comment!] allocator kind for the current crate

[query description - consider adding a doc-comment!] collecting upvars mentioned in tcx.def_path_str(def_id)

[query description - consider adding a doc-comment!] maybe_unused_trait_import for tcx.def_path_str(def_id.to_def_id())

[query description - consider adding a doc-comment!] looking up all possibly unused extern crates

[query description - consider adding a doc-comment!] names_imported_by_glob_use for tcx.def_path_str(def_id.to_def_id())

[query description - consider adding a doc-comment!] calculating the stability index for the local crate

[query description - consider adding a doc-comment!] fetching all foreign CrateNum instances

A vector of every trait accessible in the whole crate (i.e., including those from subcrates). This is used only for error reporting.

The list of symbols exported from the given crate.

  • All names contained in exported_symbols(cnum) are guaranteed to correspond to a publicly visible symbol in cnum machine code.
  • The exported_symbols sets of different crates do not intersect.

[query description - consider adding a doc-comment!] collect_and_partition_mono_items

[query description - consider adding a doc-comment!] determining whether tcx.def_path_str(def_id) needs codegen

All items participating in code generation together with items inlined into them.

[query description - consider adding a doc-comment!] codegen_unit

[query description - consider adding a doc-comment!] determining which generic parameters are unused by tcx.def_path_str(key)

[query description - consider adding a doc-comment!] optimization level used by backend

[query description - consider adding a doc-comment!] output_filenames

Do not call this query directly: invoke normalize instead.

Do not call this query directly: invoke normalize_erasing_regions instead.

Do not call this query directly: invoke normalize_erasing_regions instead.

[query description - consider adding a doc-comment!] computing implied outlives bounds for {:?}

Do not call this query directly: invoke infcx.at().dropck_outlives() instead.

Do not call this query directly: invoke infcx.predicate_may_hold() or infcx.predicate_must_hold() instead.

[query description - consider adding a doc-comment!] evaluating trait selection obligation goal.value

Do not call this query directly: part of the Eq type-op

Do not call this query directly: part of the Eq type-op

Do not call this query directly: part of the Subtype type-op

Do not call this query directly: part of the ProvePredicate type-op

Do not call this query directly: part of the Normalize type-op

Do not call this query directly: part of the Normalize type-op

Do not call this query directly: part of the Normalize type-op

Do not call this query directly: part of the Normalize type-op

[query description - consider adding a doc-comment!] impossible substituted predicates: tcx.def_path_str(key.0)

[query description - consider adding a doc-comment!] computing autoderef types for {:?}

[query description - consider adding a doc-comment!] looking up supported target features

Get an estimate of the size of an InstanceDef based on its MIR for CGU partitioning.

[query description - consider adding a doc-comment!] looking up enabled feature gates

Attempt to resolve the given DefId to an Instance, for the given generics args (SubstsRef), returning one of:

  • Ok(Some(instance)) on success
  • Ok(None) when the SubstsRef are still too generic, and therefore don’t allow finding the final Instance
  • Err(ErrorReported) when the Instance resolution process couldn’t complete due to errors elsewhere - this is distinct from Ok(None) to avoid misleading diagnostics when an error has already been/will be emitted, for the original cause

[query description - consider adding a doc-comment!] resolving instance of the const argument ty :: Instance :: new(key.value.0.to_def_id(), key.value.2)

[query description - consider adding a doc-comment!] normalizing opaque types in {:?}

Checks whether a type is definitely uninhabited. This is conservative: for some types that are uninhabited we return false, but we only return true for types that are definitely uninhabited. ty.conservative_is_privately_uninhabited implies that any value of type ty will be Abi::Uninhabited. (Note that uninhabited types may have nonzero size, to account for partial initialisation. See #49298 for details.)

[query description - consider adding a doc-comment!] looking up limits

Performs an HIR-based well-formed check on the item with the given HirId. If we get an Umimplemented error that matches the provided Predicate, return the cause of the newly created obligation.

This is only used by error-reporting code to get a better cause (in particular, a better span) for an existing error. Therefore, it is best-effort, and may never handle all of the cases that the normal ty::Ty-based wfcheck does. This is fine, because the ty::Ty-based wfcheck is always run.

Iterate over every impl that could possibly match the self type self_ty.

Applies function to every impl that could possibly match the self type self_ty and returns the first non-none value.

Returns an iterator containing all impls

Creates a hash of the type Ty which will be the same no matter what crate context it’s calculated within. This is used by the type_id intrinsic.

Attempts to returns the deeply last field of nested structures, but does not apply any normalization in its search. Returns the same type if input ty is not a structure at all.

Returns the deeply last field of nested structures, or the same type if not a structure at all. Corresponds to the only possible unsized field, and its type can be used to determine unsizing strategy.

Should only be called if ty has no inference variables and does not need its lifetimes preserved (e.g. as part of codegen); otherwise normalization attempt may cause compiler bugs.

Returns the deeply last field of nested structures, or the same type if not a structure at all. Corresponds to the only possible unsized field, and its type can be used to determine unsizing strategy.

This is parameterized over the normalization strategy (i.e. how to handle <T as Trait>::Assoc and impl Trait); pass the identity function to indicate no normalization should take place.

See also struct_tail_erasing_lifetimes, which is suitable for use during codegen.

Same as applying struct_tail on source and target, but only keeps going as long as the two types are instances of the same structure definitions. For (Foo<Foo<T>>, Foo<dyn Trait>), the result will be (Foo<T>, Trait), whereas struct_tail produces T, and Trait, respectively.

Should only be called if the types have no inference variables and do not need their lifetimes preserved (e.g., as part of codegen); otherwise, normalization attempt may cause compiler bugs.

Same as applying struct_tail on source and target, but only keeps going as long as the two types are instances of the same structure definitions. For (Foo<Foo<T>>, Foo<dyn Trait>), the result will be (Foo<T>, Trait), whereas struct_tail produces T, and Trait, respectively.

See also struct_lockstep_tails_erasing_lifetimes, which is suitable for use during codegen.

Calculate the destructor of a given type.

Returns the set of types that are required to be alive in order to run the destructor of def (see RFCs 769 and 1238).

Note that this returns only the constraints for the destructor of def itself. For the destructors of the contents, you need adt_dtorck_constraint.

Returns true if def_id refers to a closure (e.g., |x| x * 2). Note that closures have a DefId, but the closure expression also has a HirId that is located within the context where the closure appears (and, sadly, a corresponding NodeId, since those are not yet phased out). The parent of the closure’s DefId will also be the context where it appears.

Returns true if def_id refers to a trait (i.e., trait Foo { ... }).

Returns true if def_id refers to a trait alias (i.e., trait Foo = ...;), and false otherwise.

Returns true if this DefId refers to the implicit constructor for a tuple struct like struct Foo(u32), and false otherwise.

Given the def-ID of a fn or closure, returns the def-ID of the innermost fn item that the closure is contained within. This is a significant DefId because, when we do type-checking, we type-check this fn item and all of its (transitive) closures together. Therefore, when we fetch the typeck the closure, for example, we really wind up fetching the typeck the enclosing fn item.

Given the DefId and substs a closure, creates the type of self argument that the closure expects. For example, for a Fn closure, this would return a reference type &T where T = closure_ty.

Returns None if this closure’s kind has not yet been inferred. This should only be possible during type checking.

Note that the return value is a late-bound region and hence wrapped in a binder.

Returns true if the node pointed to by def_id is a static item.

Returns true if this is a static item with the #[thread_local] attribute.

Returns true if the node pointed to by def_id is a mutable static item.

Get the type of the pointer to the static that we use in MIR.

Expands the given impl trait type, stopping if the type is recursive.

Retrieves an allocation that represents the contents of a vtable. There’s a cache within TyCtxt so it will be deduplicated.

Allocates a read-only byte or string literal for mir::interpret.

Returns a range of the start/end indices specified with the rustc_layout_scalar_valid_range attribute.

Creates a type context and call the closure with a TyCtxt reference to the context. The closure enforces that the type context and any interned value (types, substs, etc.) can only be used while ty::tls has a valid reference to the context, to allow formatting values that need it.

Constructs a TyKind::Error type and registers a delay_span_bug to ensure it gets used.

Constructs a TyKind::Error type and registers a delay_span_bug with the given msg to ensure it gets used.

Like err but for constants.

Obtain all lang items of this crate and all dependencies (recursively)

Obtain the given diagnostic item’s DefId. Use is_diagnostic_item if you just want to compare against another DefId, since is_diagnostic_item is cheaper.

Check whether the diagnostic item with the given name has the given DefId.

Converts a DefId into its fully expanded DefPath (every DefId is really just an interned DefPath).

Note that if id is not local to this crate, the result will be a non-local DefPath.

Note that this is untracked and should only be used within the query system if the result is otherwise tracked through queries

Note that this is untracked and should only be used within the query system if the result is otherwise tracked through queries

If true, we should use the MIR-based borrowck, but also fall back on the AST borrowck if the MIR-based one errors.

What mode(s) of borrowck should we run? AST? MIR? both? (Also considers the #![feature(nll)] setting.)

If true, we should use lazy normalization for constants, otherwise we still evaluate them eagerly.

Given a DefId for an fn, return all the dyn and impl traits in its return type.

Determines whether identifiers in the assembly have strict naming rules. Currently, only NVPTX* targets need it.

Returns &'static core::panic::Location<'static>.

Returns a displayable description and article for the given def_id (e.g. ("a", "struct")).

Given a fn type, returns an equivalent unsafe fn type; that is, a fn type that is equivalent in every way for being unsafe.

Given the def_id of a Trait trait_def_id and the name of an associated item assoc_name returns true if the trait_def_id defines an associated item of name assoc_name.

Computes the def-ids of the transitive super-traits of trait_def_id. This (intentionally) does not compute the full elaborated super-predicates but just the set of def-ids. It is used to identify which traits may define a given associated type to help avoid cycle errors. Returns a DefId iterator.

Given a closure signature, returns an equivalent fn signature. Detuples and so forth – so e.g., if we have a sig with Fn<(u32, i32)> then you would get a fn(u32, i32). unsafety determines the unsafety of the fn signature. If you pass hir::Unsafety::Unsafe in the previous example, then you would get an unsafe fn (u32, i32). It cannot convert a closure that requires unsafe.

Same a self.mk_region(kind), but avoids accessing the interners if *r == kind.

This method copies Place’s projection, add an element and reintern it. Should not be used to build a full Place it’s just a convenient way to grab a projection and modify it in flight.

Walks upwards from id to find a node which might change lint levels with attributes. It stops at bound and just returns it if reached.

Returns an equivalent value with all free regions removed (note that late-bound regions remain, because they are important for subtyping, but they are anonymized and normalized as well)..

Returns an iterator of the DefIds for all body-owners in this crate. If you would prefer to iterate over the bodies themselves, you can do self.hir().krate().body_ids.iter().

Look up the name of an item across crates. This does not look at HIR.

When possible, this function should be used for cross-crate lookups over opt_item_name to avoid invalidating the incremental cache. If you need to handle items without a name, or HIR items that will not be serialized cross-crate, or if you need the span of the item, use opt_item_name instead.

Look up the name and span of an item or Node.

See item_name for more information.

Returns true if the impls are the same polarity and the trait either has no items or is annotated #[marker] and prevents item overrides.

Returns ty::VariantDef if res refers to a struct, or variant or their constructors, panics otherwise.

Returns the possibly-auto-generated MIR of a (DefId, Subst) pair.

Gets the attributes of a definition.

Determines whether an item is annotated with an attribute.

Returns true if this is an auto trait.

Returns layout of a generator. Layout might be unavailable if the generator is tainted by errors.

Given the DefId of an impl, returns the DefId of the trait it implements. If it implements no trait, returns None.

If the given defid describes a method belonging to an impl, returns the DefId of the impl that the method belongs to; otherwise, returns None.

Looks up the span of impl_did if the impl is local; otherwise returns Err with the name of the crate containing the impl.

Hygienically compares a use-site name (use_name) for a field or an associated item with its supposed definition name (def_name). The method also needs DefId of the supposed definition’s parent/scope to perform comparison.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Create a hashing context for hashing new results.

Access the DepGraph.

Access the profiler.

Access the compiler session.

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more

This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if can_reconstruct_query_key() is true. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. Read more

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more

This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if can_reconstruct_query_key() is true. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. Read more

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more

This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if can_reconstruct_query_key() is true. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. Read more

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more

This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if can_reconstruct_query_key() is true. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. Read more

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more

This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if can_reconstruct_query_key() is true. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. Read more

This method turns the parameters of a DepNodeConstructor into an opaque Fingerprint to be used in DepNode. Not all DepNodeParams support being turned into a Fingerprint (they don’t need to if the corresponding DepNode is anonymous). Read more

This method tries to recover the query key from the given DepNode, something which is needed when forcing DepNodes during red-green evaluation. The query system will only call this method if can_reconstruct_query_key() is true. It is always valid to return None here, in which case incremental compilation will treat the query as having changed instead of forcing it. Read more

The resulting type after dereferencing.

Dereferences the value.

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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 be different between compiler versions and platforms. 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: 8 bytes