Skip to content

Commit 930f877

Browse files
committed
auto merge of #19262 : murarth/rust/module-path-fix, r=jakub-
Closes #18859
2 parents 8fb027e + 6a5fc50 commit 930f877

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/libsyntax/ext/expand.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,19 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
412412
let mut new_items = match it.node {
413413
ast::ItemMac(..) => expand_item_mac(it, fld),
414414
ast::ItemMod(_) | ast::ItemForeignMod(_) => {
415-
fld.cx.mod_push(it.ident);
415+
let valid_ident =
416+
it.ident.name != parse::token::special_idents::invalid.name;
417+
418+
if valid_ident {
419+
fld.cx.mod_push(it.ident);
420+
}
416421
let macro_escape = contains_macro_escape(new_attrs.as_slice());
417422
let result = with_exts_frame!(fld.cx.syntax_env,
418423
macro_escape,
419424
noop_fold_item(it, fld));
420-
fld.cx.mod_pop();
425+
if valid_ident {
426+
fld.cx.mod_pop();
427+
}
421428
result
422429
},
423430
_ => {

src/test/run-pass/issue-18859.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
mod foo {
12+
pub mod bar {
13+
pub mod baz {
14+
pub fn name() -> &'static str {
15+
module_path!()
16+
}
17+
}
18+
}
19+
}
20+
21+
fn main() {
22+
assert_eq!(module_path!(), "issue-18859");
23+
assert_eq!(foo::bar::baz::name(), "issue-18859::foo::bar::baz");
24+
}

0 commit comments

Comments
 (0)