Skip to content

Commit 9855b34

Browse files
committed
submod_path: use id.span
1 parent 024af0b commit 9855b34

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

src/librustc_parse/parser/module.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ impl<'a> Parser<'a> {
4545
pub(super) fn parse_item_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
4646
let in_cfg = crate::config::process_configure_mod(self.sess, self.cfg_mods, attrs);
4747

48-
let id_span = self.token.span;
4948
let id = self.parse_ident()?;
5049
let (module, mut inner_attrs) = if self.eat(&token::Semi) {
5150
if in_cfg && self.recurse_into_file_modules {
5251
// This mod is in an external file. Let's go get it!
5352
let ModulePathSuccess { path, directory_ownership } =
54-
self.submod_path(id, &attrs, id_span)?;
55-
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?
53+
self.submod_path(id, &attrs)?;
54+
self.eval_src_mod(path, directory_ownership, id.to_string(), id.span)?
5655
} else {
5756
(ast::Mod { inner: DUMMY_SP, items: Vec::new(), inline: false }, Vec::new())
5857
}
@@ -99,7 +98,6 @@ impl<'a> Parser<'a> {
9998
&mut self,
10099
id: ast::Ident,
101100
outer_attrs: &[Attribute],
102-
id_sp: Span,
103101
) -> PResult<'a, ModulePathSuccess> {
104102
if let Some(path) = Parser::submod_path_from_attr(outer_attrs, &self.directory.path) {
105103
let directory_ownership = match path.file_name().and_then(|s| s.to_str()) {
@@ -125,10 +123,10 @@ impl<'a> Parser<'a> {
125123

126124
match self.directory.ownership {
127125
DirectoryOwnership::Owned { .. } => {
128-
paths.result.map_err(|err| self.span_fatal_err(id_sp, err))
126+
paths.result.map_err(|err| self.span_fatal_err(id.span, err))
129127
}
130-
DirectoryOwnership::UnownedViaBlock => self.error_decl_mod_in_block(id_sp, paths),
131-
DirectoryOwnership::UnownedViaMod => self.error_cannot_declare_mod_here(id_sp, paths),
128+
DirectoryOwnership::UnownedViaBlock => self.error_decl_mod_in_block(id.span, paths),
129+
DirectoryOwnership::UnownedViaMod => self.error_cannot_declare_mod_here(id.span, paths),
132130
}
133131
}
134132

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// Test that macro-expanded non-inline modules behave correctly
22

33
macro_rules! mod_decl {
4-
($i:ident) => { mod $i; } //~ ERROR Cannot declare a non-inline module inside a block
4+
($i:ident) => {
5+
mod $i;
6+
};
57
}
68

79
mod macro_expanded_mod_helper {
810
mod_decl!(foo); // This should search in the folder `macro_expanded_mod_helper`
911
}
1012

1113
fn main() {
12-
mod_decl!(foo);
14+
mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block
1315
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
error: Cannot declare a non-inline module inside a block unless it has a path attribute
2-
--> $DIR/macro-expanded-mod.rs:4:25
2+
--> $DIR/macro-expanded-mod.rs:14:15
33
|
4-
LL | ($i:ident) => { mod $i; }
5-
| ^^
6-
...
74
LL | mod_decl!(foo);
8-
| --------------- in this macro invocation
9-
|
10-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5+
| ^^^
116

127
error: aborting due to previous error
138

0 commit comments

Comments
 (0)