Skip to content

Commit c61304a

Browse files
committed
Give all impls a constness
1 parent 18597d8 commit c61304a

File tree

19 files changed

+69
-71
lines changed

19 files changed

+69
-71
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,6 +3687,7 @@ pub struct TyAlias {
36873687
#[derive(Clone, Encodable, Decodable, Debug)]
36883688
pub struct Impl {
36893689
pub generics: Generics,
3690+
pub constness: Const,
36903691
pub of_trait: Option<Box<TraitImplHeader>>,
36913692
pub self_ty: Box<Ty>,
36923693
pub items: ThinVec<Box<AssocItem>>,
@@ -3696,7 +3697,6 @@ pub struct Impl {
36963697
pub struct TraitImplHeader {
36973698
pub defaultness: Defaultness,
36983699
pub safety: Safety,
3699-
pub constness: Const,
37003700
pub polarity: ImplPolarity,
37013701
pub trait_ref: TraitRef,
37023702
}
@@ -4072,9 +4072,9 @@ mod size_asserts {
40724072
static_assert_size!(GenericArg, 24);
40734073
static_assert_size!(GenericBound, 88);
40744074
static_assert_size!(Generics, 40);
4075-
static_assert_size!(Impl, 64);
4076-
static_assert_size!(Item, 136);
4077-
static_assert_size!(ItemKind, 72);
4075+
static_assert_size!(Impl, 80);
4076+
static_assert_size!(Item, 152);
4077+
static_assert_size!(ItemKind, 88);
40784078
static_assert_size!(LitKind, 24);
40794079
static_assert_size!(Local, 96);
40804080
static_assert_size!(MetaItemLit, 40);
@@ -4085,7 +4085,7 @@ mod size_asserts {
40854085
static_assert_size!(PathSegment, 24);
40864086
static_assert_size!(Stmt, 32);
40874087
static_assert_size!(StmtKind, 16);
4088-
static_assert_size!(TraitImplHeader, 80);
4088+
static_assert_size!(TraitImplHeader, 72);
40894089
static_assert_size!(Ty, 64);
40904090
static_assert_size!(TyKind, 40);
40914091
// tidy-alphabetical-end

compiler/rustc_ast/src/visit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,11 +928,11 @@ macro_rules! common_visitor_and_walkers {
928928
}
929929

930930
impl_walkable!(|&$($mut)? $($lt)? self: Impl, vis: &mut V| {
931-
let Impl { generics, of_trait, self_ty, items } = self;
931+
let Impl { generics, of_trait, self_ty, items, constness: _ } = self;
932932
try_visit!(vis.visit_generics(generics));
933933
if let Some(box of_trait) = of_trait {
934-
let TraitImplHeader { defaultness, safety, constness, polarity, trait_ref } = of_trait;
935-
visit_visitable!($($mut)? vis, defaultness, safety, constness, polarity, trait_ref);
934+
let TraitImplHeader { defaultness, safety, polarity, trait_ref } = of_trait;
935+
visit_visitable!($($mut)? vis, defaultness, safety, polarity, trait_ref);
936936
}
937937
try_visit!(vis.visit_ty(self_ty));
938938
visit_visitable_with!($($mut)? vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() });

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
345345
of_trait,
346346
self_ty: ty,
347347
items: impl_items,
348+
constness,
348349
}) => {
349350
// Lower the "impl header" first. This ordering is important
350351
// for in-band lifetimes! Consider `'a` here:
@@ -378,11 +379,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
378379
.arena
379380
.alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item)));
380381

382+
let constness = self.lower_constness(*constness);
383+
381384
hir::ItemKind::Impl(hir::Impl {
382385
generics,
383386
of_trait,
384387
self_ty: lowered_ty,
385388
items: new_impl_items,
389+
constness,
386390
})
387391
}
388392
ItemKind::Trait(box Trait {
@@ -970,9 +974,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
970974
&mut self,
971975
trait_impl_header: &TraitImplHeader,
972976
) -> &'hir hir::TraitImplHeader<'hir> {
973-
let TraitImplHeader { constness, safety, polarity, defaultness, ref trait_ref } =
974-
*trait_impl_header;
975-
let constness = self.lower_constness(constness);
977+
let TraitImplHeader { safety, polarity, defaultness, ref trait_ref } = *trait_impl_header;
976978
let safety = self.lower_safety(safety, hir::Safety::Safe);
977979
let polarity = match polarity {
978980
ImplPolarity::Positive => ImplPolarity::Positive,
@@ -995,7 +997,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
995997
);
996998

997999
self.arena.alloc(hir::TraitImplHeader {
998-
constness,
9991000
safety,
10001001
polarity,
10011002
defaultness,

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,14 +1011,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10111011
match &item.kind {
10121012
ItemKind::Impl(Impl {
10131013
generics,
1014+
constness,
10141015
of_trait:
1015-
Some(box TraitImplHeader {
1016-
safety,
1017-
polarity,
1018-
defaultness: _,
1019-
constness,
1020-
trait_ref: t,
1021-
}),
1016+
Some(box TraitImplHeader { safety, polarity, defaultness: _, trait_ref: t }),
10221017
self_ty,
10231018
items,
10241019
}) => {
@@ -1050,7 +1045,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10501045
walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl { of_trait: true });
10511046
});
10521047
}
1053-
ItemKind::Impl(Impl { generics, of_trait: None, self_ty, items }) => {
1048+
ItemKind::Impl(Impl { generics, of_trait: None, self_ty, items, constness: _ }) => {
10541049
self.visit_attrs_vis(&item.attrs, &item.vis);
10551050
self.visibility_not_permitted(
10561051
&item.vis,

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a> State<'a> {
305305
let (cb, ib) = self.head(visibility_qualified(&item.vis, "union"));
306306
self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib);
307307
}
308-
ast::ItemKind::Impl(ast::Impl { generics, of_trait, self_ty, items }) => {
308+
ast::ItemKind::Impl(ast::Impl { generics, of_trait, self_ty, items, constness }) => {
309309
let (cb, ib) = self.head("");
310310
self.print_visibility(&item.vis);
311311

@@ -321,24 +321,20 @@ impl<'a> State<'a> {
321321
};
322322

323323
if let Some(box of_trait) = of_trait {
324-
let ast::TraitImplHeader {
325-
defaultness,
326-
safety,
327-
constness,
328-
polarity,
329-
ref trait_ref,
330-
} = *of_trait;
324+
let ast::TraitImplHeader { defaultness, safety, polarity, ref trait_ref } =
325+
*of_trait;
331326
self.print_defaultness(defaultness);
332327
self.print_safety(safety);
333328
impl_generics(self);
334-
self.print_constness(constness);
329+
self.print_constness(*constness);
335330
if let ast::ImplPolarity::Negative(_) = polarity {
336331
self.word("!");
337332
}
338333
self.print_trait_ref(trait_ref);
339334
self.space();
340335
self.word_space("for");
341336
} else {
337+
self.print_constness(*constness);
342338
impl_generics(self);
343339
}
344340

compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ pub(crate) fn expand_deriving_coerce_pointee(
137137
safety: ast::Safety::Default,
138138
polarity: ast::ImplPolarity::Positive,
139139
defaultness: ast::Defaultness::Final,
140-
constness: ast::Const::No,
141140
trait_ref,
142141
})),
142+
constness: ast::Const::No,
143143
self_ty: self_type.clone(),
144144
items: ThinVec::new(),
145145
}),
@@ -160,9 +160,9 @@ pub(crate) fn expand_deriving_coerce_pointee(
160160
safety: ast::Safety::Default,
161161
polarity: ast::ImplPolarity::Positive,
162162
defaultness: ast::Defaultness::Final,
163-
constness: ast::Const::No,
164163
trait_ref,
165164
})),
165+
constness: ast::Const::No,
166166
self_ty: self_type.clone(),
167167
items: ThinVec::new(),
168168
}),

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,13 +835,9 @@ impl<'a> TraitDef<'a> {
835835
safety: ast::Safety::Default,
836836
polarity: ast::ImplPolarity::Positive,
837837
defaultness: ast::Defaultness::Final,
838-
constness: if self.is_const {
839-
ast::Const::Yes(DUMMY_SP)
840-
} else {
841-
ast::Const::No
842-
},
843838
trait_ref,
844839
})),
840+
constness: if self.is_const { ast::Const::Yes(DUMMY_SP) } else { ast::Const::No },
845841
self_ty: self_type,
846842
items: methods.into_iter().chain(associated_types).collect(),
847843
}),

