X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_hir%2Fsrc%2Fhir.rs;h=e0a3864506548f186e95c15387f8b7f7526ba1f0;hb=b4513ce6f835ed3f5c34a3ddc745d8cd3198cbf2;hp=82e260d158bc468acb5ec56372e53e49e1a4fb82;hpb=0a528b16fcee67f0ce47c88bf7b57f1bd5439bad;p=rust.git diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 82e260d158b..e0a38645065 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -487,6 +487,7 @@ pub enum GenericParamKind<'hir> { #[derive(Debug, HashStable_Generic)] pub struct GenericParam<'hir> { pub hir_id: HirId, + pub def_id: LocalDefId, pub name: ParamName, pub span: Span, pub pure_wrt_drop: bool, @@ -921,6 +922,7 @@ pub struct Crate<'hir> { #[derive(Debug, HashStable_Generic)] pub struct Closure<'hir> { + pub def_id: LocalDefId, pub binder: ClosureBinder, pub capture_clause: CaptureBy, pub bound_generic_params: &'hir [GenericParam<'hir>], @@ -1615,7 +1617,7 @@ pub enum ArrayLen { impl ArrayLen { pub fn hir_id(&self) -> HirId { match self { - &ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, body: _ }) => hir_id, + &ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, .. }) => hir_id, } } } @@ -1627,10 +1629,11 @@ pub fn hir_id(&self) -> HirId { /// explicit discriminant values for enum variants. /// /// You can check if this anon const is a default in a const param -/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_hir_id(..)` +/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_def_id(..)` #[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)] pub struct AnonConst { pub hir_id: HirId, + pub def_id: LocalDefId, pub body: BodyId, } @@ -2717,6 +2720,12 @@ pub enum IsAsync { NotAsync, } +impl IsAsync { + pub fn is_async(self) -> bool { + self == IsAsync::Async + } +} + #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)] pub enum Defaultness { Default { has_value: bool }, @@ -2798,7 +2807,8 @@ pub struct Variant<'hir> { /// Name of the variant. pub ident: Ident, /// Id of the variant (not the constructor, see `VariantData::ctor_hir_id()`). - pub id: HirId, + pub hir_id: HirId, + pub def_id: LocalDefId, /// Fields and constructor id of the variant. pub data: VariantData<'hir>, /// Explicit discriminant (e.g., `Foo = 1`). @@ -2865,6 +2875,7 @@ pub struct FieldDef<'hir> { pub vis_span: Span, pub ident: Ident, pub hir_id: HirId, + pub def_id: LocalDefId, pub ty: &'hir Ty<'hir>, } @@ -2886,11 +2897,11 @@ pub enum VariantData<'hir> { /// A tuple variant. /// /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. - Tuple(&'hir [FieldDef<'hir>], HirId), + Tuple(&'hir [FieldDef<'hir>], HirId, LocalDefId), /// A unit variant. /// /// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`. - Unit(HirId), + Unit(HirId, LocalDefId), } impl<'hir> VariantData<'hir> { @@ -2902,11 +2913,19 @@ pub fn fields(&self) -> &'hir [FieldDef<'hir>] { } } + /// Return the `LocalDefId` of this variant's constructor, if it has one. + pub fn ctor_def_id(&self) -> Option { + match *self { + VariantData::Struct(_, _) => None, + VariantData::Tuple(_, _, def_id) | VariantData::Unit(_, def_id) => Some(def_id), + } + } + /// Return the `HirId` of this variant's constructor, if it has one. pub fn ctor_hir_id(&self) -> Option { match *self { VariantData::Struct(_, _) => None, - VariantData::Tuple(_, hir_id) | VariantData::Unit(hir_id) => Some(hir_id), + VariantData::Tuple(_, hir_id, _) | VariantData::Unit(hir_id, _) => Some(hir_id), } } } @@ -3532,7 +3551,7 @@ pub fn fn_kind(self) -> Option> { /// Get the fields for the tuple-constructor, /// if this node is a tuple constructor, otherwise None pub fn tuple_fields(&self) -> Option<&'hir [FieldDef<'hir>]> { - if let Node::Ctor(&VariantData::Tuple(fields, _)) = self { Some(fields) } else { None } + if let Node::Ctor(&VariantData::Tuple(fields, _, _)) = self { Some(fields) } else { None } } } @@ -3548,7 +3567,7 @@ mod size_asserts { static_assert_size!(FnDecl<'_>, 40); static_assert_size!(ForeignItem<'_>, 72); static_assert_size!(ForeignItemKind<'_>, 40); - static_assert_size!(GenericArg<'_>, 24); + static_assert_size!(GenericArg<'_>, 32); static_assert_size!(GenericBound<'_>, 48); static_assert_size!(Generics<'_>, 56); static_assert_size!(Impl<'_>, 80);