Skip to content

Commit e71c375

Browse files
committed
Box the ForeignMod in ItemKind::ForeignMod.
1 parent cb6230e commit e71c375

File tree

17 files changed

+41
-32
lines changed

17 files changed

+41
-32
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,7 @@ pub enum ItemKind {
28352835
/// E.g., `mod foo;` or `mod foo { .. }`.
28362836
/// `unsafe` keyword on modules is accepted syntactically for macro DSLs, but not
28372837
/// semantically by Rust.
2838-
Mod(Unsafe, ModKind),
2838+
Mod(Unsafe, P<ModKind>),
28392839
/// An external module (`extern`).
28402840
///
28412841
/// E.g., `extern {}` or `extern "C" {}`.
@@ -3043,8 +3043,8 @@ mod size_asserts {
30433043
static_assert_size!(GenericBound, 88);
30443044
static_assert_size!(Generics, 72);
30453045
static_assert_size!(Impl, 200);
3046-
static_assert_size!(Item, 152);
3047-
static_assert_size!(ItemKind, 64);
3046+
static_assert_size!(Item, 136);
3047+
static_assert_size!(ItemKind, 48);
30483048
static_assert_size!(Lit, 48);
30493049
static_assert_size!(Pat, 120);
30503050
static_assert_size!(Path, 40);

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
10271027
}
10281028
ItemKind::Mod(unsafety, mod_kind) => {
10291029
visit_unsafety(unsafety, vis);
1030-
match mod_kind {
1030+
match &mut **mod_kind {
10311031
ModKind::Loaded(items, _inline, ModSpans { inner_span, inject_use_span }) => {
10321032
vis.visit_span(inner_span);
10331033
vis.visit_span(inject_use_span);

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
311311
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
312312
visitor.visit_fn(kind, item.span, item.id)
313313
}
314-
ItemKind::Mod(_unsafety, ref mod_kind) => match mod_kind {
314+
ItemKind::Mod(_unsafety, ref mod_kind) => match &**mod_kind {
315315
ModKind::Loaded(items, _inline, _inner_span) => {
316316
walk_list!(visitor, visit_item, items)
317317
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
272272
hir::ItemKind::Fn(sig, generics, body_id)
273273
})
274274
}
275-
ItemKind::Mod(_, ref mod_kind) => match mod_kind {
275+
ItemKind::Mod(_, ref mod_kind) => match &**mod_kind {
276276
ModKind::Loaded(items, _, spans) => {
277277
hir::ItemKind::Mod(self.lower_mod(items, spans))
278278
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12841284
self.err_handler().span_err(span, "module cannot be declared unsafe");
12851285
}
12861286
// Ensure that `path` attributes on modules are recorded as used (cf. issue #35584).
1287-
if !matches!(mod_kind, ModKind::Loaded(_, Inline::Yes, _))
1287+
if !matches!(&**mod_kind, ModKind::Loaded(_, Inline::Yes, _))
12881288
&& !self.session.contains_name(&item.attrs, sym::path)
12891289
{
12901290
self.check_mod_file_item_asciionly(item.ident);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> State<'a> {
183183
}));
184184
self.print_ident(item.ident);
185185

186-
match mod_kind {
186+
match &**mod_kind {
187187
ModKind::Loaded(items, ..) => {
188188
self.nbsp();
189189
self.bopen();

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
129129

130130
// We don't want to recurse into anything other than mods, since
131131
// mods or tests inside of functions will break things
132-
if let ast::ItemKind::Mod(_, ModKind::Loaded(.., ref spans)) = item.kind {
132+
if let ast::ItemKind::Mod(_, ref mod_kind) = item.kind
133+
&& let ModKind::Loaded(.., ref spans) = &**mod_kind
134+
{
133135
let ast::ModSpans { inner_span: span, inject_use_span: _ } = *spans;
134136
let prev_tests = mem::take(&mut self.tests);
135137
noop_visit_item_kind(&mut item.kind, self);

compiler/rustc_expand/src/expand.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
673673
if matches!(attr.style, AttrStyle::Inner)
674674
&& matches!(
675675
item_inner.kind,
676-
ItemKind::Mod(
677-
_,
678-
ModKind::Unloaded | ModKind::Loaded(_, Inline::No, _),
679-
)
676+
ItemKind::Mod(_, ref mod_kind) if
677+
matches!(&**mod_kind, ModKind::Unloaded | ModKind::Loaded(_, Inline::No, _)),
680678
) =>
681679
{
682680
rustc_parse::fake_token_stream_for_item(
@@ -800,7 +798,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
800798
fn visit_item(&mut self, item: &'ast ast::Item) {
801799
match &item.kind {
802800
ItemKind::Mod(_, mod_kind)
803-
if !matches!(mod_kind, ModKind::Loaded(_, Inline::Yes, _)) =>
801+
if !matches!(&**mod_kind, ModKind::Loaded(_, Inline::Yes, _)) =>
804802
{
805803
feature_err(
806804
self.parse_sess,
@@ -1069,7 +1067,7 @@ impl InvocationCollectorNode for P<ast::Item> {
10691067
};
10701068

10711069
let ecx = &mut collector.cx;
1072-
let (file_path, dir_path, dir_ownership) = match mod_kind {
1070+
let (file_path, dir_path, dir_ownership) = match &**mod_kind {
10731071
ModKind::Loaded(_, inline, _) => {
10741072
// Inline `mod foo { ... }`, but we still need to push directories.
10751073
let (dir_path, dir_ownership) = mod_dir_path(
@@ -1107,7 +1105,7 @@ impl InvocationCollectorNode for P<ast::Item> {
11071105
);
11081106
}
11091107

1110-
*mod_kind = ModKind::Loaded(items, Inline::No, spans);
1108+
**mod_kind = ModKind::Loaded(items, Inline::No, spans);
11111109
node.attrs = attrs;
11121110
if node.attrs.len() > old_attrs_len {
11131111
// If we loaded an out-of-line module and added some inner attributes,

compiler/rustc_expand/src/parse/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn out_of_line_mod() {
319319
.unwrap();
320320

321321
if let ast::ItemKind::Mod(_, ref mod_kind) = item.kind {
322-
assert!(matches!(mod_kind, ast::ModKind::Loaded(items, ..) if items.len() == 2));
322+
assert!(matches!(&**mod_kind, ast::ModKind::Loaded(items, ..) if items.len() == 2));
323323
} else {
324324
panic!();
325325
}

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ impl<'a> Parser<'a> {
3636
let unsafety = self.parse_unsafety();
3737
self.expect_keyword(kw::Mod)?;
3838
let id = self.parse_ident()?;
39-
let mod_kind = if self.eat(&token::Semi) {
39+
let mod_kind = P(if self.eat(&token::Semi) {
4040
ModKind::Unloaded
4141
} else {
4242
self.expect(&token::OpenDelim(Delimiter::Brace))?;
4343
let (mut inner_attrs, items, inner_span) =
4444
self.parse_mod(&token::CloseDelim(Delimiter::Brace))?;
4545
attrs.append(&mut inner_attrs);
4646
ModKind::Loaded(items, Inline::Yes, inner_span)
47-
};
47+
});
4848
Ok((id, ItemKind::Mod(unsafety, mod_kind)))
4949
}
5050

0 commit comments

Comments
 (0)