mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-16 05:56:56 +00:00
don't drop types with no drop glue when tailcalling
this is required as otherwise drops of `&mut` refs count as a usage of a 'two-phase temporary' causing an ICE.
This commit is contained in:
parent
99768c80a1
commit
af2ce8b702
@ -785,6 +785,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let local =
|
||||
place.as_local().unwrap_or_else(|| bug!("projection in tail call args"));
|
||||
|
||||
if !self.local_decls[local].ty.needs_drop(self.tcx, self.typing_env()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(DropData { source_info, local, kind: DropKind::Value })
|
||||
}
|
||||
Operand::Constant(_) => None,
|
||||
@ -795,6 +799,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
self.scopes.scopes.iter().rev().nth(1).unwrap().region_scope,
|
||||
DUMMY_SP,
|
||||
);
|
||||
let typing_env = self.typing_env();
|
||||
let unwind_drops = &mut self.scopes.unwind_drops;
|
||||
|
||||
// the innermost scope contains only the destructors for the tail call arguments
|
||||
@ -805,6 +810,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let source_info = drop_data.source_info;
|
||||
let local = drop_data.local;
|
||||
|
||||
if !self.local_decls[local].ty.needs_drop(self.tcx, typing_env) {
|
||||
continue;
|
||||
}
|
||||
|
||||
match drop_data.kind {
|
||||
DropKind::Value => {
|
||||
// `unwind_to` should drop the value that we're about to
|
||||
|
@ -66,7 +66,6 @@
|
||||
bb6: {
|
||||
+ _8 = const false;
|
||||
StorageDead(_4);
|
||||
StorageDead(_3);
|
||||
drop(_2) -> [return: bb7, unwind: bb12];
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,6 @@
|
||||
bb6: {
|
||||
+ _8 = const false;
|
||||
StorageDead(_4);
|
||||
StorageDead(_3);
|
||||
- drop(_2) -> [return: bb7, unwind continue];
|
||||
+ drop(_2) -> [return: bb7, unwind: bb12];
|
||||
}
|
||||
|
@ -63,7 +63,6 @@ fn f() -> () {
|
||||
|
||||
bb6: {
|
||||
StorageDead(_4);
|
||||
StorageDead(_3);
|
||||
drop(_2) -> [return: bb7, unwind: bb17];
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,6 @@ fn f() -> () {
|
||||
|
||||
bb6: {
|
||||
StorageDead(_4);
|
||||
StorageDead(_3);
|
||||
drop(_2) -> [return: bb7, unwind: bb17];
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,6 @@
|
||||
bb8: {
|
||||
+ _12 = const false;
|
||||
StorageDead(_6);
|
||||
StorageDead(_5);
|
||||
drop(_4) -> [return: bb9, unwind: bb16];
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,6 @@
|
||||
bb8: {
|
||||
+ _12 = const false;
|
||||
StorageDead(_6);
|
||||
StorageDead(_5);
|
||||
drop(_4) -> [return: bb9, unwind: bb16];
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,6 @@ fn f_with_arg(_1: String, _2: String) -> () {
|
||||
|
||||
bb8: {
|
||||
StorageDead(_6);
|
||||
StorageDead(_5);
|
||||
drop(_4) -> [return: bb9, unwind: bb23];
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,6 @@ fn f_with_arg(_1: String, _2: String) -> () {
|
||||
|
||||
bb8: {
|
||||
StorageDead(_6);
|
||||
StorageDead(_5);
|
||||
drop(_4) -> [return: bb9, unwind: bb23];
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,9 @@ error[E0597]: `local` does not live long enough
|
||||
LL | let local = Type;
|
||||
| ----- binding `local` declared here
|
||||
LL | become takes_borrow(&local);
|
||||
| ^^^^^^ borrowed value does not live long enough
|
||||
LL |
|
||||
LL | }
|
||||
| - `local` dropped here while still borrowed
|
||||
| ^^^^^^- `local` dropped here while still borrowed
|
||||
| |
|
||||
| borrowed value does not live long enough
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user