1
Fork 0

resolve: Filter away macro prelude in modules with #[no_implicit_prelude] on 2018 edition

This commit is contained in:
Vadim Petrochenkov 2018-11-03 00:07:56 +03:00
parent e53a5ffd6b
commit 9ed9d6d0d0
5 changed files with 37 additions and 5 deletions

View file

@ -963,6 +963,10 @@ impl Session {
self.opts.debugging_opts.teach && self.diagnostic().must_teach(code) self.opts.debugging_opts.teach && self.diagnostic().must_teach(code)
} }
pub fn rust_2015(&self) -> bool {
self.opts.edition == Edition::Edition2015
}
/// Are we allowed to use features from the Rust 2018 edition? /// Are we allowed to use features from the Rust 2018 edition?
pub fn rust_2018(&self) -> bool { pub fn rust_2018(&self) -> bool {
self.opts.edition >= Edition::Edition2018 self.opts.edition >= Edition::Edition2018

View file

@ -660,11 +660,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
binding.map(|binding| (binding, Flags::MODULE, Flags::empty())) binding.map(|binding| (binding, Flags::MODULE, Flags::empty()))
} }
WhereToResolve::MacroUsePrelude => { WhereToResolve::MacroUsePrelude => {
match self.macro_use_prelude.get(&ident.name).cloned() { let mut result = Err(Determinacy::Determined);
Some(binding) => Ok((binding, Flags::PRELUDE, Flags::empty())), if use_prelude || self.session.rust_2015() {
None => Err(Determinacy::Determined), if let Some(binding) = self.macro_use_prelude.get(&ident.name).cloned() {
result = Ok((binding, Flags::PRELUDE, Flags::empty()));
} }
} }
result
}
WhereToResolve::BuiltinMacros => { WhereToResolve::BuiltinMacros => {
match self.builtin_macros.get(&ident.name).cloned() { match self.builtin_macros.get(&ident.name).cloned() {
Some(binding) => Ok((binding, Flags::PRELUDE, Flags::empty())), Some(binding) => Ok((binding, Flags::PRELUDE, Flags::empty())),
@ -682,7 +685,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
} }
} }
WhereToResolve::LegacyPluginHelpers => { WhereToResolve::LegacyPluginHelpers => {
if self.session.plugin_attributes.borrow().iter() if (use_prelude || self.session.rust_2015()) &&
self.session.plugin_attributes.borrow().iter()
.any(|(name, _)| ident.name == &**name) { .any(|(name, _)| ident.name == &**name) {
let binding = (Def::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper), let binding = (Def::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper),
ty::Visibility::Public, ident.span, Mark::root()) ty::Visibility::Public, ident.span, Mark::root())

View file

@ -0,0 +1,11 @@
// edition:2018
#[no_implicit_prelude]
mod bar {
fn f() {
::std::print!(""); // OK
print!(); //~ ERROR cannot find macro `print!` in this scope
}
}
fn main() {}

View file

@ -0,0 +1,10 @@
error: cannot find macro `print!` in this scope
--> $DIR/no_implicit_prelude-2018.rs:7:9
|
LL | print!(); //~ ERROR cannot find macro `print!` in this scope
| ^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?
error: aborting due to previous error

View file

@ -21,7 +21,10 @@ mod bar {
Vec::new(); //~ ERROR failed to resolve Vec::new(); //~ ERROR failed to resolve
().clone() //~ ERROR no method named `clone` found ().clone() //~ ERROR no method named `clone` found
} }
fn f() { ::foo::m!(); } fn f() {
::foo::m!();
println!(); // OK on 2015 edition (at least for now)
}
} }
fn main() {} fn main() {}