Skip to content

Commit 8124827

Browse files
authored
Unrolled build for #155702
Rollup merge of #155702 - mejrs:itemkind_trait-fields, r=petrochenkov Change `ItemKind::Trait` to a field variant. This changes `ItemKind::Trait` from an octuple(!!) to an enum variant with fields. Their names were chosen to match up with existing usage and minimize renaming. I'm leaning towards renaming `ident` to `name` as well; let me know if that's desired.
2 parents 52b6e2c + 9515f52 commit 8124827

43 files changed

Lines changed: 98 additions & 97 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,16 +569,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
569569
(safety, items, bounds)
570570
},
571571
);
572-
hir::ItemKind::Trait(
572+
hir::ItemKind::Trait {
573573
impl_restriction,
574574
constness,
575-
*is_auto,
575+
is_auto: *is_auto,
576576
safety,
577577
ident,
578578
generics,
579579
bounds,
580580
items,
581-
)
581+
}
582582
}
583583
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
584584
let constness = self.lower_constness(*constness);

compiler/rustc_hir/src/hir.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4467,7 +4467,7 @@ impl<'hir> Item<'hir> {
44674467
GenericBounds<'hir>,
44684468
&'hir [TraitItemId]
44694469
),
4470-
ItemKind::Trait(impl_restriction, constness, is_auto, safety, ident, generics, bounds, items),
4470+
ItemKind::Trait { impl_restriction, constness, is_auto, safety, ident, generics, bounds, items },
44714471
(impl_restriction, *constness, *is_auto, *safety, *ident, generics, bounds, items);
44724472

44734473
expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
@@ -4659,16 +4659,16 @@ pub enum ItemKind<'hir> {
46594659
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
46604660
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
46614661
/// A trait definition.
4662-
Trait(
4663-
&'hir ImplRestriction<'hir>,
4664-
Constness,
4665-
IsAuto,
4666-
Safety,
4667-
Ident,
4668-
&'hir Generics<'hir>,
4669-
GenericBounds<'hir>,
4670-
&'hir [TraitItemId],
4671-
),
4662+
Trait {
4663+
impl_restriction: &'hir ImplRestriction<'hir>,
4664+
constness: Constness,
4665+
is_auto: IsAuto,
4666+
safety: Safety,
4667+
ident: Ident,
4668+
generics: &'hir Generics<'hir>,
4669+
bounds: GenericBounds<'hir>,
4670+
items: &'hir [TraitItemId],
4671+
},
46724672
/// A trait alias.
46734673
TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
46744674

@@ -4714,7 +4714,7 @@ impl ItemKind<'_> {
47144714
| ItemKind::Enum(ident, ..)
47154715
| ItemKind::Struct(ident, ..)
47164716
| ItemKind::Union(ident, ..)
4717-
| ItemKind::Trait(_, _, _, _, ident, ..)
4717+
| ItemKind::Trait { ident, .. }
47184718
| ItemKind::TraitAlias(_, ident, ..) => Some(ident),
47194719

47204720
ItemKind::Use(_, UseKind::Glob | UseKind::ListStem)
@@ -4732,7 +4732,7 @@ impl ItemKind<'_> {
47324732
| ItemKind::Enum(_, generics, _)
47334733
| ItemKind::Struct(_, generics, _)
47344734
| ItemKind::Union(_, generics, _)
4735-
| ItemKind::Trait(_, _, _, _, _, generics, _, _)
4735+
| ItemKind::Trait { generics, .. }
47364736
| ItemKind::TraitAlias(_, _, generics, _)
47374737
| ItemKind::Impl(Impl { generics, .. }) => generics,
47384738
_ => return None,

compiler/rustc_hir/src/intravisit.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -618,16 +618,16 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
618618
try_visit!(visitor.visit_generics(generics));
619619
try_visit!(visitor.visit_variant_data(struct_definition));
620620
}
621-
ItemKind::Trait(
622-
ref impl_restriction,
623-
_constness,
624-
_is_auto,
625-
_safety,
621+
ItemKind::Trait {
622+
impl_restriction,
623+
constness: _,
624+
is_auto: _,
625+
safety: _,
626626
ident,
627-
ref generics,
627+
generics,
628628
bounds,
629-
trait_item_refs,
630-
) => {
629+
items: trait_item_refs,
630+
} => {
631631
if let RestrictionKind::Restricted(path) = &impl_restriction.kind {
632632
walk_list!(visitor, visit_path_segment, path.segments);
633633
}

compiler/rustc_hir/src/target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl Target {
132132
ItemKind::Enum(..) => Target::Enum,
133133
ItemKind::Struct(..) => Target::Struct,
134134
ItemKind::Union(..) => Target::Union,
135-
ItemKind::Trait(..) => Target::Trait,
135+
ItemKind::Trait { .. } => Target::Trait,
136136
ItemKind::TraitAlias(..) => Target::TraitAlias,
137137
ItemKind::Impl(imp_) => Target::Impl { of_trait: imp_.of_trait.is_some() },
138138
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub(super) fn check_item<'tcx>(
326326
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
327327
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
328328
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
329-
hir::ItemKind::Trait(..) => check_trait(tcx, item),
329+
hir::ItemKind::Trait { .. } => check_trait(tcx, item),
330330
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
331331
_ => Ok(()),
332332
}
@@ -1188,7 +1188,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
11881188
});
11891189

11901190
// Only check traits, don't check trait aliases
1191-
if let hir::ItemKind::Trait(..) = item.kind {
1191+
if let hir::ItemKind::Trait { .. } = item.kind {
11921192
check_gat_where_clauses(tcx, item.owner_id.def_id);
11931193
}
11941194
res

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
895895
let item = tcx.hir_expect_item(def_id);
896896

897897
let (constness, is_alias, is_auto, safety, impl_restriction) = match item.kind {
898-
hir::ItemKind::Trait(impl_restriction, constness, is_auto, safety, ..) => (
898+
hir::ItemKind::Trait { impl_restriction, constness, is_auto, safety, .. } => (
899899
constness,
900900
false,
901901
is_auto == hir::IsAuto::Yes,

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
221221

222222
// Add in the self type parameter.
223223
let opt_self = if let Node::Item(item) = node
224-
&& let ItemKind::Trait(..) | ItemKind::TraitAlias(..) = item.kind
224+
&& let ItemKind::Trait { .. } | ItemKind::TraitAlias(..) = item.kind
225225
{
226226
// Something of a hack: We reuse the node ID of the trait for the self type parameter.
227227
Some(ty::GenericParamDef {
@@ -402,7 +402,7 @@ fn param_default_policy(node: Node<'_>) -> Option<ParamDefaultPolicy> {
402402

403403
Some(match node {
404404
Node::Item(item) => match item.kind {
405-
ItemKind::Trait(..)
405+
ItemKind::Trait { .. }
406406
| ItemKind::TraitAlias(..)
407407
| ItemKind::TyAlias(..)
408408
| ItemKind::Enum(..)

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
172172
));
173173
}
174174
}
175-
ItemKind::Trait(_, _, _, _, _, _, self_bounds, ..)
175+
ItemKind::Trait { bounds: self_bounds, .. }
176176
| ItemKind::TraitAlias(_, _, _, self_bounds) => {
177177
is_trait = Some((self_bounds, item.span));
178178
}
@@ -669,7 +669,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
669669
};
670670

671671
let (generics, superbounds) = match item.kind {
672-
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
672+
hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits),
673673
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
674674
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
675675
};
@@ -934,7 +934,7 @@ pub(super) fn type_param_predicates<'tcx>(
934934
};
935935

936936
if let Node::Item(item) = hir_node
937-
&& let hir::ItemKind::Trait(..) = item.kind
937+
&& let hir::ItemKind::Trait { .. } = item.kind
938938
// Implied `Self: Trait` and supertrait bounds.
939939
&& param_id == item_hir_id
940940
{
@@ -1073,7 +1073,7 @@ pub(super) fn const_conditions<'tcx>(
10731073
Node::Item(item) => match item.kind {
10741074
hir::ItemKind::Impl(impl_) => (impl_.generics, None, false),
10751075
hir::ItemKind::Fn { generics, .. } => (generics, None, false),
1076-
hir::ItemKind::Trait(_, _, _, _, _, generics, supertraits, _) => {
1076+
hir::ItemKind::Trait { generics, bounds: supertraits, .. } => {
10771077
(generics, Some((Some(item.owner_id.def_id), supertraits)), false)
10781078
}
10791079
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => {
@@ -1194,7 +1194,7 @@ pub(super) fn explicit_implied_const_bounds<'tcx>(
11941194
}
11951195
None => match tcx.hir_node_by_def_id(def_id) {
11961196
Node::Item(hir::Item {
1197-
kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..),
1197+
kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..),
11981198
..
11991199
}) => implied_predicates_with_filter(
12001200
tcx,

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
647647
| hir::ItemKind::Enum(_, generics, _)
648648
| hir::ItemKind::Struct(_, generics, _)
649649
| hir::ItemKind::Union(_, generics, _)
650-
| hir::ItemKind::Trait(_, _, _, _, _, generics, ..)
650+
| hir::ItemKind::Trait { generics, .. }
651651
| hir::ItemKind::TraitAlias(_, _, generics, ..)
652652
| hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
653653
// These kinds of items have only early-bound lifetime parameters.
@@ -2258,7 +2258,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
22582258
// we already do that in `BoundVarContext::supertrait_hrtb_vars`.
22592259
if let Res::SelfTyParam { trait_: _ } = expected_res
22602260
&& let hir::Node::Item(item) = node
2261-
&& let hir::ItemKind::Trait(..) = item.kind
2261+
&& let hir::ItemKind::Trait { .. } = item.kind
22622262
{
22632263
// Yield the trait's def id. Supertraits will be
22642264
// elaborated from that.

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
171171
Ty::new_adt(tcx, def, args)
172172
}
173173
ItemKind::GlobalAsm { .. } => tcx.typeck(def_id).node_type(hir_id),
174-
ItemKind::Trait(..)
174+
ItemKind::Trait { .. }
175175
| ItemKind::TraitAlias(..)
176176
| ItemKind::Macro(..)
177177
| ItemKind::Mod(..)

0 commit comments

Comments
 (0)