Skip to content

Commit c524f11

Browse files
committed
Do not ICE on field access check on expr with ty::Error
Fix rust-lang#123428
1 parent 76cf07d commit c524f11

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

compiler/rustc_passes/src/dead.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
153153
self.insert_def_id(def.non_enum_variant().fields[index].did);
154154
}
155155
ty::Tuple(..) => {}
156-
_ => span_bug!(lhs.span, "named field access on non-ADT"),
156+
ty::Error(_) => {}
157+
kind => span_bug!(lhs.span, "named field access on non-ADT: {kind:?}"),
157158
}
158159
}
159160

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::mem;
2+
3+
trait Foo {
4+
fn foo(&self) -> usize;
5+
}
6+
impl<T> Foo for T {
7+
fn foo(&self) -> usize {
8+
mem::size_of::<T>()
9+
}
10+
}
11+
12+
fn main_ref() {
13+
let array = [(); {
14+
let mut n = 0;
15+
while n < 5 {} //~ ERROR constant evaluation is taking a long time
16+
0
17+
}];
18+
19+
let u8_ = (7, 1u8);
20+
let u32_ = (4u32, 5u32);
21+
22+
let buf: &mut [*const dyn Foo] = &mut [&u8_, &u8_.0, &u32_, &u32_.0];
23+
}
24+
25+
fn main() {
26+
main_ref();
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/do-not-ice-on-field-access-of-err-type.rs:15:9
3+
|
4+
LL | while n < 5 {}
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
8+
If your compilation actually takes a long time, you can safely allow the lint.
9+
help: the constant being evaluated
10+
--> $DIR/do-not-ice-on-field-access-of-err-type.rs:13:22
11+
|
12+
LL | let array = [(); {
13+
| ______________________^
14+
LL | | let mut n = 0;
15+
LL | | while n < 5 {}
16+
LL | | 0
17+
LL | | }];
18+
| |_____^
19+
= note: `#[deny(long_running_const_eval)]` on by default
20+
21+
error: aborting due to 1 previous error
22+

0 commit comments

Comments
 (0)