Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@ impl Session {
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?
pub fn rust_2018(&self) -> bool {
self.opts.edition >= Edition::Edition2018
Expand Down
12 changes: 8 additions & 4 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
binding.map(|binding| (binding, Flags::MODULE, Flags::empty()))
}
WhereToResolve::MacroUsePrelude => {
match self.macro_use_prelude.get(&ident.name).cloned() {
Some(binding) => Ok((binding, Flags::PRELUDE, Flags::empty())),
None => Err(Determinacy::Determined),
let mut result = Err(Determinacy::Determined);
if use_prelude || self.session.rust_2015() {
if let Some(binding) = self.macro_use_prelude.get(&ident.name).cloned() {
result = Ok((binding, Flags::PRELUDE, Flags::empty()));
}
}
result
}
WhereToResolve::BuiltinMacros => {
match self.builtin_macros.get(&ident.name).cloned() {
Expand All @@ -682,7 +685,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
}
}
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) {
let binding = (Def::NonMacroAttr(NonMacroAttrKind::LegacyPluginHelper),
ty::Visibility::Public, ident.span, Mark::root())
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/hygiene/no_implicit_prelude-2018.rs
Original file line number Diff line number Diff line change
@@ -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() {}
10 changes: 10 additions & 0 deletions src/test/ui/hygiene/no_implicit_prelude-2018.stderr
Original file line number Diff line number Diff line change
@@ -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

5 changes: 4 additions & 1 deletion src/test/ui/hygiene/no_implicit_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ mod bar {
Vec::new(); //~ ERROR failed to resolve
().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() {}