-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #103413 - RalfJung:phantom-dropck, r=lcnr
PhantomData: fix documentation wrt interaction with dropck As far as I could find out, the `PhantomData`-dropck interaction *only* affects code using `may_dangle`. The documentation in the standard library has not been updated for 8 years and thus stems from a time when Rust still used "parametric dropck", before [RFC 1238](https://rust-lang.github.io/rfcs/1238-nonparametric-dropck.html). Back then what the docs said was correct, but with `may_dangle` dropck it stopped being entirely accurate and these days, with NLL, it is actively misleading. Fixes #102810 Fixes #70841 Cc `@nikomatsakis` I hope what I am saying here is right.^^
- Loading branch information
Showing
3 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// check-pass | ||
//! This test checks that dropck knows that ManuallyDrop does not drop its field. | ||
#![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); | ||
} |