Skip to content

Commit

Permalink
Do not ICE on field access check on expr with ty::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Apr 5, 2024
1 parent 76cf07d commit c524f11
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
self.insert_def_id(def.non_enum_variant().fields[index].did);
}
ty::Tuple(..) => {}
_ => span_bug!(lhs.span, "named field access on non-ADT"),
ty::Error(_) => {}
kind => span_bug!(lhs.span, "named field access on non-ADT: {kind:?}"),
}
}

Expand Down
27 changes: 27 additions & 0 deletions tests/ui/consts/do-not-ice-on-field-access-of-err-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::mem;

trait Foo {
fn foo(&self) -> usize;
}
impl<T> Foo for T {
fn foo(&self) -> usize {
mem::size_of::<T>()
}
}

fn main_ref() {
let array = [(); {
let mut n = 0;
while n < 5 {} //~ ERROR constant evaluation is taking a long time
0
}];

let u8_ = (7, 1u8);
let u32_ = (4u32, 5u32);

let buf: &mut [*const dyn Foo] = &mut [&u8_, &u8_.0, &u32_, &u32_.0];
}

fn main() {
main_ref();
}
22 changes: 22 additions & 0 deletions tests/ui/consts/do-not-ice-on-field-access-of-err-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: constant evaluation is taking a long time
--> $DIR/do-not-ice-on-field-access-of-err-type.rs:15:9
|
LL | while n < 5 {}
| ^^^^^^^^^^^^^^
|
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
--> $DIR/do-not-ice-on-field-access-of-err-type.rs:13:22
|
LL | let array = [(); {
| ______________________^
LL | | let mut n = 0;
LL | | while n < 5 {}
LL | | 0
LL | | }];
| |_____^
= note: `#[deny(long_running_const_eval)]` on by default

error: aborting due to 1 previous error

0 comments on commit c524f11

Please sign in to comment.