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

pub enum Res<Id = HirId> {
    Def(DefKind, DefId),
    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(DefKind, DefId)
Expand description

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

Not bound to a specific namespace.

PrimTy(PrimTy)
Expand description

A primitive type such as i32 or str.

Belongs to the type namespace.

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

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
Expand description

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

Belongs to the type namespace.

SelfCtor(DefId)
Expand description

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)
Expand description

A local variable or function parameter.

Belongs to the value namespace.

NonMacroAttr(NonMacroAttrKind)
Expand description

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
Expand description

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

impl<Id> Res<Id>[src]

pub fn def_id(&self) -> DefId where
    Id: Debug, 
[src]

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

pub fn opt_def_id(&self) -> Option<DefId>[src]

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

pub fn mod_def_id(&self) -> Option<DefId>[src]

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

pub fn descr(&self) -> &'static str[src]

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

pub fn article(&self) -> &'static str[src]

Gets an English article for the Res.

pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Res<R>[src]

pub fn macro_kind(self) -> Option<MacroKind>[src]

pub fn ns(&self) -> Option<Namespace>[src]

Returns None if this is Res::Err

pub fn matches_ns(&self, ns: Namespace) -> bool[src]

Always returns true if self is Res::Err

pub fn expected_in_tuple_struct_pat(&self) -> bool[src]

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

Trait Implementations

impl<Id: Clone> Clone for Res<Id>[src]

fn clone(&self) -> Res<Id>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<Id: Debug> Debug for Res<Id>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<Id, __D: Decoder> Decodable<__D> for Res<Id> where
    Id: Decodable<__D>, 
[src]

fn decode(__decoder: &mut __D) -> Result<Self, <__D as Decoder>::Error>[src]

impl<Id, __E: Encoder> Encodable<__E> for Res<Id> where
    Id: Encodable<__E>, 
[src]

fn encode(&self, __encoder: &mut __E) -> Result<(), <__E as Encoder>::Error>[src]

impl<Id: Hash> Hash for Res<Id>[src]

fn hash<__H: Hasher>(&self, state: &mut __H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher, 
1.3.0[src]

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

impl<Id, __CTX> HashStable<__CTX> for Res<Id> where
    __CTX: HashStableContext,
    Id: HashStable<__CTX>, 
[src]

fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)[src]

impl<Id: PartialEq> PartialEq<Res<Id>> for Res<Id>[src]

fn eq(&self, other: &Res<Id>) -> bool[src]

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

fn ne(&self, other: &Res<Id>) -> bool[src]

This method tests for !=.

impl<Id: Copy> Copy for Res<Id>[src]

impl<Id: Eq> Eq for Res<Id>[src]

impl<Id> StructuralEq for Res<Id>[src]

impl<Id> StructuralPartialEq for Res<Id>[src]

Auto Trait Implementations

impl<Id> RefUnwindSafe for Res<Id> where
    Id: RefUnwindSafe, 

impl<Id> Send for Res<Id> where
    Id: Send, 

impl<Id> Sync for Res<Id> where
    Id: Sync, 

impl<Id> Unpin for Res<Id> where
    Id: Unpin, 

impl<Id> UnwindSafe for Res<Id> where
    Id: UnwindSafe, 

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone, 
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.