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

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2671,7 +2671,9 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder {
26712671

26722672
fn visit_item(&mut self, item: &'tcx ast::Item) {
26732673
if self.target_module == item.id {
2674-
if let ItemKind::Mod(_, ModKind::Loaded(items, _inline, mod_spans)) = &item.kind {
2674+
if let ItemKind::Mod(_, mod_kind) = &item.kind
2675+
&& let ModKind::Loaded(items, _inline, mod_spans) = &**mod_kind
2676+
{
26752677
let inject = mod_spans.inject_use_span;
26762678
if is_span_suitable_for_use_injection(inject) {
26772679
self.first_legal_span = Some(inject);

compiler/rustc_resolve/src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ fn soft_custom_inner_attributes_gate(path: &ast::Path, invoc: &Invocation) -> bo
164164
[seg1, seg2] if seg1.ident.name == sym::rustfmt && seg2.ident.name == sym::skip => {
165165
if let InvocationKind::Attr { item, .. } = &invoc.kind {
166166
if let Annotatable::Item(item) = item {
167-
if let ItemKind::Mod(_, ModKind::Loaded(_, Inline::No, _)) = item.kind {
167+
if let ItemKind::Mod(_, ref mod_kind) = item.kind
168+
&& let ModKind::Loaded(_, Inline::No, _) = &**mod_kind
169+
{
168170
return true;
169171
}
170172
}

src/tools/clippy/clippy_lints/src/duplicate_mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ impl_lint_pass!(DuplicateMod => [DUPLICATE_MOD]);
6363

6464
impl EarlyLintPass for DuplicateMod {
6565
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
66-
if let ItemKind::Mod(_, ModKind::Loaded(_, Inline::No, mod_spans)) = &item.kind
66+
if let ItemKind::Mod(_, mod_kind) = &item.kind
67+
&& let ModKind::Loaded(_, Inline::No, mod_spans) = &**mod_kind
6768
&& let FileName::Real(real) = cx.sess().source_map().span_to_filename(mod_spans.inner_span)
6869
&& let Some(local_path) = real.into_local_path()
6970
&& let Ok(absolute_path) = local_path.canonicalize()

src/tools/clippy/clippy_lints/src/single_component_path_imports.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ fn track_uses(
114114
}
115115

116116
match &item.kind {
117-
ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) => {
118-
check_mod(cx, items);
119-
},
117+
ItemKind::Mod(_, mod_kind) => {
118+
if let ModKind::Loaded(ref items, ..) = **mod_kind {
119+
check_mod(cx, items);
120+
}
121+
}
120122
ItemKind::MacroDef(MacroDef { macro_rules: true, .. }) => {
121123
macros.push(item.ident.name);
122124
},

src/tools/clippy/clippy_utils/src/ast_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
273273
},
274274
(Mod(lu, lmk), Mod(ru, rmk)) => {
275275
lu == ru
276-
&& match (lmk, rmk) {
276+
&& match (&**lmk, &**rmk) {
277277
(ModKind::Loaded(litems, linline, _), ModKind::Loaded(ritems, rinline, _)) => {
278278
linline == rinline && over(litems, ritems, |l, r| eq_item(l, r, eq_item_kind))
279279
},

src/tools/rustfmt/src/items.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,10 +3320,12 @@ pub(crate) fn rewrite_extern_crate(
33203320

33213321
/// Returns `true` for `mod foo;`, false for `mod foo { .. }`.
33223322
pub(crate) fn is_mod_decl(item: &ast::Item) -> bool {
3323-
!matches!(
3324-
item.kind,
3325-
ast::ItemKind::Mod(_, ast::ModKind::Loaded(_, ast::Inline::Yes, _))
3326-
)
3323+
if let ast::ItemKind::Mod(_, ref mod_kind) = item.kind {
3324+
if let ast::ModKind::Loaded(_, ast::Inline::Yes, _) = &**mod_kind {
3325+
return false;
3326+
}
3327+
}
3328+
true
33273329
}
33283330

33293331
pub(crate) fn is_use_item(item: &ast::Item) -> bool {

src/tools/rustfmt/src/modules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
156156
&module_item.item,
157157
Module::new(
158158
module_item.item.span,
159-
Some(Cow::Owned(sub_mod_kind.clone())),
159+
Some(Cow::Owned((**sub_mod_kind).clone())),
160160
Cow::Owned(vec![]),
161161
Cow::Owned(vec![]),
162162
),
@@ -183,7 +183,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
183183
&item,
184184
Module::new(
185185
span,
186-
Some(Cow::Owned(sub_mod_kind.clone())),
186+
Some(Cow::Owned((**sub_mod_kind).clone())),
187187
Cow::Owned(vec![]),
188188
Cow::Owned(vec![]),
189189
),

0 commit comments

Comments
 (0)