resolve: Fix access to extern and stdlib prelude from opaque macros

Ok, it's hard to explain what happens, but identifier's hygienic contexts need to be "adjusted" to modules/scopes before they are resolved in them.
To be resolved in all kinds on preludes the identifier needs to be adjusted to the root expansion (aka "no expansion").

Previously this was done for the `macro m() { ::my_crate::foo }` case, but forgotten for all other cases.
This commit is contained in:
Vadim Petrochenkov
2019-07-06 19:45:23 +03:00
parent f923942094
commit 0ec6ea7333
5 changed files with 42 additions and 0 deletions
+1
View File
@@ -2247,6 +2247,7 @@ fn resolve_ident_in_lexical_scope(&mut self,
}
if !module.no_implicit_prelude {
ident.span.adjust(Mark::root());
if ns == TypeNS {
if let Some(binding) = self.extern_prelude_get(ident, !record_used) {
return Some(LexicalScopeBinding::Item(binding));
+1
View File
@@ -856,6 +856,7 @@ struct Flags: u8 {
match self.hygienic_lexical_parent(module, &mut ident.span) {
Some(parent_module) => WhereToResolve::Module(parent_module),
None => {
ident.span.adjust(Mark::root());
use_prelude = !module.no_implicit_prelude;
match ns {
TypeNS => WhereToResolve::ExternPrelude,
@@ -0,0 +1,3 @@
#![feature(decl_macro)]
pub macro stdlib_macro() {}
@@ -0,0 +1,21 @@
// check-pass
// aux-build:stdlib-prelude.rs
#![feature(decl_macro)]
#![feature(prelude_import)]
extern crate stdlib_prelude;
#[prelude_import]
use stdlib_prelude::*;
macro mac() {
mod m {
use std::mem; // OK (extern prelude)
stdlib_macro!(); // OK (stdlib prelude)
}
}
mac!();
fn main() {}
@@ -0,0 +1,16 @@
// check-pass
#![feature(decl_macro)]
macro mac() {
mod m {
fn f() {
std::mem::drop(0); // OK (extern prelude)
drop(0); // OK (stdlib prelude)
}
}
}
mac!();
fn main() {}