-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it #138717
Conversation
r? @Noratrieb rustbot has assigned @Noratrieb. Use |
r? WaffleLapkin |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
I need to think. |
This comment has been minimized.
This comment has been minimized.
One alternative not requiring compiler hacks is to put it into a separate 2021 edition crate and then reexport it from libcore, but that may (or may not) cause some larger build/infrastructure issues. |
Probably will. And no one wants to spend a day debugging the CI issues when it does. And speaking from my POV as libs reviewer, I strongly prefer core's current dependency graph to it having any dependencies at all. |
It really should be. If this isn't temporary, it means that Rust 2024 isn't as expressive as Rust 2021. That would be a problem! Opened #138718 to track that. |
Definitely considered that. But adding a dependency to core isn't trivial. And unfortunately we don't have Luckily this attribute is very simple to implement, and thus simple to remove again. (It just sets the SyntaxExtension::edition field.) |
Is it reasonable to try running crater with the identity() fix to see how much code breaks? Broken code probably would need to look like |
Considering that pin!() is used often in aync application code (not just libraries), I think crater might not be very representative, as there might be a lot of uses in code that is not on (public) github or crates.io. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@bors r=WaffleLapkin |
#[test] | ||
#[cfg(not(bootstrap))] | ||
fn temp_lifetime() { | ||
// Check that temporary lifetimes work as in Rust 2021. | ||
// Regression test for https://github.com/rust-lang/rust/issues/138596 | ||
match std::pin::pin!(foo(&mut 0)) { | ||
_ => {} | ||
} | ||
async fn foo(_: &mut usize) {} | ||
} |
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.
When I tried to work on this with my failed attempt, I thought of extra tests which seem important for pin
, so you may want to add them if you like them 🙂:
fn transitive_extension {
async fn temporary() {}
// `pin!` witnessed in the wild being used like this, even if it yields
// a `Pin<&mut &mut impl Unpin>`; it does work because `pin!`
// happens to transitively extend the lifespan of `temporary()`.
let p = pin!(&mut temporary());
let _use = p;
}
as well as the following things which have to fail to compile to guarantee the soundness of pin!
: pin!
needs to consume ownership of the argument given to it, by having moved that value to its own super let
local, or by having funneled it through a value expression such as { $value }
.
-
struct NotCopy<T>(T); #[allow(unused_mut)] let mut pointee = NotCopy(core::marker::PhantomPinned); pin!(pointee); let _moved = pointee; // Error, use of moved value.
-
struct NotCopy<T>(T); let mut pointee = NotCopy(core::marker::PhantomPinned); pin!(*&mut pointee); // Error, cannot move out of `&mut`, `NotCopy` is not `Copy`. let _moved = pointee;
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.
Thanks! Would you mind putting that in a PR?
…pkin Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it Fixes a regression, see issue below. This is a temporary fix, super let is the real solution. Closes rust-lang#138596
Rollup of 10 pull requests Successful merges: - rust-lang#138364 (ports the compiler test cases to new rust_intrinsic format) - rust-lang#138570 (add `naked_functions_target_feature` unstable feature) - rust-lang#138623 ([bootstrap] Use llvm_runtimes for compiler-rt) - rust-lang#138627 (Autodiff cleanups) - rust-lang#138669 (tests: accept some noise from LLVM 21 in symbols-all-mangled) - rust-lang#138706 (Improve bootstrap git modified path handling) - rust-lang#138709 (Update GCC submodule) - rust-lang#138717 (Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it) - rust-lang#138721 (Use explicit cpu in some asm and codegen tests.) - rust-lang#138728 (Update `compiler-builtins` to 0.1.152) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#138364 (ports the compiler test cases to new rust_intrinsic format) - rust-lang#138570 (add `naked_functions_target_feature` unstable feature) - rust-lang#138623 ([bootstrap] Use llvm_runtimes for compiler-rt) - rust-lang#138627 (Autodiff cleanups) - rust-lang#138669 (tests: accept some noise from LLVM 21 in symbols-all-mangled) - rust-lang#138706 (Improve bootstrap git modified path handling) - rust-lang#138709 (Update GCC submodule) - rust-lang#138717 (Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it) - rust-lang#138721 (Use explicit cpu in some asm and codegen tests.) - rust-lang#138728 (Update `compiler-builtins` to 0.1.152) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#138364 (ports the compiler test cases to new rust_intrinsic format) - rust-lang#138570 (add `naked_functions_target_feature` unstable feature) - rust-lang#138623 ([bootstrap] Use llvm_runtimes for compiler-rt) - rust-lang#138627 (Autodiff cleanups) - rust-lang#138669 (tests: accept some noise from LLVM 21 in symbols-all-mangled) - rust-lang#138706 (Improve bootstrap git modified path handling) - rust-lang#138709 (Update GCC submodule) - rust-lang#138717 (Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it) - rust-lang#138721 (Use explicit cpu in some asm and codegen tests.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#138717 - jdonszelmann:pin-macro, r=WaffleLapkin Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it Fixes a regression, see issue below. This is a temporary fix, super let is the real solution. Closes rust-lang#138596
Fixes a regression, see issue below. This is a temporary fix, super let is the real solution.
Closes #138596