Rollup merge of #99413 - steffahn:btree_dropck, r=m-ou-se
Add `PhantomData` marker for dropck to `BTreeMap` closes #99408
This commit is contained in:
commit
43783b80ee
5 changed files with 76 additions and 7 deletions
16
src/test/ui/btreemap/btreemap_dropck.rs
Normal file
16
src/test/ui/btreemap/btreemap_dropck.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
13
src/test/ui/btreemap/btreemap_dropck.stderr
Normal file
13
src/test/ui/btreemap/btreemap_dropck.stderr
Normal file
|
|
@ -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`.
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
#[derive(Hash)]
|
||||
pub enum ElemDerived { //~ ERROR recursive type `ElemDerived` has infinite size
|
||||
pub enum ElemDerived {
|
||||
//~^ ERROR recursive type `ElemDerived` has infinite size
|
||||
//~| ERROR cycle detected when computing drop-check constraints for `ElemDerived`
|
||||
A(ElemDerived)
|
||||
}
|
||||
|
||||
|
||||
pub enum Elem {
|
||||
Derived(ElemDerived)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ error[E0072]: recursive type `ElemDerived` has infinite size
|
|||
|
|
||||
LL | pub enum ElemDerived {
|
||||
| ^^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
|
||||
...
|
||||
LL | A(ElemDerived)
|
||||
| ----------- recursive without indirection
|
||||
|
|
||||
|
|
@ -11,6 +12,20 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ElemDerived
|
|||
LL | A(Box<ElemDerived>)
|
||||
| ++++ +
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0391]: cycle detected when computing drop-check constraints for `ElemDerived`
|
||||
--> $DIR/issue-72554.rs:4:1
|
||||
|
|
||||
LL | pub enum ElemDerived {
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: ...which immediately requires computing drop-check constraints for `ElemDerived` again
|
||||
note: cycle used when computing drop-check constraints for `Elem`
|
||||
--> $DIR/issue-72554.rs:11:1
|
||||
|
|
||||
LL | pub enum Elem {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
For more information about this error, try `rustc --explain E0072`.
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0072, E0391.
|
||||
For more information about an error, try `rustc --explain E0072`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue