Implement borrowck for &pin mut|const $place#153693
Implement borrowck for &pin mut|const $place#153693frank-king wants to merge 8 commits intorust-lang:mainfrom
&pin mut|const $place#153693Conversation
This comment has been minimized.
This comment has been minimized.
f6b714b to
46c66aa
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
63fbcd8 to
122d1be
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
|
Let me self-review the whole PR carefully before marking it ready for review. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a72c987 to
9fe2f02
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@frank-king How is your review going? |
| } | ||
|
|
||
| fn direct_pin_mut_not_unpin() { | ||
| let _ = &pin mut NotUnpin { _pin: PhantomPinned }; |
There was a problem hiding this comment.
This is probably wrong. Generally, let x = &pin mut y; should be equivalent to let ref mut x = y;. Given that (Playground)
struct NoPinV2 {
x: i32,
}
struct NoPinV2NoUnpin {
x: i32,
__: std::marker::PhantomPinned,
}
struct NoPinV2Generic<T> {
y: T,
}
struct NoPinV2GenericUnpin<T> {
y: T,
__: std::marker::PhantomPinned,
}
impl<T> Unpin for NoPinV2GenericUnpin<T> {}
fn foo<T>(
mut x: NoPinV2,
mut y: NoPinV2NoUnpin,
mut z: NoPinV2Generic<T>,
mut w: NoPinV2GenericUnpin<T>,
) {
let ref pin mut x = x; // ok
let ref pin mut y = y; // ok
let ref pin mut z = z; // ok
let ref pin mut w = w; // ok
// However, only the first is accepted
let x = &pin mut x; // ok
let y = &pin mut y; // ERROR
let z = &pin mut z; // ERROR
let w = &pin mut w; // ERROR
}Regarding pin patterns, the #[pin_v2] checks actually happen when field projections take place, rather than when pinned borrows (via the ref pin patterns) do.
I'm afraid that we should check #[pin_v2] at field projections (including nested field projections like &pin mut foo.a[2].0) too. I guess this can be processed when walking at the expr adjuestments (but highly unsure)
1e8d2cd to
5764e08
Compare
|
Some changes occurred in match lowering cc @Nadrieril Some changes occurred to constck cc @fee1-dead Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to the CTFE machinery |
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
I'm going to mark this PR ready since there isn't a simple and clear solution to the unresolved questions yet. Help wanted from reviewers. |
Remove the now-unnecessary helper method and access state.pinned_borrows directly.
5764e08 to
03d1f29
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
Part of Pin Ergonomics.
This forbids places to be moved or mutably borrowed ever since they are pinned until they are reassigned (even after the pinned borrows themselves expire).
Tasks:
Pinsdataflow analysispinpattern matching&pinborrows for ADTs without#[pin_v2](for soundness concerns)Unresolved questions
When should
#[pin_v2]be checked?Currently, it is checked at
rustc_hir_typck::FnCtxt::check_expr_addr_of, but field projections are not correctly handled.Should we check this after the expr adjustments are available or even at THIR?
Related discussions:
How to deal with
Unpintypes?Should
&pinborrowed places ofUnpintypes be prevented from being moved, or just don't treatUnpintypes specially and emit move-after-pin as usual?