Skip to content

Commit 5f6772c

Browse files
committed
Constify trait aliases
1 parent 3ca752f commit 5f6772c

File tree

21 files changed

+157
-39
lines changed

21 files changed

+157
-39
lines changed

compiler/rustc_ast/src/ast.rs

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

36273627
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
36283628
pub struct TraitAlias {
3629+
pub constness: Const,
36293630
pub ident: Ident,
36303631
pub generics: Generics,
36313632
#[visitable(extra = BoundKind::Bound)]

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,8 @@ macro_rules! common_visitor_and_walkers {
833833
visit_visitable!($($mut)? vis, impl_),
834834
ItemKind::Trait(trait_) =>
835835
visit_visitable!($($mut)? vis, trait_),
836-
ItemKind::TraitAlias(box TraitAlias { ident, generics, bounds }) => {
837-
visit_visitable!($($mut)? vis, ident, generics);
836+
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds}) => {
837+
visit_visitable!($($mut)? vis, constness, ident, generics);
838838
visit_visitable_with!($($mut)? vis, bounds, BoundKind::Bound)
839839
}
840840
ItemKind::MacCall(m) =>

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
415415
);
416416
hir::ItemKind::Trait(constness, *is_auto, safety, ident, generics, bounds, items)
417417
}
418-
ItemKind::TraitAlias(box TraitAlias { ident, generics, bounds }) => {
418+
ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
419+
let constness = self.lower_constness(*constness);
419420
let ident = self.lower_ident(*ident);
420421
let (generics, bounds) = self.lower_generics(
421422
generics,
@@ -429,7 +430,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
429430
)
430431
},
431432
);
432-
hir::ItemKind::TraitAlias(ident, generics, bounds)
433+
hir::ItemKind::TraitAlias(constness, ident, generics, bounds)
433434
}
434435
ItemKind::MacroDef(ident, MacroDef { body, macro_rules }) => {
435436
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
@@ -385,8 +385,11 @@ impl<'a> State<'a> {
385385
let empty = item.attrs.is_empty() && items.is_empty();
386386
self.bclose(item.span, empty, cb);
387387
}
388-
ast::ItemKind::TraitAlias(box TraitAlias { ident, generics, bounds }) => {
389-
let (cb, ib) = self.head(visibility_qualified(&item.vis, "trait"));
388+
ast::ItemKind::TraitAlias(box TraitAlias { constness, ident, generics, bounds }) => {
389+
let (cb, ib) = self.head("");
390+
self.print_visibility(&item.vis);
391+
self.print_constness(*constness);
392+
self.word_nbsp("trait");
390393
self.print_ident(*ident);
391394
self.print_generic_params(&generics.params);
392395
self.nbsp();

compiler/rustc_hir/src/hir.rs

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

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

42514251
expect_impl, &Impl<'hir>, ItemKind::Impl(imp), imp;
42524252
}
@@ -4423,7 +4423,7 @@ pub enum ItemKind<'hir> {
44234423
&'hir [TraitItemId],
44244424
),
44254425
/// A trait alias.
4426-
TraitAlias(Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
4426+
TraitAlias(Constness, Ident, &'hir Generics<'hir>, GenericBounds<'hir>),
44274427

44284428
/// An implementation, e.g., `impl<A> Trait for Foo { .. }`.
44294429
Impl(Impl<'hir>),
@@ -4468,7 +4468,7 @@ impl ItemKind<'_> {
44684468
| ItemKind::Struct(ident, ..)
44694469
| ItemKind::Union(ident, ..)
44704470
| ItemKind::Trait(_, _, _, ident, ..)
4471-
| ItemKind::TraitAlias(ident, ..) => Some(ident),
4471+
| ItemKind::TraitAlias(_, ident, ..) => Some(ident),
44724472

44734473
ItemKind::Use(_, UseKind::Glob | UseKind::ListStem)
44744474
| ItemKind::ForeignMod { .. }
@@ -4486,7 +4486,7 @@ impl ItemKind<'_> {
44864486
| ItemKind::Struct(_, generics, _)
44874487
| ItemKind::Union(_, generics, _)
44884488
| ItemKind::Trait(_, _, _, _, generics, _, _)
4489-
| ItemKind::TraitAlias(_, generics, _)
4489+
| ItemKind::TraitAlias(_, _, generics, _)
44904490
| ItemKind::Impl(Impl { generics, .. }) => generics,
44914491
_ => return None,
44924492
})

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
@@ -167,7 +167,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
167167
}
168168
}
169169
ItemKind::Trait(_, _, _, _, _, self_bounds, ..)
170-
| ItemKind::TraitAlias(_, _, self_bounds) => {
170+
| ItemKind::TraitAlias(_, _, _, self_bounds) => {
171171
is_trait = Some((self_bounds, item.span));
172172
}
173173
_ => {}
@@ -654,7 +654,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
654654

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

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
@@ -1594,7 +1594,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15941594
Node::Item(hir::Item {
15951595
kind:
15961596
hir::ItemKind::Trait(_, _, _, ident, ..)
1597-
| hir::ItemKind::TraitAlias(ident, ..),
1597+
| hir::ItemKind::TraitAlias(_, ident, ..),
15981598
..
15991599
})
16001600
// We may also encounter unsatisfied GAT or method bounds

0 commit comments

Comments
 (0)