Skip to content

Commit ad44d42

Browse files
authored
Rollup merge of #63543 - c410-f3r:variant, r=c410-f3r
Merge Variant and Variant_ Extracted from #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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 6 additions & 8 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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);

0 commit comments

Comments
 (0)