-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
document and test the precise span that triggers edition-dependent behavior #86539
Comments
I did some digging through the implementations. These are the spans used by each of the edition-dependent behaviours:
I have no clue what happens if we somehow manage to make a |
I made a proc macro that allows changing the edition of a single token and did some experiments:
|
For closures: The span of rust/compiler/rustc_span/src/lib.rs Lines 657 to 671 in 75ed342
The logic of |
The same |
Impressive investigation! Note that mixing spans can also be done by // In a crate `::a`
#[macro_export]
macro_rules! mk_m {( $std:ident ) => (
#[macro_export]
macro_rules! m {( $panic:ident ) => ( $std::$panic!() )}
)}
// In a crate `::b`
::a::mk_m!(std);
// In a crate `::c`
m!(panic); // <- `std` is spanned at `::b`, `::` and `!` at `::a` (I think), and `panic` here, at `::c`. |
Similar existing issue - #50122. |
This is an example I just posted on Zulip: // library crate in Rust 2021:
#[macro_export]
macro_rules! x { ($t:tt) => { $t::panic!("{{"); }; }
#[macro_export]
macro_rules! y { ($t:tt) => { std::$t!("{{"); }; }
// binary crate in Rust 2018:
use dep2021::*;
macro_rules! z {
(x) => { x!(std); };
(y) => { y!(panic); };
}
fn main() {
x!(std); // 2021
y!(panic); // 2021
z!(x); // 2018 !!
z!(y); // 2021
} An |
My hunch is that most of the edition-dependent features don't have a documented bit of text that we use to figure out what edition they are-- and that we don't have tests for that logic. We should clarify this and document the "edition span" in the Edition Migration Guide, and then make tests that check that it works correctly.
The text was updated successfully, but these errors were encountered: