-
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
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
This PR implements part of #130494, parsing
let pin mut x
orlet pin const x
in local variables that cannot be moved.