-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Undocumented soundness fix between 1.34 and 1.35 #76147
Comments
Going over the git log doesn't show anything like an associated type soundness fix. We should at the very least make sure this is covered by a test.^^ @rustbot ping cleanup-crew |
This comment has been minimized.
This comment has been minimized.
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke |
minimized pub fn union(v: &mut Vec<String>, x: usize, y: usize) {
unsafe {
let x: *mut &mut String = &mut v.get_unchecked_mut(x);
let y: *mut &mut String = &mut v.get_unchecked_mut(y);
debug_assert_ne!(x, y);
}
} |
@lcnr that minimized version also fails to compile with Rust 1.34, though? So it doesn't represent the regression. EDIT: never mind, I forgot to pass |
you need pub fn union<'a>(v: &'a mut Vec<String>, x: usize, y: usize) {
unsafe {
let x: *mut &'a mut String = &mut v.get_unchecked_mut(x);
let y: &'a mut String = v.get_unchecked_mut(y);
debug_assert_ne!(*x, y);
}
} |
This does compile though, even in on the current nightly, so I am not quite sure what's the intended behavior here: pub fn union<'a>(mut v: &'a mut String) {
unsafe {
let x: *mut &'a mut String = &mut v;
let y: &'a mut String = v;
debug_assert_ne!(*x, y);
}
} |
As a completely self contained example: fn ok<'a>(v: &'a mut ()) -> &'a mut () {
v
}
pub fn union<'a>(v: &'a mut ()) {
let x: *mut &'a mut () = &mut ok(v);
let _ = (x, v);
} |
That one should compile. The |
I don't yet see the difference between |
I think this is #58673 |
That said, I thought that |
I compiled a rather old project of mine for the first time in quite a while and was surprised that it no longer compiled on stable, which it did way back in 1.34.
Non-minimized regression demo: https://rust.godbolt.org/z/f9n6h8
The core of the problem is this bit of code:
It turns out that it was always wrong -- I meant to get a
*mut Entry
, not a*mut &mut Entry
-- so I think this is probably an allowed breaking change?But it's not documented in the release notes for 1.35, which surprised me.
It's not obvious to me exactly what got fixed here. Is a temporary lifetime different, or is borrowck just detecting something it didn't used to? (Both examples are on edition 2018, so I think MIR borrowck?)
The text was updated successfully, but these errors were encountered: