Expand description

Trait Resolution. See the rustc dev guide for more information on how this works.



  • Support code for rustdoc and external tools. You really don’t want to be using this unless you need to.
  • Defines a Chalk-based TraitEngine
  • coherence 🔒
    See Rustc Dev Guide chapters on trait-resolution and trait-specialization for more info on how this works.
  • Checking that constant values used in types can be successfully evaluated.
  • engine 🔒
  • fulfill 🔒
  • Miscellaneous type-system utilities that are too small to deserve their own modules.
  • “Object safety” refers to the ability for a trait to be converted to an object. In general, traits may only be converted to an object if all of their methods meet certain criteria. In particular, they must:
  • project 🔒
    Code for projecting associated types out of trait references.
  • Experimental types for the trait query interface. The methods defined in this module are all based on canonicalization, which makes a canonical query by replacing unbound inference variables and regions, so that results can be reused more broadly. The providers for the queries defined here can be found in rustc_traits.
  • select 🔒
    Candidate selection. See the rustc dev guide for more information on how this works.
  • specialize 🔒
    Logic and data structures related to impl specialization, explained in greater detail below.
  • util 🔒
  • vtable 🔒






  • Returns the object safety violations that affect astconv – currently, Self in supertraits. This is needed because object_safety_violations can’t be used during type collection.
  • Normalize a type and process all resulting obligations, returning any errors
  • Given an upcast trait object described by object, returns the index of the method method_def_id (which should be part of object.upcast_trait_ref) within the vtable for object.
  • Normalizes the predicates and checks whether they hold in an empty environment. If this returns true, then either normalize encountered an error or one of the predicates did not hold. Used when creating vtables to check for unsatisfiable methods.
  • Checks whether a trait’s method is impossible to call on a given impl.
  • We say a method is vtable safe if it can be invoked on a trait object. Note that object-safe traits can have some non-vtable-safe methods, so long as they require Self: Sized or otherwise ensure that they cannot be used when Self = Trait.
  • Normalizes the parameter environment, reporting errors if they occur.
  • The guts of normalize: normalize a specific projection like <T as Trait>::Item. The result is always a type (and possibly additional obligations). If ambiguity arises, which implies that there are unresolved type variables in the projection, we will substitute a fresh type variable $X and generate a new obligation <T as Trait>::Item == $X for later.
  • Checks the coherence orphan rules. impl_def_id should be the DefId of a trait impl. To pass, either the trait must be local, or else two conditions must be satisfied:
  • If there are types that satisfy both impls, returns Some with a suitably-freshened ImplHeader with those types substituted. Otherwise, returns None.
  • FIXME(@lcnr): this function doesn’t seem right and shouldn’t exist?
  • Creates predicate obligations from the generic bounds.
  • This method traverses the structure of ty, trying to find any types that are not allowed to be used in a const generic.
  • This method traverses the structure of ty, trying to find an instance of an ADT (i.e. struct or enum) that doesn’t implement the structural-match traits, or a generic type parameter (which cannot be determined to be structural-match).
  • A specialized variant of elaborate_trait_refs that only elaborates trait references that may define the given associated type assoc_name. It uses the super_predicates_that_define_assoc_type query to avoid enumerating super-predicates that aren’t related to assoc_item. This is used when resolving types like Self::Item or T::Item and helps to avoid cycle errors (see e.g. #35237).
  • Given a subst for the requested impl, translate it to a subst appropriate for the actual item definition (whether it be in that impl, a parent impl, or the trait).
  • Determines whether the type ty is known to meet bound and returns true if so. Returns false if ty either does not meet bound or is not known to meet bound (note that this is conservative towards no impl, which is the opposite of the evaluate methods).
  • Casts a trait reference into a reference to one of its super traits; returns None if target_trait_def_id is not a supertrait.

Type Definitions

Opaque Types

  •  🔒