diff --git a/compiler/rustc_mir_transform/src/impossible_predicates.rs b/compiler/rustc_mir_transform/src/impossible_predicates.rs index 5f116d7716db..9a0de3c93263 100644 --- a/compiler/rustc_mir_transform/src/impossible_predicates.rs +++ b/compiler/rustc_mir_transform/src/impossible_predicates.rs @@ -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(); diff --git a/tests/crashes/140100.rs b/tests/crashes/140100.rs deleted file mode 100644 index 0836ffe2d92f..000000000000 --- a/tests/crashes/140100.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ known-bug: #140100 -fn a() -where - b: Sized, -{ - println!() -} diff --git a/tests/crashes/140365.rs b/tests/crashes/140365.rs deleted file mode 100644 index 809ceaf35a05..000000000000 --- a/tests/crashes/140365.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ known-bug: #140365 -//@compile-flags: -C opt-level=1 -Zvalidate-mir -fn f() -> &'static str -where - Self: Sized, -{ - "" -} diff --git a/tests/ui/mir/meaningless-bound.rs b/tests/ui/mir/meaningless-bound.rs new file mode 100644 index 000000000000..c9427e7ece51 --- /dev/null +++ b/tests/ui/mir/meaningless-bound.rs @@ -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() {} diff --git a/tests/ui/mir/meaningless-bound.stderr b/tests/ui/mir/meaningless-bound.stderr new file mode 100644 index 000000000000..dc08def83b66 --- /dev/null +++ b/tests/ui/mir/meaningless-bound.stderr @@ -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`.