From ec05c7f6a07b09511dab3c51b1b88b37444a5efd Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 19 Jul 2026 17:20:13 +0200 Subject: [PATCH] fix ICE is opsem inhabitedness check --- .../rustc_middle/src/ty/inhabitedness/mod.rs | 8 ++++++-- .../pointee-type-with-error-issue-159560.rs | 10 ++++++++++ .../pointee-type-with-error-issue-159560.stderr | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.rs create mode 100644 tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 1d4c55aa34690..8e5316bab8fbb 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -339,8 +339,12 @@ fn is_opsem_inhabited_recursor<'tcx, SEEN>( }) } - ty::Error(_) - | ty::Infer(..) + ty::Error(_error_guaranteed) => { + // We have a token proving there was an error, so we can return a dummy value. + true + } + + ty::Infer(..) | ty::Placeholder(..) | ty::Bound(..) | ty::Param(..) diff --git a/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.rs b/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.rs new file mode 100644 index 0000000000000..52a3b1ee2f0c1 --- /dev/null +++ b/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.rs @@ -0,0 +1,10 @@ +//@ compile-flags: -Zextra-const-ub-checks + +struct A { + f: _, //~ERROR: not allowed +} + +// FIXME: the error message makes no sense +static B: &A = B; //~ERROR: access itself + +fn main() {} diff --git a/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr b/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr new file mode 100644 index 0000000000000..bd738ad505705 --- /dev/null +++ b/tests/ui/consts/extra-const-ub/pointee-type-with-error-issue-159560.stderr @@ -0,0 +1,16 @@ +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/pointee-type-with-error-issue-159560.rs:4:8 + | +LL | f: _, + | ^ not allowed in type signatures + +error[E0080]: encountered static that tried to access itself during initialization + --> $DIR/pointee-type-with-error-issue-159560.rs:8:16 + | +LL | static B: &A = B; + | ^ evaluation of `B` failed here + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0080, E0121. +For more information about an error, try `rustc --explain E0080`.