Skip to content

Commit 0604cf5

Browse files
authored
Rollup merge of #92207 - tmiasko:delay-drop-elaboration-bug, r=jackh726
Delay remaining `span_bug`s in drop elaboration This follows changes from #67967 and converts remaining `span_bug`s into delayed bugs, since for const items drop elaboration might be executed on a MIR which failed borrowck. Fixes #81708. Fixes #91816.
2 parents cdc5c13 + 0db192a commit 0604cf5

File tree

3 files changed

+89
-8
lines changed

3 files changed

+89
-8
lines changed

compiler/rustc_mir_transform/src/elaborate_drops.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,12 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
316316
LookupResult::Parent(Some(parent)) => {
317317
let (_maybe_live, maybe_dead) = self.init_data.maybe_live_dead(parent);
318318
if maybe_dead {
319-
span_bug!(
319+
self.tcx.sess.delay_span_bug(
320320
terminator.source_info.span,
321-
"drop of untracked, uninitialized value {:?}, place {:?} ({:?})",
322-
bb,
323-
place,
324-
path
321+
&format!(
322+
"drop of untracked, uninitialized value {:?}, place {:?} ({:?})",
323+
bb, place, path,
324+
),
325325
);
326326
}
327327
continue;
@@ -368,10 +368,9 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
368368
bb,
369369
),
370370
LookupResult::Parent(..) => {
371-
span_bug!(
371+
self.tcx.sess.delay_span_bug(
372372
terminator.source_info.span,
373-
"drop of untracked value {:?}",
374-
bb
373+
&format!("drop of untracked value {:?}", bb),
375374
);
376375
}
377376
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Regression test for issue 81708 and issue 91816 where running a drop
2+
// elaboration on a MIR which failed borrowck lead to an ICE.
3+
4+
static A: () = {
5+
let a: [String; 1];
6+
//~^ ERROR destructors cannot be evaluated at compile-time
7+
a[0] = String::new();
8+
//~^ ERROR destructors cannot be evaluated at compile-time
9+
//~| ERROR use of possibly-uninitialized variable
10+
};
11+
12+
struct B<T>([T; 1]);
13+
14+
impl<T> B<T> {
15+
pub const fn f(mut self, other: T) -> Self {
16+
let _this = self;
17+
//~^ ERROR destructors cannot be evaluated at compile-time
18+
self.0[0] = other;
19+
//~^ ERROR destructors cannot be evaluated at compile-time
20+
//~| ERROR use of moved value
21+
self
22+
}
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
error[E0493]: destructors cannot be evaluated at compile-time
2+
--> $DIR/drop-elaboration-after-borrowck-error.rs:7:5
3+
|
4+
LL | a[0] = String::new();
5+
| ^^^^
6+
| |
7+
| statics cannot evaluate destructors
8+
| value is dropped here
9+
10+
error[E0493]: destructors cannot be evaluated at compile-time
11+
--> $DIR/drop-elaboration-after-borrowck-error.rs:5:9
12+
|
13+
LL | let a: [String; 1];
14+
| ^ statics cannot evaluate destructors
15+
...
16+
LL | };
17+
| - value is dropped here
18+
19+
error[E0381]: use of possibly-uninitialized variable: `a`
20+
--> $DIR/drop-elaboration-after-borrowck-error.rs:7:5
21+
|
22+
LL | a[0] = String::new();
23+
| ^^^^ use of possibly-uninitialized `a`
24+
25+
error[E0493]: destructors cannot be evaluated at compile-time
26+
--> $DIR/drop-elaboration-after-borrowck-error.rs:18:9
27+
|
28+
LL | self.0[0] = other;
29+
| ^^^^^^^^^
30+
| |
31+
| constant functions cannot evaluate destructors
32+
| value is dropped here
33+
34+
error[E0493]: destructors cannot be evaluated at compile-time
35+
--> $DIR/drop-elaboration-after-borrowck-error.rs:16:13
36+
|
37+
LL | let _this = self;
38+
| ^^^^^ constant functions cannot evaluate destructors
39+
...
40+
LL | }
41+
| - value is dropped here
42+
43+
error[E0382]: use of moved value: `self.0`
44+
--> $DIR/drop-elaboration-after-borrowck-error.rs:18:9
45+
|
46+
LL | pub const fn f(mut self, other: T) -> Self {
47+
| -------- move occurs because `self` has type `B<T>`, which does not implement the `Copy` trait
48+
LL | let _this = self;
49+
| ---- value moved here
50+
LL |
51+
LL | self.0[0] = other;
52+
| ^^^^^^^^^ value used here after move
53+
54+
error: aborting due to 6 previous errors
55+
56+
Some errors have detailed explanations: E0381, E0382, E0493.
57+
For more information about an error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)