-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Too lenient #[may_dangle]
on BTreeMap
; misses PhantomData
for dropck
#99408
Comments
This is actually also a (not too recent) regression (in
So maybe #64595 made a difference? @rustbot label regression-from-stable-to-stable |
This is what changed apparently, the following compiles successfully since #![feature(dropck_eyepatch)]
use std::mem::ManuallyDrop;
struct S<T>(ManuallyDrop<T>);
unsafe impl<#[may_dangle] T> Drop for S<T> {
fn drop(&mut self) {}
}
struct NonTrivialDrop<'a>(&'a str);
impl<'a> Drop for NonTrivialDrop<'a> {
fn drop(&mut self) {}
}
fn main() {
let s = String::from("string");
let _t = S(ManuallyDrop::new(NonTrivialDrop(&s)));
drop(s);
} I mean, yeah, this change was good IMO, so it is just the library that needs fixing, dropck itself seems fine. |
It's probably time we move https://forge.rust-lang.org/libs/maintaining-std.html#is-there-a-manual-drop-implementation to the std-dev-guide. |
Add `PhantomData` marker for dropck to `BTreeMap` closes rust-lang#99408
Add `PhantomData` marker for dropck to `BTreeMap` closes rust-lang#99408
Add `PhantomData` marker for dropck to `BTreeMap` closes rust-lang#99408
Add `PhantomData` marker for dropck to `BTreeMap` closes rust-lang#99408
Add `PhantomData` marker for dropck to `BTreeMap` closes rust-lang#99408
That PR sounds like it was meant to be an optimization, not changing behavior. There are no new tests. And yet it turns out that it did change behavior! Specifically, I think this is when dropck started exploiting that ManuallyDrop does not drop its fields. I will add a corresponding testcase to #103413. |
Yes, I seem to recall us fixing fallout from that PR a while back - it did indeed (unintentionally) change behavior, though I don't have in cache what went wrong with the changes. |
By "fixing" you mean bring back the original behavior? That does not seem to be entirely the case; as this issue shows, one change in behavior did remain in place. |
(playground)
@rustbot label T-libs, I-unsound
@rustbot claim
The text was updated successfully, but these errors were encountered: