forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
PhantomData
marker for dropck to BTreeMap
closes rust-lang#99408
- Loading branch information
Showing
5 changed files
with
76 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
struct PrintOnDrop<'a>(&'a str); | ||
|
||
impl Drop for PrintOnDrop<'_> { | ||
fn drop(&mut self) { | ||
println!("printint: {}", self.0); | ||
} | ||
} | ||
|
||
use std::collections::BTreeMap; | ||
use std::iter::FromIterator; | ||
|
||
fn main() { | ||
let s = String::from("Hello World!"); | ||
let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]); | ||
drop(s); //~ ERROR cannot move out of `s` because it is borrowed | ||
} |
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,13 @@ | ||
error[E0505]: cannot move out of `s` because it is borrowed | ||
--> $DIR/btreemap_dropck.rs:15:10 | ||
| | ||
LL | let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]); | ||
| -- borrow of `s` occurs here | ||
LL | drop(s); | ||
| ^ move out of `s` occurs here | ||
LL | } | ||
| - borrow might be used here, when `_map` is dropped and runs the `Drop` code for type `BTreeMap` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0505`. |
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