-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Remove braces from Rust 2015 panic macro #88919
Conversation
☔ The latest upstream changes (presumably #89047) made this pull request unmergeable. Please resolve the merge conflicts. |
@rfcbot merge This removes the extra This is a subtle breaking change: fn main() {
let a: &usize;
a = &panic!();
} used to compile, and will now fail with:
We didn't see any case of this during the 2021 crater run when switching to the 2021 panic macro, which also doesn't have this extra Grepping for cc @rust-lang/lang |
Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I don't think we should be landing breakage without strong motivation, particularly when we are already using the edition mechanism to transition users to a space where they'll never encounter this inconsistency. Can we elaborate on the reasoning to do this? The PR description says that the discrepancy is annoying, but it's not clear to me which context that's in; I wouldn't expect any Rust user to encounter it, and I feel like std doesn't really get simpler if we omit a couple of braces on a macro that's unlikely to get touched much. I think we need stronger justification. If we had the opportunity to fully align the macros across all editions, I think that would be a different discussion, but this PR at least doesn't unify any macros in core/std as far as I can tell... and from past discussions my understanding is that isn't possible. |
This inconsistency is not current migrated by
I actually discovered this subtle difference when I tried to align macros across all editions; I was experimenting doing thhe following in the rustc_builtin_macros for
The rationale behind the attempted change is to simplify the logic of current non_fmt_panic so that it will only need to check for legacy panic calls rather than having to inspect the arguments again. Appearantly when I make the change the tests break, and I realized this inconsistency, and |
It's expected that there are gaps forever in between editions; I don't think whether cargo fix changes this really matters for that? Most users (particularly those not upgrading to new editions) are not running cargo fix regardless.
The transition would only be made more painful by breaking users on 2015, right? They'd not be able to run cargo fix, as it doesn't support by default running with a broken compilation in the baseline compiler. Edition migrations target the intersection of two editions, not immediately putting you into the new edition. If there is a major benefit to compiler internals, then we could consider breaking users, so perhaps seeing the benefits there would be a good motivation -- if it's a fairly local increase in complexity, the edition mechanism was an explicit choice in tradeoffs that made the call that we're OK with more complex internals in favor of avoiding breakage. |
Another option is changing the language/compiler to make the version without braces work as well in this situation. |
I agree with @Mark-Simulacrum that I would want to see more discussion of the motivation here. Why was this change in Rust 2021, for starters? |
|
I think this is a case where brace introduces an opportunity for coercion. It's similar to e.g. this case: let x: &&dyn Any = &&1; // This doesn't work
let x: &&dyn Any = &{&1}; // This works |
@nikomatsakis This is a difference between std::panic and core::panic in Rust 2015/2018, see #80846. In Rust 2021, std::panic and core::panic are the same, removing this difference. |
OK. I see now. I'm still feeling a bit skeptical-- as Marc says, the point of editions is not permit permanent differences between editions, and to ensure that users have to "opt-in" to see them. We don't necessarily mandate |
Marking this issue as Nominated since it seems that this FCP may be stalled and it seems like it's probably due for discussion. |
(from #88860 (comment)) Clippy currently relies on the exact expansion of Although the long term goal should be for clippy to not depend on std's implementation details but I think this is another data point showing that the discrepency is bad and the brace should be removed. |
(clippy team member here) No, we definitely should not fossilize the panic implementation because of clippy, we should fix the resugaring |
I might be misinterpreting @nbdd0121's comment but they seem to be advocating for not fossilizing the panic impl and removing the braces. Is that also what you mean by fixing the resugaring @Manishearth or am I misunderstanding your desired path to resolution? |
Oh I misinterpreted stuff, sorry. I meant to say: rustc should not avoid updating this because of clippy; and in the long term we need to come up with a better way to do resugaring in rust/clippy so this is never a problem. |
☔ The latest upstream changes (presumably #90067) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We discussed this PR during today's libs-api team meeting and our general consensus was that we would prefer to not modify the 2015 panic macro without a strong motivation, and it was not clear to us that this change is strongly motivated. Our reasoning was that this was already fixed as part of the 2021 edition boundary, and so anyone who is negatively affected by this inconsistency can already fix it by using the latest edition starting tomorrow. It seems that the motivation in this PR is that the discrepancy is confusing and makes continued maintenance and development around panics more difficult. If this continues to be a recurring issue across the project we can revisit this decision, but for now we'd prefer to prioritize avoiding breakage, even if it's only theoretical breakage. |
There isn't much detail in the meeting notes. From the meeting notes:
Is the clippy thing discussed? |
Clippy has basically a bug, which should be fixed, buy the appropriate fix is in clippy, not changing the standard library implementation in a way that includes at least theoretical breakage. So it's not really motivation for this patch. |
Yes. Insofar as we noted that the clippy team had advised that we not focus on clippy maintenance difficulties when making decisions about std APIs. @Manishearth correct me if I'm wrong. |
Fix manual_assert and match_wild_err_arm for `#![no_std]` and Rust 2021 Rust 2015 `std::panic!` has a wrapping block while `core::panic!` and Rust 2021 `std::panic!` does not. See rust-lang/rust#88919 for details. Note that the test won't pass until clippy changes in rust-lang/rust#88860 is synced. --- changelog: Fix [`manual_assert`] and [`match_wild_err_arm`] for `#![no_std]` and Rust 2021. Fixes #7723
Closing according to #88919 (comment) . |
I rediscovered #80846 myself when tweaking panic macros for const panics. I find this discrepancy between core panic, 2021 panic and 2015 std panic confusing and a little bit annoying.
Given that #80846 suggests that the braces is not there for purpose, and edition 2021 crater run does not seem to catch any crates depending on this behaviour (the difference is only triggered when using
&panic!()
), I think it shall be fine to remove this and align panic macros across editions.Fix rust-lang/rust-clippy#7723
r? @m-ou-se