Skip to content

Commit 66e880b

Browse files
committed
Constify trait aliases
1 parent 305847d commit 66e880b

File tree

20 files changed

+156
-38
lines changed

20 files changed

+156
-38
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,7 @@ impl Default for FnHeader {
36243624

36253625
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
36263626
pub struct TraitAlias {
3627+
pub constness: Const,
36273628
pub ident: Ident,
36283629
pub generics: Generics,
36293630
#[visitable(extra = BoundKind::Bound)]

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ macro_rules! common_visitor_and_walkers {
835835
visit_visitable!($($mut)? vis, impl_),
836836
ItemKind::Trait(trait_) =>
837837
visit_visitable!($($mut)? vis, trait_),
838-
ItemKind::TraitAlias(box TraitAlias { ident, generics, bounds }) => {
839-
visit_visitable!($($mut)? vis, ident, generics);
838+
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds}) => {
839+
visit_visitable!($($mut)? vis, constness, ident, generics);
840840
visit_visitable_with!($($mut)? vis, bounds, BoundKind::Bound)
841841
}
842842
ItemKind::MacCall(m) =>

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
417417
);
418418
hir::ItemKind::Trait(constness, *is_auto, safety, ident, generics, bounds, items)
419419
}
420-
ItemKind::TraitAlias(box TraitAlias { ident, generics, bounds }) => {
420+
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
421+
let constness = self.lower_constness(*constness);
421422
let ident = self.lower_ident(*ident);
422423
let (generics, bounds) = self.lower_generics(
423424
generics,
@@ -431,7 +432,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
431432
)
432433
},
433434
);
434-
hir::ItemKind::TraitAlias(ident, generics, bounds)
435+
hir::ItemKind::TraitAlias(constness, ident, generics, bounds)
435436
}
436437
ItemKind::MacroDef(ident, MacroDef { body, macro_rules }) => {
437438
let ident = self.lower_ident(*ident);

compiler/rustc_ast_pretty/src/pprust/state/item.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,11 @@ impl<'a> State<'a> {
387387
let empty = item.attrs.is_empty() && items.is_empty();
388388
self.bclose(item.span, empty, cb);
389389
}
390-
ast::ItemKind::TraitAlias(box TraitAlias { ident, generics, bounds }) => {
391-
let (cb, ib) = self.head(visibility_qualified(&item.vis, "trait"));
390+
ast::ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
391+
let (cb, ib) = self.head("");
392+
self.print_visibility(&item.vis);
393+
self.print_constness(*constness);
394+
self.word_nbsp("trait");
392395
self.print_ident(*ident);
393396
self.print_generic_params(&generics.params);
394397
self.nbsp();

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,8 +4237,8 @@ impl<'hir> Item<'hir> {
42374237
ItemKind::Trait(constness, is_auto, safety, ident, generics, bounds, items),
42384238
(*constness, *is_auto, *safety, *ident, generics, bounds, items);
42394239

4240-
expect_trait_alias, (Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4241-
ItemKind::TraitAlias(ident, generics, bounds), (*ident, generics, bounds);
4240+
expect_trait_alias, (Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4241+
ItemKind::TraitAlias(constness, ident, generics, bounds), (*constness, *ident, generics, bounds);
42424242

42434243
expect_impl, &Impl<'hir>, ItemKind::Impl(imp), imp;
42444244
}
@@ -4415,7 +4415,7 @@ pub enum ItemKind<'hir> {
44154415
&'hir [TraitItemId],
44164416
),
44174417
/// A trait alias.
4418-
TraitAlias(Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4418+
TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
44194419

44204420
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
44214421
Impl(Impl<'hir>),
@@ -4460,7 +4460,7 @@ impl ItemKind<'_> {
44604460
| ItemKind::Struct(ident, ..)
44614461
| ItemKind::Union(ident, ..)
44624462
| ItemKind::Trait(_, _, _, ident, ..)
4463-
| ItemKind::TraitAlias(ident, ..) => Some(ident),
4463+
| ItemKind::TraitAlias(_, ident, ..) => Some(ident),
44644464

44654465
ItemKind::Use(_, UseKind::Glob | UseKind::ListStem)
44664466
| ItemKind::ForeignMod { .. }
@@ -4478,7 +4478,7 @@ impl ItemKind<'_> {
44784478
| ItemKind::Struct(_, generics, _)
44794479
| ItemKind::Union(_, generics, _)
44804480
| ItemKind::Trait(_, _, _, _, generics, _, _)
4481-
| ItemKind::TraitAlias(_, generics, _)
4481+
| ItemKind::TraitAlias(_, _, generics, _)
44824482
| ItemKind::Impl(Impl { generics, .. }) => generics,
44834483
_ => return None,
44844484
})

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
626626
walk_list!(visitor, visit_param_bound, bounds);
627627
walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
628628
}
629-
ItemKind::TraitAlias(ident, ref generics, bounds) => {
629+
ItemKind::TraitAlias(_constness, ident, ref generics, bounds) => {
630630
try_visit!(visitor.visit_ident(ident));
631631
try_visit!(visitor.visit_generics(generics));
632632
walk_list!(visitor, visit_param_bound, bounds);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
166166
}
167167
}
168168
ItemKind::Trait(_, _, _, _, _, self_bounds, ..)
169-
| ItemKind::TraitAlias(_, _, self_bounds) => {
169+
| ItemKind::TraitAlias(_, _, _, self_bounds) => {
170170
is_trait = Some((self_bounds, item.span));
171171
}
172172
_ => {}
@@ -651,7 +651,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
651651

652652
let (generics, superbounds) = match item.kind {
653653
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
654-
hir::ItemKind::TraitAlias(_, generics, supertraits) => (generics, supertraits),
654+
hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits),
655655
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
656656
};
657657

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
632632
| hir::ItemKind::Struct(_, generics, _)
633633
| hir::ItemKind::Union(_, generics, _)
634634
| hir::ItemKind::Trait(_, _, _, _, generics, ..)
635-
| hir::ItemKind::TraitAlias(_, generics, ..)
635+
| hir::ItemKind::TraitAlias(_, _, generics, ..)
636636
| hir::ItemKind::Impl(hir::Impl { generics, .. }) => {
637637
// These kinds of items have only early-bound lifetime parameters.
638638
self.visit_early(item.hir_id(), generics, |this| intravisit::walk_item(this, item));

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,10 @@ impl<'a> State<'a> {
765765
}
766766
self.bclose(item.span, cb);
767767
}
768-
hir::ItemKind::TraitAlias(ident, generics, bounds) => {
769-
let (cb, ib) = self.head("trait");
768+
hir::ItemKind::TraitAlias(constness, ident, generics, bounds) => {
769+
let (cb, ib) = self.head("");
770+
self.print_constness(constness);
771+
self.word_nbsp("trait");
770772
self.print_ident(ident);
771773
self.print_generic_params(generics.params);
772774
self.nbsp();

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11871187
Node::Item(hir::Item {
11881188
kind:
11891189
hir::ItemKind::Trait(_, _, _, ident, ..)
1190-
| hir::ItemKind::TraitAlias(ident, ..),
1190+
| hir::ItemKind::TraitAlias(_, ident, ..),
11911191
..
11921192
})
11931193
// We may also encounter unsatisfied GAT or method bounds

0 commit comments

Comments
 (0)