Conversation
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
I expect this needs crater, so: @bors try |
This comment has been minimized.
This comment has been minimized.
prevent deref coercions in `pin!`
092ecb8 to
8f93fc9
Compare
|
Just realized I could format things more cleanly (diff). This shouldn't affect the correctness of the try build. |
|
A more explicit approach could be to do something like: super let mut pinned = $value;
#[allow(unreachable_code)]
'p: {
fn unreachable_type_constraint<'a, T>(_: T) -> Pin<&'a mut T> {
unreachable!()
}
break 'p unsafe { Pin::new_unchecked(&mut pinned) };
unreachable_type_constraint(pinned)
} |
|
So that's how to add types to macros! Funky idiom, but I do prefer the explicitness of actually having types, yeah. I think that'd be less likely to break inference too if anything's started relying on it; iirc type expectations are propagated from the block to the break expression (via the block's coercion target type). But it's fine because we'll encounter an error instead of silently adding a coercion if things don't match up.. I think. Would you prefer to make your own PR @eggyal, or should I just work that into this one? I'm not a library reviewer so I can't say which would be preferable from that perspective, but from the perspective I do have, I think adding a type constraint is a better fix. |
|
By all means work it into this one. This idiom was originally suggested to me by lcnr some years ago, so I claim no credit for it! |
|
this change requires someone from libs team to be approved, so i'm reassigning r? libs |
8f93fc9 to
524b11d
Compare
|
Went ahead with the unreachable type constraint version of this (diff). There's unfortunately a bit of a diagnostics regression due to the extra type checking. I still think it's worth the lower likelihood of breakage, but it's a tradeoff. I'll be firing off a fresh try build, but if the diagnostics are a sticking point, maybe it'd be worth comparing crater results for both approaches? |
|
@bors try |
This comment has been minimized.
This comment has been minimized.
prevent deref coercions in `pin!`
|
I'll crater the type constraint approach first since that's my preferred quick fix at the moment. Also going to try re-running pr-check-2. It never restarted after being canceled it looks like? |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Fixes #153438 using a (hopefully temporary!) typed macro idiom to ensure that when
pin!produces aPin<&mut T>, its argument is of typeT. See #153438 (comment) for my ideas on how this could be changed in the future.