-
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
pin macro no longer lifetime extends argument #138596
Comments
This seems very likely to be related to |
Thank you for the report! It would be useful to bisect the regression using cargo-bisect-rustc to make it easier to figure out what happened and ping the relevant people. |
Running a bisect with the OP code does indeed point the finger at the Regression in rust-lang-ci@6d75903 bisected with cargo-bisect-rustc v0.6.9Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc Trying to bisect the manual expansion code from #138596 (comment) in the 2024 edition doesn't seem find anything (it keeps running well past the introduction of the 2024 edition). |
Looks like this change: https://doc.rust-lang.org/edition-guide/rust-2024/temporary-tail-expr-scope.html#temporary-scope-may-be-narrowed the block no longer extends the lifetime. |
@danielhenrymantilla since the idea of the pin macro comes from you I think |
I think I have a fix for this. Can anyone offhand think if there would be any problems with the following? diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs
index 7fcd19f67ee..08c0f663588 100644
--- a/library/core/src/pin.rs
+++ b/library/core/src/pin.rs
@@ -2014,5 +2014,5 @@ unsafe impl<T: ?Sized> PinCoerceUnsized for *mut T {}
//
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
// for more info.
- $crate::pin::Pin::<&mut _> { __pointer: &mut { $value } }
+ $crate::pin::Pin::<&mut _> { __pointer: &mut ( $value ) }
} I don't see a particular reason that |
Oh, hm, maybe that won't work... There are some limitations with mutability.... |
The main reason for the block is to force moving the value to take ownership, otherwise this works and is UB (playground): #![feature(unsafe_pin_internals)]
struct Foo(std::marker::PhantomPinned);
fn main() {
let mut value = Foo(std::marker::PhantomPinned);
let indirect = &mut value;
// let pinned = pin!(*indirect);
let pinned = std::pin::Pin { __pointer: &mut (*indirect) };
// let pinned = std::pin::Pin { __pointer: &mut {*indirect} };
println!("{:p}", pinned.as_ref());
let moved = value;
println!("{:p}", &moved);
} |
Hm, yea I understand now. Crud, I'm not sure how to resolve that. |
manually keep the |
I *believe* this ought to be fixing rust-lang#138596
I *believe* this ought to be fixing rust-lang#138596
@ehuss' idea was on the right track, the semantics of braces are the one thing having changed; but @Nemo157's remark about parens themselves not forcing a value expression is indeed on point; this leaves us with the "typical" I've gone for the former in: UPDATE: using I have listed the necessary changes in the language-or-compiler for us to feature a proper solution or workaround |
@jdonszelmann made a temporary fix: #138717 This PR adds a If we land this now, we have some more time to think about how to express this properly in Rust 2024. |
…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 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
This is now fixed using a temporary solution that marks the expansion of pin!() as Rust 2021. The expressivity problem in Rust 2024 is tracked in #138718 |
Code
I tried this code:
I expected to see this happen: Compiles without error
Instead, this happened:
Version it worked on
It most recently worked on:
1.86.0-beta.6 (2025-03-16 8c7969a3ae4a292789a4)
Version with regression
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: