Skip to content

Commit 538b000

Browse files
committed
Also bail out if predicates contain errors.
1 parent 1987471 commit 538b000

File tree

5 files changed

+41
-17
lines changed

5 files changed

+41
-17
lines changed

compiler/rustc_mir_transform/src/impossible_predicates.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'tcx> MirPass<'tcx> for ImpossiblePredicates {
4141
tracing::trace!(def_id = ?body.source.def_id());
4242
let predicates = tcx.predicates_of(body.source.def_id()).instantiate_identity(tcx);
4343
tracing::trace!(?predicates);
44-
let predicates = predicates
44+
let predicates: Vec<_> = predicates
4545
.predicates
4646
.into_iter()
4747
.filter(|p| {
@@ -54,7 +54,7 @@ impl<'tcx> MirPass<'tcx> for ImpossiblePredicates {
5454
})
5555
.collect();
5656
tracing::trace!(?predicates);
57-
if traits::impossible_predicates(tcx, predicates) {
57+
if predicates.references_error() || traits::impossible_predicates(tcx, predicates) {
5858
trace!("found unsatisfiable predicates");
5959
// Clear the body to only contain a single `unreachable` statement.
6060
let bbs = body.basic_blocks.as_mut();

tests/crashes/140100.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/crashes/140365.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/ui/mir/meaningless-bound.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Regression test for #140100 and #140365
2+
//@compile-flags: -C opt-level=1 -Zvalidate-mir
3+
4+
fn a()
5+
where
6+
b: Sized,
7+
//~^ ERROR cannot find type `b` in this scope
8+
{
9+
println!()
10+
}
11+
12+
fn f() -> &'static str
13+
where
14+
Self: Sized,
15+
//~^ ERROR cannot find type `Self` in this scope
16+
{
17+
""
18+
}
19+
20+
fn main() {}

tests/ui/mir/meaningless-bound.stderr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0412]: cannot find type `b` in this scope
2+
--> $DIR/meaningless-bound.rs:6:5
3+
|
4+
LL | b: Sized,
5+
| ^ not found in this scope
6+
7+
error[E0411]: cannot find type `Self` in this scope
8+
--> $DIR/meaningless-bound.rs:14:5
9+
|
10+
LL | fn f() -> &'static str
11+
| - `Self` not allowed in a function
12+
LL | where
13+
LL | Self: Sized,
14+
| ^^^^ `Self` is only available in impls, traits, and type definitions
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0411, E0412.
19+
For more information about an error, try `rustc --explain E0411`.

0 commit comments

Comments
 (0)