compiler/rustc_expand/src/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,10 +2389,10 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
23892389
) -> SmallVec<[Box<ast::AssocItem>; 1]> {
23902390
match ctxt {
23912391
AssocCtxt::Trait => self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag)),
2392-
AssocCtxt::Impl { of_trait: false } => {
2392+
AssocCtxt::Impl { of_trait: false, .. } => {
23932393
self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag))
23942394
}
2395-
AssocCtxt::Impl { of_trait: true } => {
2395+
AssocCtxt::Impl { of_trait: true, .. } => {
23962396
self.flat_map_node(AstNodeWrapper::new(node, TraitImplItemTag))
23972397
}
23982398
}

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,11 +4345,11 @@ pub struct Impl<'hir> {
43454345
pub of_trait: Option<&'hir TraitImplHeader<'hir>>,
43464346
pub self_ty: &'hir Ty<'hir>,
43474347
pub items: &'hir [ImplItemId],
4348+
pub constness: Constness,
43484349
}
43494350

43504351
#[derive(Debug, Clone, Copy, HashStable_Generic)]
43514352
pub struct TraitImplHeader<'hir> {
4352-
pub constness: Constness,
43534353
pub safety: Safety,
43544354
pub polarity: ImplPolarity,
43554355
pub defaultness: Defaultness,
@@ -4914,7 +4914,7 @@ mod size_asserts {
49144914
static_assert_size!(GenericArg<'_>, 16);
49154915
static_assert_size!(GenericBound<'_>, 64);
49164916
static_assert_size!(Generics<'_>, 56);
4917-
static_assert_size!(Impl<'_>, 40);
4917+
static_assert_size!(Impl<'_>, 48);
49184918
static_assert_size!(ImplItem<'_>, 88);
49194919
static_assert_size!(ImplItemKind<'_>, 40);
49204920
static_assert_size!(Item<'_>, 88);

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,9 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
590590
try_visit!(visitor.visit_generics(generics));
591591
try_visit!(visitor.visit_enum_def(enum_definition));
592592
}
593-
ItemKind::Impl(Impl { generics, of_trait, self_ty, items }) => {
593+
ItemKind::Impl(Impl { generics, of_trait, self_ty, items, constness: _ }) => {
594594
try_visit!(visitor.visit_generics(generics));
595595
if let Some(TraitImplHeader {
596-
constness: _,
597596
safety: _,
598597
polarity: _,
599598
defaultness: _,

0 commit comments

Comments
 (0)