Skip to content

Commit ad44d42

Browse files
authored
Rollup merge of rust-lang#63543 - c410-f3r:variant, r=c410-f3r
Merge Variant and Variant_ Extracted from rust-lang#63468.
2 parents d4ecc6f + 6a42b0b commit ad44d42

File tree

46 files changed

+162
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+162
-166
lines changed

src/librustc/hir/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
336336
fn is_c_like_enum(item: &hir::Item) -> bool {
337337
if let hir::ItemKind::Enum(ref def, _) = item.node {
338338
for variant in &def.variants {
339-
match variant.node.data {
339+
match variant.data {
340340
hir::VariantData::Unit(..) => { /* continue */ }
341341
_ => { return false; }
342342
}

src/librustc/hir/intravisit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,15 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
577577
variant: &'v Variant,
578578
generics: &'v Generics,
579579
parent_item_id: HirId) {
580-
visitor.visit_ident(variant.node.ident);
581-
visitor.visit_id(variant.node.id);
582-
visitor.visit_variant_data(&variant.node.data,
583-
variant.node.ident.name,
580+
visitor.visit_ident(variant.ident);
581+
visitor.visit_id(variant.id);
582+
visitor.visit_variant_data(&variant.data,
583+
variant.ident.name,
584584
generics,
585585
parent_item_id,
586586
variant.span);
587-
walk_list!(visitor, visit_anon_const, &variant.node.disr_expr);
588-
walk_list!(visitor, visit_attribute, &variant.node.attrs);
587+
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
588+
walk_list!(visitor, visit_attribute, &variant.attrs);
589589
}
590590

591591
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {

src/librustc/hir/lowering/item.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,12 @@ impl LoweringContext<'_> {
757757
}
758758

759759
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
760-
Spanned {
761-
node: hir::VariantKind {
762-
ident: v.node.ident,
763-
id: self.lower_node_id(v.node.id),
764-
attrs: self.lower_attrs(&v.node.attrs),
765-
data: self.lower_variant_data(&v.node.data),
766-
disr_expr: v.node.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
767-
},
760+
hir::Variant {
761+
attrs: self.lower_attrs(&v.attrs),
762+
data: self.lower_variant_data(&v.data),
763+
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
764+
id: self.lower_node_id(v.id),
765+
ident: v.ident,
768766
span: v.span,
769767
}
770768
}

src/librustc/hir/map/collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,11 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
544544
}
545545

546546
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: HirId) {
547-
self.insert(v.span, v.node.id, Node::Variant(v));
548-
self.with_parent(v.node.id, |this| {
547+
self.insert(v.span, v.id, Node::Variant(v));
548+
self.with_parent(v.id, |this| {
549549
// Register the constructor of this variant.
550-
if let Some(ctor_hir_id) = v.node.data.ctor_hir_id() {
551-
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.node.data));
550+
if let Some(ctor_hir_id) = v.data.ctor_hir_id() {
551+
this.insert(v.span, ctor_hir_id, Node::Ctor(&v.data));
552552
}
553553
intravisit::walk_variant(this, v, g, item_id);
554554
});

src/librustc/hir/map/def_collector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
155155
}
156156

157157
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
158-
let def = self.create_def(v.node.id,
159-
DefPathData::TypeNs(v.node.ident.as_interned_str()),
158+
let def = self.create_def(v.id,
159+
DefPathData::TypeNs(v.ident.as_interned_str()),
160160
v.span);
161161
self.with_parent(def, |this| {
162-
if let Some(ctor_hir_id) = v.node.data.ctor_id() {
162+
if let Some(ctor_hir_id) = v.data.ctor_id() {
163163
this.create_def(ctor_hir_id, DefPathData::Ctor, v.span);
164164
}
165165
visit::walk_variant(this, v, g, item_id)

src/librustc/hir/map/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl<'hir> Map<'hir> {
907907
_ => bug!("struct ID bound to non-struct {}", self.node_to_string(id))
908908
}
909909
}
910-
Some(Node::Variant(variant)) => &variant.node.data,
910+
Some(Node::Variant(variant)) => &variant.data,
911911
Some(Node::Ctor(data)) => data,
912912
_ => bug!("expected struct or variant, found {}", self.node_to_string(id))
913913
}
@@ -940,7 +940,7 @@ impl<'hir> Map<'hir> {
940940
Node::ForeignItem(fi) => fi.ident.name,
941941
Node::ImplItem(ii) => ii.ident.name,
942942
Node::TraitItem(ti) => ti.ident.name,
943-
Node::Variant(v) => v.node.ident.name,
943+
Node::Variant(v) => v.ident.name,
944944
Node::Field(f) => f.ident.name,
945945
Node::Lifetime(lt) => lt.name.ident().name,
946946
Node::GenericParam(param) => param.name.ident().name,
@@ -961,7 +961,7 @@ impl<'hir> Map<'hir> {
961961
Some(Node::ForeignItem(fi)) => Some(&fi.attrs[..]),
962962
Some(Node::TraitItem(ref ti)) => Some(&ti.attrs[..]),
963963
Some(Node::ImplItem(ref ii)) => Some(&ii.attrs[..]),
964-
Some(Node::Variant(ref v)) => Some(&v.node.attrs[..]),
964+
Some(Node::Variant(ref v)) => Some(&v.attrs[..]),
965965
Some(Node::Field(ref f)) => Some(&f.attrs[..]),
966966
Some(Node::Expr(ref e)) => Some(&*e.attrs),
967967
Some(Node::Stmt(ref s)) => Some(s.node.attrs()),
@@ -1155,7 +1155,7 @@ impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() }
11551155

11561156
impl Named for Item { fn name(&self) -> Name { self.ident.name } }
11571157
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
1158-
impl Named for VariantKind { fn name(&self) -> Name { self.ident.name } }
1158+
impl Named for Variant { fn name(&self) -> Name { self.ident.name } }
11591159
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
11601160
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
11611161
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
@@ -1332,7 +1332,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
13321332
}
13331333
Some(Node::Variant(ref variant)) => {
13341334
format!("variant {} in {}{}",
1335-
variant.node.ident,
1335+
variant.ident,
13361336
path_str(), id_str)
13371337
}
13381338
Some(Node::Field(ref field)) => {

src/librustc/hir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ pub struct EnumDef {
21932193
}
21942194

21952195
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
2196-
pub struct VariantKind {
2196+
pub struct Variant {
21972197
/// Name of the variant.
21982198
#[stable_hasher(project(name))]
21992199
pub ident: Ident,
@@ -2205,10 +2205,10 @@ pub struct VariantKind {
22052205
pub data: VariantData,
22062206
/// Explicit discriminant (e.g., `Foo = 1`).
22072207
pub disr_expr: Option<AnonConst>,
2208+
/// Span
2209+
pub span: Span
22082210
}
22092211

2210-
pub type Variant = Spanned<VariantKind>;
2211-
22122212
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
22132213
pub enum UseKind {
22142214
/// One import, e.g., `use foo::bar` or `use foo::bar as baz`.

src/librustc/hir/print.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl<'a> State<'a> {
737737
for v in variants {
738738
self.space_if_not_bol();
739739
self.maybe_print_comment(v.span.lo());
740-
self.print_outer_attributes(&v.node.attrs);
740+
self.print_outer_attributes(&v.attrs);
741741
self.ibox(INDENT_UNIT);
742742
self.print_variant(v);
743743
self.s.word(",");
@@ -829,8 +829,8 @@ impl<'a> State<'a> {
829829
pub fn print_variant(&mut self, v: &hir::Variant) {
830830
self.head("");
831831
let generics = hir::Generics::empty();
832-
self.print_struct(&v.node.data, &generics, v.node.ident.name, v.span, false);
833-
if let Some(ref d) = v.node.disr_expr {
832+
self.print_struct(&v.data, &generics, v.ident.name, v.span, false);
833+
if let Some(ref d) = v.disr_expr {
834834
self.s.space();
835835
self.word_space("=");
836836
self.print_anon_const(d);

src/librustc/ich/impls_hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
304304
}
305305
}
306306

307-
impl_stable_hash_for_spanned!(hir::VariantKind);
307+
impl_stable_hash_for_spanned!(hir::Variant);
308308

309309

310310
impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {

src/librustc/lint/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ for LateContextAndPass<'a, 'tcx, T> {
10601060
v: &'tcx hir::Variant,
10611061
g: &'tcx hir::Generics,
10621062
item_id: hir::HirId) {
1063-
self.with_lint_attrs(v.node.id, &v.node.attrs, |cx| {
1063+
self.with_lint_attrs(v.id, &v.attrs, |cx| {
10641064
lint_callback!(cx, check_variant, v, g);
10651065
hir_visit::walk_variant(cx, v, g, item_id);
10661066
lint_callback!(cx, check_variant_post, v, g);
@@ -1236,7 +1236,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
12361236
}
12371237

12381238
fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) {
1239-
self.with_lint_attrs(item_id, &v.node.attrs, |cx| {
1239+
self.with_lint_attrs(item_id, &v.attrs, |cx| {
12401240
run_early_pass!(cx, check_variant, v, g);
12411241
ast_visit::walk_variant(cx, v, g, item_id);
12421242
run_early_pass!(cx, check_variant_post, v, g);

src/librustc/lint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'tcx> {
846846
v: &'tcx hir::Variant,
847847
g: &'tcx hir::Generics,
848848
item_id: hir::HirId) {
849-
self.with_lint_attrs(v.node.id, &v.node.attrs, |builder| {
849+
self.with_lint_attrs(v.id, &v.attrs, |builder| {
850850
intravisit::walk_variant(builder, v, g, item_id);
851851
})
852852
}

src/librustc/middle/dead.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,12 @@ impl<'v, 'k, 'tcx> ItemLikeVisitor<'v> for LifeSeeder<'k, 'tcx> {
366366
match item.node {
367367
hir::ItemKind::Enum(ref enum_def, _) => {
368368
if allow_dead_code {
369-
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.id));
369+
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.id));
370370
}
371371

372372
for variant in &enum_def.variants {
373-
if let Some(ctor_hir_id) = variant.node.data.ctor_hir_id() {
374-
self.struct_constructors.insert(ctor_hir_id, variant.node.id);
373+
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
374+
self.struct_constructors.insert(ctor_hir_id, variant.id);
375375
}
376376
}
377377
}
@@ -497,7 +497,7 @@ impl DeadVisitor<'tcx> {
497497
&& !has_allow_dead_code_or_lang_attr(self.tcx, field.hir_id, &field.attrs)
498498
}
499499

500-
fn should_warn_about_variant(&mut self, variant: &hir::VariantKind) -> bool {
500+
fn should_warn_about_variant(&mut self, variant: &hir::Variant) -> bool {
501501
!self.symbol_is_live(variant.id)
502502
&& !has_allow_dead_code_or_lang_attr(self.tcx,
503503
variant.id,
@@ -596,8 +596,8 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
596596
variant: &'tcx hir::Variant,
597597
g: &'tcx hir::Generics,
598598
id: hir::HirId) {
599-
if self.should_warn_about_variant(&variant.node) {
600-
self.warn_dead_code(variant.node.id, variant.span, variant.node.ident.name,
599+
if self.should_warn_about_variant(&variant) {
600+
self.warn_dead_code(variant.id, variant.span, variant.ident.name,
601601
"variant", "constructed");
602602
} else {
603603
intravisit::walk_variant(self, variant, g, id);

src/librustc/middle/stability.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
290290
}
291291

292292
fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) {
293-
self.annotate(var.node.id, &var.node.attrs, var.span, AnnotationKind::Required,
293+
self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required,
294294
|v| {
295-
if let Some(ctor_hir_id) = var.node.data.ctor_hir_id() {
296-
v.annotate(ctor_hir_id, &var.node.attrs, var.span, AnnotationKind::Required,
295+
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
296+
v.annotate(ctor_hir_id, &var.attrs, var.span, AnnotationKind::Required,
297297
|_| {});
298298
}
299299

@@ -372,7 +372,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
372372
}
373373

374374
fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) {
375-
self.check_missing_stability(var.node.id, var.span, "variant");
375+
self.check_missing_stability(var.id, var.span, "variant");
376376
intravisit::walk_variant(self, var, g, item_id);
377377
}
378378

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
484484

485485
fn check_variant(&mut self, cx: &LateContext<'_, '_>, v: &hir::Variant, _: &hir::Generics) {
486486
self.check_missing_docs_attrs(cx,
487-
Some(v.node.id),
488-
&v.node.attrs,
487+
Some(v.id),
488+
&v.attrs,
489489
v.span,
490490
"a variant");
491491
}

src/librustc_lint/nonstandard_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl EarlyLintPass for NonCamelCaseTypes {
147147
}
148148

149149
fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant, _: &ast::Generics) {
150-
self.check_case(cx, "variant", &v.node.ident);
150+
self.check_case(cx, "variant", &v.ident);
151151
}
152152

153153
fn check_generic_param(&mut self, cx: &EarlyContext<'_>, param: &ast::GenericParam) {

src/librustc_lint/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
976976
let bytes = variant_layout.size.bytes().saturating_sub(discr_size);
977977

978978
debug!("- variant `{}` is {} bytes large",
979-
variant.node.ident,
979+
variant.ident,
980980
bytes);
981981
bytes
982982
})

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> {
16761676
id: hir::HirId) {
16771677
intravisit::walk_variant(self, v, g, id);
16781678

1679-
if let Some(ref discr) = v.node.disr_expr {
1679+
if let Some(ref discr) = v.disr_expr {
16801680
let def_id = self.tcx.hir().local_def_id(discr.hir_id);
16811681
self.record(def_id, EncodeContext::encode_info_for_anon_const, def_id);
16821682
}

src/librustc_passes/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
602602
}
603603
ItemKind::Enum(ref def, _) => {
604604
for variant in &def.variants {
605-
for field in variant.node.data.fields() {
605+
for field in variant.data.fields() {
606606
self.invalid_visibility(&field.vis, None);
607607
}
608608
}

src/librustc_privacy/lib.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -687,11 +687,11 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
687687
match item.node {
688688
hir::ItemKind::Enum(ref def, _) => {
689689
for variant in &def.variants {
690-
let variant_level = self.update(variant.node.id, item_level);
691-
if let Some(ctor_hir_id) = variant.node.data.ctor_hir_id() {
690+
let variant_level = self.update(variant.id, item_level);
691+
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
692692
self.update(ctor_hir_id, item_level);
693693
}
694-
for field in variant.node.data.fields() {
694+
for field in variant.data.fields() {
695695
self.update(field.hir_id, variant_level);
696696
}
697697
}
@@ -810,9 +810,9 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
810810
self.reach(item.hir_id, item_level).generics().predicates();
811811
}
812812
for variant in &def.variants {
813-
let variant_level = self.get(variant.node.id);
813+
let variant_level = self.get(variant.id);
814814
if variant_level.is_some() {
815-
for field in variant.node.data.fields() {
815+
for field in variant.data.fields() {
816816
self.reach(field.hir_id, variant_level).ty();
817817
}
818818
// Corner case: if the variant is reachable, but its
@@ -1647,7 +1647,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
16471647
v: &'tcx hir::Variant,
16481648
g: &'tcx hir::Generics,
16491649
item_id: hir::HirId) {
1650-
if self.access_levels.is_reachable(v.node.id) {
1650+
if self.access_levels.is_reachable(v.id) {
16511651
self.in_variant = true;
16521652
intravisit::walk_variant(self, v, g, item_id);
16531653
self.in_variant = false;
@@ -1898,7 +1898,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
18981898
self.check(item.hir_id, item_visibility).generics().predicates();
18991899

19001900
for variant in &def.variants {
1901-
for field in variant.node.data.fields() {
1901+
for field in variant.data.fields() {
19021902
self.check(field.hir_id, item_visibility).ty();
19031903
}
19041904
}

src/librustc_resolve/build_reduced_graph.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,17 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
799799
parent: Module<'a>,
800800
vis: ty::Visibility,
801801
expn_id: ExpnId) {
802-
let ident = variant.node.ident;
802+
let ident = variant.ident;
803803

804804
// Define a name in the type namespace.
805-
let def_id = self.r.definitions.local_def_id(variant.node.id);
805+
let def_id = self.r.definitions.local_def_id(variant.id);
806806
let res = Res::Def(DefKind::Variant, def_id);
807807
self.r.define(parent, ident, TypeNS, (res, vis, variant.span, expn_id));
808808

809809
// If the variant is marked as non_exhaustive then lower the visibility to within the
810810
// crate.
811811
let mut ctor_vis = vis;
812-
let has_non_exhaustive = attr::contains_name(&variant.node.attrs, sym::non_exhaustive);
812+
let has_non_exhaustive = attr::contains_name(&variant.attrs, sym::non_exhaustive);
813813
if has_non_exhaustive && vis == ty::Visibility::Public {
814814
ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
815815
}
@@ -819,9 +819,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
819819
// value namespace, they are reserved for possible future use.
820820
// It's ok to use the variant's id as a ctor id since an
821821
// error will be reported on any use of such resolution anyway.
822-
let ctor_node_id = variant.node.data.ctor_id().unwrap_or(variant.node.id);
822+
let ctor_node_id = variant.data.ctor_id().unwrap_or(variant.id);
823823
let ctor_def_id = self.r.definitions.local_def_id(ctor_node_id);
824-
let ctor_kind = CtorKind::from_ast(&variant.node.data);
824+
let ctor_kind = CtorKind::from_ast(&variant.data);
825825
let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Variant, ctor_kind), ctor_def_id);
826826
self.r.define(parent, ident, ValueNS, (ctor_res, ctor_vis, variant.span, expn_id));
827827
}

0 commit comments

Comments
 (0)