diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2025-07-20 22:33:04 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2025-07-20 22:45:07 +0000 |
| commit | 1987471d05854cc8b5014dab44e7648834c02213 (patch) | |
| tree | dce0f8c54332578b7878af90833726233b81ab4e | |
| parent | 82310651b93a594a3fd69015e1562186a080d94c (diff) | |
| download | rust-1987471d05854cc8b5014dab44e7648834c02213.tar.gz rust-1987471d05854cc8b5014dab44e7648834c02213.zip | |
Consider parent predicates in ImpossiblePredicates pass.
| -rw-r--r-- | compiler/rustc_mir_transform/src/impossible_predicates.rs | 26 | ||||
| -rw-r--r-- | tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr | 25 | ||||
| -rw-r--r-- | tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs | 1 | ||||
| -rw-r--r-- | tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.rs | 3 | ||||
| -rw-r--r-- | tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/layout/unknown-when-no-type-parameter.rs | 5 | ||||
| -rw-r--r-- | tests/ui/layout/unknown-when-no-type-parameter.stderr | 7 | ||||
| -rw-r--r-- | tests/ui/layout/unknown-when-ptr-metadata-is-DST.rs | 3 | ||||
| -rw-r--r-- | tests/ui/layout/unknown-when-ptr-metadata-is-DST.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/trivial-bounds/everybody-copies.rs (renamed from tests/crashes/131507.rs) | 7 | ||||
| -rw-r--r-- | tests/ui/trivial-bounds/two-sized-strs.rs (renamed from tests/crashes/121363.rs) | 4 |
11 files changed, 58 insertions, 35 deletions
diff --git a/compiler/rustc_mir_transform/src/impossible_predicates.rs b/compiler/rustc_mir_transform/src/impossible_predicates.rs index 86e2bf6cb3c..5f116d7716d 100644 --- a/compiler/rustc_mir_transform/src/impossible_predicates.rs +++ b/compiler/rustc_mir_transform/src/impossible_predicates.rs @@ -27,7 +27,7 @@ //! it's usually never invoked in this way. use rustc_middle::mir::{Body, START_BLOCK, TerminatorKind}; -use rustc_middle::ty::{TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{TyCtxt, TypeFlags, TypeVisitableExt}; use rustc_trait_selection::traits; use tracing::trace; @@ -36,14 +36,26 @@ use crate::pass_manager::MirPass; pub(crate) struct ImpossiblePredicates; impl<'tcx> MirPass<'tcx> for ImpossiblePredicates { + #[tracing::instrument(level = "trace", skip(self, tcx, body))] fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let predicates = tcx - .predicates_of(body.source.def_id()) + tracing::trace!(def_id = ?body.source.def_id()); + let predicates = tcx.predicates_of(body.source.def_id()).instantiate_identity(tcx); + tracing::trace!(?predicates); + let predicates = predicates .predicates - .iter() - .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); - if traits::impossible_predicates(tcx, traits::elaborate(tcx, predicates).collect()) { - trace!("found unsatisfiable predicates for {:?}", body.source); + .into_iter() + .filter(|p| { + !p.has_type_flags( + // Only consider global clauses to simplify. + TypeFlags::HAS_FREE_LOCAL_NAMES + // Clauses that refer to unevaluated constants as they cause cycles. + | TypeFlags::HAS_CT_PROJECTION, + ) + }) + .collect(); + tracing::trace!(?predicates); + if traits::impossible_predicates(tcx, predicates) { + trace!("found unsatisfiable predicates"); // Clear the body to only contain a single `unreachable` statement. let bbs = body.basic_blocks.as_mut(); bbs.raw.truncate(1); diff --git a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr index fa12dd14753..364fecb96ea 100644 --- a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr +++ b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr @@ -10,8 +10,14 @@ note: required by a bound in `ct_unused_0::AliasConstUnused` LL | type AliasConstUnused<T: Copy> = (T, I32<{ DATA }>); | ^^^^ required by this bound in `AliasConstUnused` +error[E0080]: entering unreachable code + --> $DIR/type-alias-bounds.rs:29:52 + | +LL | type AliasConstUnused where String: Copy = I32<{ 0; 0 }>; + | ^^^^^^^^ evaluation of `ct_unused_1::AliasConstUnused::{constant#0}` failed here + error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:31:12 + --> $DIR/type-alias-bounds.rs:32:12 | LL | let _: AliasConstUnused; | ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` @@ -23,41 +29,42 @@ LL | type AliasConstUnused where String: Copy = I32<{ 0; 0 }>; | ^^^^ required by this bound in `AliasConstUnused` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:39:12 + --> $DIR/type-alias-bounds.rs:40:12 | LL | let _: AliasFnUnused<String>; | ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `AliasFnUnused` - --> $DIR/type-alias-bounds.rs:36:27 + --> $DIR/type-alias-bounds.rs:37:27 | LL | type AliasFnUnused<T: Copy> = (T, I32<{ code() }>); | ^^^^ required by this bound in `AliasFnUnused` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:57:12 + --> $DIR/type-alias-bounds.rs:58:12 | LL | let _: AliasAssocConstUsed<String>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `AliasAssocConstUsed` - --> $DIR/type-alias-bounds.rs:55:41 + --> $DIR/type-alias-bounds.rs:56:41 | LL | type AliasAssocConstUsed<T: Trait + Copy> = I32<{ T::DATA }>; | ^^^^ required by this bound in `AliasAssocConstUsed` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:65:12 + --> $DIR/type-alias-bounds.rs:66:12 | LL | let _: AliasFnUsed<String>; | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | note: required by a bound in `AliasFnUsed` - --> $DIR/type-alias-bounds.rs:62:33 + --> $DIR/type-alias-bounds.rs:63:33 | LL | type AliasFnUsed<T: Trait + Copy> = I32<{ code::<T>() }>; | ^^^^ required by this bound in `AliasFnUsed` -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0080, E0277. +For more information about an error, try `rustc --explain E0080`. diff --git a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs index f16e646129c..775b28f8c73 100644 --- a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs +++ b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.rs @@ -27,6 +27,7 @@ fn ct_unused_0() { fn ct_unused_1() { #[allow(trivial_bounds)] type AliasConstUnused where String: Copy = I32<{ 0; 0 }>; + //[neg]~^ ERROR entering unreachable code #[cfg(neg)] let _: AliasConstUnused; //[neg]~^ ERROR the trait bound `String: Copy` is not satisfied diff --git a/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.rs b/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.rs index 4423b83e24d..8015a2fe081 100644 --- a/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.rs +++ b/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.rs @@ -5,7 +5,8 @@ where str: Sized, { [(); { let _a: Option<str> = None; 0 }]; - //~^ ERROR the type `Option<str>` has an unknown layout + //~^ ERROR entering unreachable code + //~| NOTE evaluation of `return_str::{constant#0}` failed here } fn main() {} diff --git a/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.stderr b/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.stderr index 43fe9e3a7a7..cad73b603c1 100644 --- a/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.stderr +++ b/tests/ui/layout/uncomputable-due-to-trivial-bounds-ice-135138.stderr @@ -1,8 +1,8 @@ -error[E0080]: the type `Option<str>` has an unknown layout - --> $DIR/uncomputable-due-to-trivial-bounds-ice-135138.rs:7:16 +error[E0080]: entering unreachable code + --> $DIR/uncomputable-due-to-trivial-bounds-ice-135138.rs:7:10 | LL | [(); { let _a: Option<str> = None; 0 }]; - | ^^ evaluation of `return_str::{constant#0}` failed here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `return_str::{constant#0}` failed here error: aborting due to 1 previous error diff --git a/tests/ui/layout/unknown-when-no-type-parameter.rs b/tests/ui/layout/unknown-when-no-type-parameter.rs index f787998868d..8579593c65c 100644 --- a/tests/ui/layout/unknown-when-no-type-parameter.rs +++ b/tests/ui/layout/unknown-when-no-type-parameter.rs @@ -9,9 +9,8 @@ where (): Project, { [(); size_of::<<() as Project>::Assoc>()]; - //~^ ERROR the type `<() as Project>::Assoc` has an unknown layout - //~| NOTE inside `std::mem::size_of::<<() as Project>::Assoc>` - //~| NOTE failed inside this call + //~^ ERROR entering unreachable code + //~| NOTE evaluation of `foo::{constant#0}` failed here } fn main() {} diff --git a/tests/ui/layout/unknown-when-no-type-parameter.stderr b/tests/ui/layout/unknown-when-no-type-parameter.stderr index 9bb42c46ec3..7c382c7a855 100644 --- a/tests/ui/layout/unknown-when-no-type-parameter.stderr +++ b/tests/ui/layout/unknown-when-no-type-parameter.stderr @@ -1,11 +1,8 @@ -error[E0080]: the type `<() as Project>::Assoc` has an unknown layout +error[E0080]: entering unreachable code --> $DIR/unknown-when-no-type-parameter.rs:11:10 | LL | [(); size_of::<<() as Project>::Assoc>()]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `foo::{constant#0}` failed inside this call - | -note: inside `std::mem::size_of::<<() as Project>::Assoc>` - --> $SRC_DIR/core/src/mem/mod.rs:LL:COL + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `foo::{constant#0}` failed here error: aborting due to 1 previous error diff --git a/tests/ui/layout/unknown-when-ptr-metadata-is-DST.rs b/tests/ui/layout/unknown-when-ptr-metadata-is-DST.rs index 54f339711d5..da11804c226 100644 --- a/tests/ui/layout/unknown-when-ptr-metadata-is-DST.rs +++ b/tests/ui/layout/unknown-when-ptr-metadata-is-DST.rs @@ -6,7 +6,8 @@ where str: std::ptr::Pointee<Metadata = str>, { [(); { let _a: Option<&str> = None; 0 }]; - //~^ ERROR the type `str` has an unknown layout + //~^ ERROR entering unreachable code + //~| NOTE evaluation of `return_str::{constant#0}` failed here } fn main() {} diff --git a/tests/ui/layout/unknown-when-ptr-metadata-is-DST.stderr b/tests/ui/layout/unknown-when-ptr-metadata-is-DST.stderr index fd9eedc9267..888e2574119 100644 --- a/tests/ui/layout/unknown-when-ptr-metadata-is-DST.stderr +++ b/tests/ui/layout/unknown-when-ptr-metadata-is-DST.stderr @@ -1,8 +1,8 @@ -error[E0080]: the type `str` has an unknown layout - --> $DIR/unknown-when-ptr-metadata-is-DST.rs:8:16 +error[E0080]: entering unreachable code + --> $DIR/unknown-when-ptr-metadata-is-DST.rs:8:10 | LL | [(); { let _a: Option<&str> = None; 0 }]; - | ^^ evaluation of `return_str::{constant#0}` failed here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `return_str::{constant#0}` failed here error: aborting due to 1 previous error diff --git a/tests/crashes/131507.rs b/tests/ui/trivial-bounds/everybody-copies.rs index 05b5e76bed7..3469fa1f1da 100644 --- a/tests/crashes/131507.rs +++ b/tests/ui/trivial-bounds/everybody-copies.rs @@ -1,5 +1,8 @@ -//@ known-bug: #131507 -//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+Inline -Zvalidate-mir +//! Regression test for #131507 +//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+Inline -Zvalidate-mir --crate-type lib +//@ build-pass + +#![expect(incomplete_features)] #![feature(non_lifetime_binders)] fn brick() diff --git a/tests/crashes/121363.rs b/tests/ui/trivial-bounds/two-sized-strs.rs index 38796342284..5cb82eac417 100644 --- a/tests/crashes/121363.rs +++ b/tests/ui/trivial-bounds/two-sized-strs.rs @@ -1,7 +1,9 @@ -//@ known-bug: #121363 +//! Regression test for #121363 //@ compile-flags: -Zmir-enable-passes=+GVN --crate-type lib +//@ build-pass #![feature(trivial_bounds)] +#![expect(trivial_bounds)] #[derive(Debug)] struct TwoStrs(str, str) |
