-
Notifications
You must be signed in to change notification settings - Fork 13k
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
regression: a value of type HashMap<Pulse, u64>
cannot be built from
#135669
Comments
Minimized (zipped for your convenience: foo.zip): src/lib.rs // This crate is in edition 2021
bar::create_macro! {{
// This code works on edition 2021, but not edition 2018
let _ = [1i32].into_iter().collect::<Vec<i32>>();
}}
create_fn!(); bar/src/lib.rs // This crate is in edition 2018
#[macro_export]
macro_rules! create_macro {
($body:tt) => {
macro_rules! create_fn {
() => {
fn a() {
$body
}
};
}
};
} Cargo.toml[workspace]
members = ["bar"]
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[dependencies]
bar = { path = "bar" } bar/Cargo.toml[package]
edition = "2018"
name = "bar"
version = "0.1.0" In stable, the function body is compiled as edition 2021. In beta, it is compiled as edition 2018. For context: This is the intended usage pattern of the parameterized_test crate. |
Hm, yea, I can see how that doesn't look to be working quite as I intended. I would expect substitutions to retain whatever edition the input has, but it makes sense that the macro_rules compiler is ignoring that. I would be fine reverting #133274 if that is what people want. It did not have a high importance for edition compatibility. I don't recall how many crates would fail in the 2024 edition without it, though. I think it should eventually be fixed, but may require deeper changes if it is possible. |
@rustbot labels -T-libs +T-lang +I-lang-nominated Let's nominate to sign off on this regression. I talked this one over with @ehuss, and the conclusion we came to is that it's probably best to just accept this if the breakage looks as minimal as what we're seeing here. Keeping the #133274 PR is helpful to the edition migration, and more broadly, this behavior -- while itself not right either -- at least gives the caller the ability to fix this problem. What it does, essentially, is to leak out to the caller the edition of the crate that defines the macro, but we have of course other places that's also true, e.g.: |
I think the model is this---
And then the question I don't know is:
Or is my mental model broken here somehow...? Are the editions of the pasted-in tokens being changed? |
@theemathas do you know whether this code would error (building on your example)... // code in Edition 2024
bar::create_macro! {{
let gen = 3; // <-- ERROR
}}
create_fn!(); ...my expectation is that it will, because the span of the |
@nikomatsakis Your example with Will follow up here shortly with some more information. |
@ehuss I see -- that is surprising to me (that it overwrites the edition of the substitutions). It is not my mental model at all. I'm trying to remember now if we decided that ultimately that was better at some point or what. That said, if we do that, I think that the model of "use the edition of the crate definition" feels better than "edition of the crate consumer". |
This isn't actually "inference". See https://doc.rust-lang.org/edition-guide/rust-2021/IntoIterator-for-arrays.html The token used is the |
I don't think there is a general rule of thumb to describe which tokens affect edition behavior. It depends on the particular feature. For For To try to explain the example above a little more explicitly, let's look at the behavior on stable (before #133274).
After #133274, it is:
Note that there is something really wonky here which I don't really understand. I don't think it is related to this issue, but it is weird looking. I unfortunately don't remember the context from #84429. (For the record, I still don't fully understand expansion contexts, and so this is just the best interpretation I have.) |
The text was updated successfully, but these errors were encountered: