Also bail out if predicates contain errors.

This commit is contained in:
Camille GILLOT 2025-07-20 23:12:44 +00:00
parent 1987471d05
commit 538b0004bc
5 changed files with 41 additions and 17 deletions

View File

@ -41,7 +41,7 @@ impl<'tcx> MirPass<'tcx> for ImpossiblePredicates {
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
let predicates: Vec<_> = predicates
.predicates
.into_iter()
.filter(|p| {
@ -54,7 +54,7 @@ impl<'tcx> MirPass<'tcx> for ImpossiblePredicates {
})
.collect();
tracing::trace!(?predicates);
if traits::impossible_predicates(tcx, predicates) {
if predicates.references_error() || 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();

View File

@ -1,7 +0,0 @@
//@ known-bug: #140100
fn a()
where
b: Sized,
{
println!()
}

View File

@ -1,8 +0,0 @@
//@ known-bug: #140365
//@compile-flags: -C opt-level=1 -Zvalidate-mir
fn f() -> &'static str
where
Self: Sized,
{
""
}

View File

@ -0,0 +1,20 @@
//! Regression test for #140100 and #140365
//@compile-flags: -C opt-level=1 -Zvalidate-mir
fn a()
where
b: Sized,
//~^ ERROR cannot find type `b` in this scope
{
println!()
}
fn f() -> &'static str
where
Self: Sized,
//~^ ERROR cannot find type `Self` in this scope
{
""
}
fn main() {}

View File

@ -0,0 +1,19 @@
error[E0412]: cannot find type `b` in this scope
--> $DIR/meaningless-bound.rs:6:5
|
LL | b: Sized,
| ^ not found in this scope
error[E0411]: cannot find type `Self` in this scope
--> $DIR/meaningless-bound.rs:14:5
|
LL | fn f() -> &'static str
| - `Self` not allowed in a function
LL | where
LL | Self: Sized,
| ^^^^ `Self` is only available in impls, traits, and type definitions
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0411, E0412.
For more information about an error, try `rustc --explain E0411`.