-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Parse pin
ned local variable declarations
#135631
base: master
Are you sure you want to change the base?
Conversation
r? @Noratrieb rustbot has assigned @Noratrieb. Use |
Some changes occurred in match checking cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
The tracking issue only mentions constructors and reborrowing, and not pinned locals, so I don't think this should be added. |
Compared to Similarly, For example: struct Foo;
impl Foo {
fn by_pin_const(&pin const self) {}
fn by_pin_mut(&pin mut self) {}
fn by_ref(&self) {}
fn by_mut(&mut self) {}
fn by_value(self) {}
}
fn bar() {
let pin mut foo = Foo; // define a pinned mutable local (cannot be moved but can be mutated)
foo.by_pin(); // ok
foo.by_pin_mut(); // ok
foo.by_ref(); // ok because `Pin<Foo>` impls Deref<Target = Foo>
foo.by_mut(); //~ ERROR cannot borrow `foo` mutably because it is pinned
foo.by_value(); //~ ERROR cannot move `foo` because it is pinned
foo = Foo; //~ ERROR cannot assign to `foo` because the previous value it bound has be pinned
let pin const foo = Foo; // define a pinned immutable local (cannot be moved nor mutated)
foo.by_pin(); // ok
foo.by_pin_mut(); // ERROR cannot borrow `foo` mutably because it is immutably pinned
foo.by_ref(); // ok because `Pin<Foo>` impls Deref<Target = Foo>
foo.by_mut(); //~ ERROR cannot borrow `foo` mutably because it is immutably pinned
foo.by_value(); //~ ERROR cannot move `foo` because it is pinned
foo = Foo; //~ ERROR cannot assign to `foo` because the `foo` is immuable
} |
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.
This feature needs to be gated properly so that we reject this in #[cfg]
'd out code.
e311c1e
to
87de2da
Compare
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
87de2da
to
9d32ffd
Compare
☔ The latest upstream changes (presumably #135755) made this pull request unmergeable. Please resolve the merge conflicts. |
9d32ffd
to
cdf8fcf
Compare
Quite excited for this after reading Pinned Places and working through the churn/pain of removing |
cdf8fcf
to
8890fdb
Compare
cc @eholk |
Sorry for the delay, I lost track of this. This is not an item on the list of #130494. Is this still something that the lang team is interested in pursuing? @traviscross @eholk |
There's a good chance that, in the context of the pin ergonomics experiment, we'll want something like this. It seems like we'll either have it be explicit, like in this PR, or the compiler will implicitly track whether a place has been pinned. Given that the goal of the pin ergonomics experiment is to explore the space here and get some experience with it, I think it's reasonable to pursue the idea of pinned places. |
It's fine to include this in the scope of the experiment. My only concern would be ensuring that someone is planning to follow-up shortly to make these actually work as intended. |
This comment has been minimized.
This comment has been minimized.
6187c56
to
3f81506
Compare
☔ The latest upstream changes (presumably #137235) made this pull request unmergeable. Please resolve the merge conflicts. |
3f81506
to
e7b4497
Compare
☔ The latest upstream changes (presumably #137295) made this pull request unmergeable. Please resolve the merge conflicts. |
r? compiler-errors |
e7b4497
to
7003222
Compare
☔ The latest upstream changes (presumably #135726) made this pull request unmergeable. Please resolve the merge conflicts. |
This PR implements part of #130494, parsing
let pin mut x
orlet pin const x
in local variables that cannot be moved.