-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
don't ask what edition we are in; ask what edition a span is in #50999
Closed
nikomatsakis
wants to merge
2
commits into
rust-lang:master
from
nikomatsakis:issue-50172-macro-edition-hygiene
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/test/ui/rust-2018/auxiliary/inject-2015-use-root-module-lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// this is a rust 2015 crate | ||
|
||
#[macro_export] | ||
macro_rules! inject_me_at_the_root { | ||
($name1:ident, $name2:ident) => { | ||
mod $name1 { | ||
pub(crate) const THE_CONSTANT: u32 = 22; | ||
} | ||
|
||
fn $name2() -> u32 { | ||
// Key point: this `use` statement -- in Rust 2018 -- | ||
// would be an error. But because this crate is in Rust | ||
// 2015, it works, even when executed from a Rust 2018 | ||
// environment. | ||
use $name1::THE_CONSTANT; | ||
THE_CONSTANT | ||
} | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! print_me { | ||
($p:path) => { | ||
{ | ||
use $p as V; | ||
println!("{}", V); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags:--edition 2018 | ||
// aux-build:inject-2015-use-root-module-lib.rs | ||
|
||
// The macro `inject_me_at_the_root!` generates some code that uses | ||
// `use x::y` to name the global item `x`. In Rust 2018, that should | ||
// be `use crate::x::y`, but we test here that we still accept it, | ||
// as `inject_2015_lib` is in the 2015 edition. | ||
|
||
#[macro_use] | ||
extern crate inject_2015_use_root_module_lib; | ||
|
||
inject_me_at_the_root!(x, y); | ||
|
||
fn main() { | ||
println!("Hello, world: {}", y()); | ||
|
||
// This path comes out as an error, because `x::y` comes from Rust 2018 | ||
print_me!(x::y); //~ ERROR unresolved import `x::y` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags:--edition 2018 | ||
// aux-build:inject-2015-use-root-module-lib.rs | ||
// run-pass | ||
|
||
// The macro `inject_me_at_the_root!` generates some code that uses | ||
// `use x::y` to name the global item `x`. In Rust 2018, that should | ||
// be `use crate::x::y`, but we test here that we still accept it, | ||
// as `inject_2015_lib` is in the 2015 edition. | ||
|
||
#[macro_use] | ||
extern crate inject_2015_use_root_module_lib; | ||
|
||
inject_me_at_the_root!(x, y); | ||
|
||
fn main() { | ||
println!("Hello, world: {}", y()); | ||
|
||
print_me!(crate::x::y); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably just implement
Default
forEdition
."Local edition" needs to be kept in global data anyway because it's an "edition of
SyntaxContext(0)
aka not-a-macro-expansion" and it's set from default-defaultEdition2015
toself.opts.edition
immediately after options are parsed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. True, though I'm not wild about the fact that we rely so heavily on global / TLS data for this stuff.