Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b827952

Browse files
committed
Associate multiple with a crate too.
1 parent e9035f7 commit b827952

File tree

17 files changed

+28
-27
lines changed

17 files changed

+28
-27
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ pub struct WhereEqPredicate {
510510
pub struct Crate {
511511
pub attrs: Vec<Attribute>,
512512
pub items: Vec<P<Item>>,
513-
pub span: Span,
513+
pub spans: ModSpans,
514514
/// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold
515515
/// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that.
516516
pub id: NodeId,

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,11 +1108,12 @@ pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
11081108
}
11091109

11101110
pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
1111-
let Crate { attrs, items, span, id, is_placeholder: _ } = krate;
1111+
let Crate { attrs, items, spans, id, is_placeholder: _ } = krate;
11121112
vis.visit_id(id);
11131113
visit_attrs(attrs, vis);
11141114
items.flat_map_in_place(|item| vis.flat_map_item(item));
1115-
vis.visit_span(span);
1115+
let ModSpans { inner_span } = spans;
1116+
vis.visit_span(inner_span);
11161117
}
11171118

11181119
// Mutates one item into possibly many items.
@@ -1536,7 +1537,7 @@ impl DummyAstNode for Crate {
15361537
Crate {
15371538
attrs: Default::default(),
15381539
items: Default::default(),
1539-
span: Default::default(),
1540+
spans: Default::default(),
15401541
id: DUMMY_NODE_ID,
15411542
is_placeholder: Default::default(),
15421543
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
456456
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
457457

458458
self.with_hir_id_owner(CRATE_NODE_ID, |lctx| {
459-
let module = lctx.lower_mod(&c.items, c.span);
459+
let module = lctx.lower_mod(&c.items, c.spans.inner_span);
460460
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
461461
hir::OwnerNode::Crate(lctx.arena.alloc(module))
462462
});

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
112112
fn visit_crate(&mut self, c: &mut ast::Crate) {
113113
let prev_tests = mem::take(&mut self.tests);
114114
noop_visit_crate(c, self);
115-
self.add_test_cases(ast::CRATE_NODE_ID, c.span, prev_tests);
115+
self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests);
116116

117117
// Create a main function to run our tests
118118
c.items.push(mk_main(&mut self.cx));

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Annotatable {
6767
Annotatable::Param(ref p) => p.span,
6868
Annotatable::FieldDef(ref sf) => sf.span,
6969
Annotatable::Variant(ref v) => v.span,
70-
Annotatable::Crate(ref c) => c.span,
70+
Annotatable::Crate(ref c) => c.spans.inner_span,
7171
}
7272
}
7373

compiler/rustc_expand/src/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::token;
1212
use rustc_ast::tokenstream::TokenStream;
1313
use rustc_ast::visit::{self, AssocCtxt, Visitor};
1414
use rustc_ast::{AssocItemKind, AstLike, AstLikeWrapper, AttrStyle, ExprKind, ForeignItemKind};
15-
use rustc_ast::{Inline, ItemKind, MacArgs, MacStmtStyle, MetaItemKind, ModKind, ModSpans};
15+
use rustc_ast::{Inline, ItemKind, MacArgs, MacStmtStyle, MetaItemKind, ModKind};
1616
use rustc_ast::{NestedMetaItem, NodeId, PatKind, StmtKind, TyKind};
1717
use rustc_ast_pretty::pprust;
1818
use rustc_data_structures::map_in_place::MapInPlace;
@@ -364,7 +364,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
364364
}
365365

366366
pub fn expand_crate(&mut self, krate: ast::Crate) -> ast::Crate {
367-
let file_path = match self.cx.source_map().span_to_filename(krate.span) {
367+
let file_path = match self.cx.source_map().span_to_filename(krate.spans.inner_span) {
368368
FileName::Real(name) => name
369369
.into_local_path()
370370
.expect("attempting to resolve a file path in an external file"),
@@ -1091,7 +1091,7 @@ impl InvocationCollectorNode for P<ast::Item> {
10911091
ModKind::Unloaded => {
10921092
// We have an outline `mod foo;` so we need to parse the file.
10931093
let old_attrs_len = attrs.len();
1094-
let ParsedExternalMod { items, inner_span, file_path, dir_path, dir_ownership } =
1094+
let ParsedExternalMod { items, spans, file_path, dir_path, dir_ownership } =
10951095
parse_external_mod(
10961096
&ecx.sess,
10971097
ident,
@@ -1112,7 +1112,7 @@ impl InvocationCollectorNode for P<ast::Item> {
11121112
);
11131113
}
11141114

1115-
*mod_kind = ModKind::Loaded(items, Inline::No, ModSpans { inner_span });
1115+
*mod_kind = ModKind::Loaded(items, Inline::No, spans);
11161116
node.attrs = attrs;
11171117
if node.attrs.len() > old_attrs_len {
11181118
// If we loaded an out-of-line module and added some inner attributes,

compiler/rustc_expand/src/module.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct ModulePathSuccess {
2828

2929
crate struct ParsedExternalMod {
3030
pub items: Vec<P<Item>>,
31-
pub inner_span: Span,
31+
pub spans: ModSpans,
3232
pub file_path: PathBuf,
3333
pub dir_path: PathBuf,
3434
pub dir_ownership: DirOwnership,
@@ -69,13 +69,13 @@ crate fn parse_external_mod(
6969
(items, inner_span, mp.file_path)
7070
};
7171
// (1) ...instead, we return a dummy module.
72-
let (items, ModSpans { inner_span }, file_path) =
72+
let (items, spans, file_path) =
7373
result.map_err(|err| err.report(sess, span)).unwrap_or_default();
7474

7575
// Extract the directory path for submodules of the module.
7676
let dir_path = file_path.parent().unwrap_or(&file_path).to_owned();
7777

78-
ParsedExternalMod { items, inner_span, file_path, dir_path, dir_ownership }
78+
ParsedExternalMod { items, spans, file_path, dir_path, dir_ownership }
7979
}
8080

8181
crate fn mod_dir_path(

compiler/rustc_expand/src/placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn placeholder(
4949
AstFragmentKind::Crate => AstFragment::Crate(ast::Crate {
5050
attrs: Default::default(),
5151
items: Default::default(),
52-
span,
52+
spans: ast::ModSpans { inner_span: span, ..Default::default() },
5353
id,
5454
is_placeholder: true,
5555
}),

compiler/rustc_metadata/src/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ impl<'a> CrateLoader<'a> {
899899

900900
fn report_unused_deps(&mut self, krate: &ast::Crate) {
901901
// Make a point span rather than covering the whole file
902-
let span = krate.span.shrink_to_lo();
902+
let span = krate.spans.inner_span.shrink_to_lo();
903903
// Complain about anything left over
904904
for (name, entry) in self.sess.opts.externs.iter() {
905905
if let ExternLocation::FoundInLibrarySearchDirectories = entry.location {

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub fn fake_token_stream(sess: &ParseSess, nt: &Nonterminal) -> TokenStream {
331331
pub fn fake_token_stream_for_crate(sess: &ParseSess, krate: &ast::Crate) -> TokenStream {
332332
let source = pprust::crate_to_string_for_macros(krate);
333333
let filename = FileName::macro_expansion_source_code(&source);
334-
parse_stream_from_source_str(filename, source, sess, Some(krate.span))
334+
parse_stream_from_source_str(filename, source, sess, Some(krate.spans.inner_span))
335335
}
336336

337337
pub fn parse_cfg_attr(

0 commit comments

Comments
 (0)