Enum rustc_hir::def::Res[][src]

pub enum Res<Id = HirId> {
    Def(DefKindDefId),
    PrimTy(PrimTy),
    SelfTy(Option<DefId>, Option<(DefId, bool)>),
    ToolMod,
    SelfCtor(DefId),
    Local(Id),
    NonMacroAttr(NonMacroAttrKind),
    Err,
}
Expand description

The resolution of a path or export.

For every path or identifier in Rust, the compiler must determine what the path refers to. This process is called name resolution, and Res is the primary result of name resolution.

For example, everything prefixed with /* Res */ in this example has an associated Res:

fn str_to_string(s: & /* Res */ str) -> /* Res */ String {
    /* Res */ String::from(/* Res */ s)
}

/* Res */ str_to_string("hello");

The associated Ress will be:

  • str will resolve to Res::PrimTy;
  • String will resolve to Res::Def, and the Res will include the DefId for String as defined in the standard library;
  • String::from will also resolve to Res::Def, with the DefId pointing to String::from;
  • s will resolve to Res::Local;
  • the call to str_to_string will resolve to Res::Def, with the DefId pointing to the definition of str_to_string in the current crate.

Variants

Def(DefKindDefId)

Definition having a unique ID (DefId), corresponds to something defined in user code.

Not bound to a specific namespace.

PrimTy(PrimTy)

A primitive type such as i32 or str.

Belongs to the type namespace.

SelfTy(Option<DefId>, Option<(DefId, bool)>)

The Self type, optionally with the trait it is associated with and optionally with the DefId of the impl it is associated with.

Belongs to the type namespace.

For example, the Self in

trait Foo {
    fn foo() -> Box<Self>;
}

would have the DefId of Foo associated with it. The Self in

struct Bar;

impl Bar {
    fn new() -> Self { Bar }
}

would have the DefId of the impl associated with it. Finally, the Self in

impl Foo for Bar {
    fn foo() -> Box<Self> { Box::new(Bar) }
}

would have both the DefId of Foo and the DefId of the impl associated with it.

See also Res::SelfCtor.


HACK(min_const_generics): impl self types also have an optional requirement to not mention any generic parameters to allow the following with min_const_generics:

impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] { todo!() } }

We do however allow Self in repeat expression even if it is generic to not break code which already works on stable while causing the const_evaluatable_unchecked future compat lint.

FIXME(lazy_normalization_consts): Remove this bodge once that feature is stable.

ToolMod

A tool attribute module; e.g., the rustfmt in #[rustfmt::skip].

Belongs to the type namespace.

SelfCtor(DefId)

The Self constructor, along with the DefId of the impl it is associated with.

Belongs to the value namespace.

See also Res::SelfTy.

Local(Id)

A local variable or function parameter.

Belongs to the value namespace.

NonMacroAttr(NonMacroAttrKind)

An attribute that is not implemented via macro. E.g., #[inline] and #[rustfmt::skip], which are essentially directives, as opposed to #[test], which is a builtin macro.

Belongs to the macro namespace.

Err

Name resolution failed. We use a dummy Res variant so later phases of the compiler won’t crash and can instead report more errors.

Not bound to a specific namespace.

Implementations

Return the DefId of this Def if it has an ID, else panic.

Return Some(..) with the DefId of this Res if it has a ID, else None.

Return the DefId of this Res if it represents a module.

A human readable name for the res kind (“function”, “module”, etc.).

Gets an English article for the Res.

Returns None if this is Res::Err

Always returns true if self is Res::Err

Returns whether such a resolved path can occur in a tuple struct/variant pattern

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.