Type Alias rustc_resolve::imports::Res

source ·
type Res = Res<NodeId>;

Aliased Type§

enum Res {
    Def(DefKind, DefId),
    PrimTy(PrimTy),
    SelfTyParam {
        trait_: DefId,
    },
    SelfTyAlias {
        alias_to: DefId,
        forbid_generic: bool,
        is_trait_impl: bool,
    },
    SelfCtor(DefId),
    Local(NodeId),
    ToolMod,
    NonMacroAttr(NonMacroAttrKind),
    Err,
}

Variants§

§

Def(DefKind, DefId)

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.

§

SelfTyParam

Fields

§trait_: DefId

The trait this Self is a generic parameter for.

The Self type, as used within a trait.

Belongs to the type namespace.

See the examples on [Res::SelfTyAlias] for details.

§

SelfTyAlias

Fields

§alias_to: DefId

The item introducing the Self type alias. Can be used in the type_of query to get the underlying type.

§forbid_generic: bool

Whether the Self type is disallowed from mentioning generics (i.e. when used in an anonymous constant).

HACK(min_const_generics): 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!() } }

struct Bar([u8; baz::<Self>()]);
const fn baz<T>() -> usize { 10 }

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:

fn foo<T>() {
    let _bar = [1_u8; std::mem::size_of::<*mut T>()];
}
§is_trait_impl: bool

Is this within an impl Foo for bar?

The Self type, as used somewhere other than within a trait.

Belongs to the type namespace.

Examples:

struct Bar(Box<Self>); // SelfTyAlias

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

impl Bar {
    fn blah() {
        let _: Self; // SelfTyAlias
    }
}

impl Foo for Bar {
    fn foo() -> Box<Self> { // SelfTyAlias
        let _: Self;        // SelfTyAlias

        todo!()
    }
}

See also [Res::SelfCtor].

§

SelfCtor(DefId)

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

Belongs to the value namespace.

See also [Res::SelfTyParam] and [Res::SelfTyAlias].

§

Local(NodeId)

A local variable or function parameter.

Belongs to the value namespace.

§

ToolMod

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

Belongs to the type 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.

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: 12 bytes

Size for each variant:

  • Def: 11 bytes
  • PrimTy: 2 bytes
  • SelfTyParam: 11 bytes
  • SelfTyAlias: 11 bytes
  • SelfCtor: 11 bytes
  • Local: 7 bytes
  • ToolMod: 0 bytes
  • NonMacroAttr: 7 bytes
  • Err: 0 bytes