Skip to content

Commit 01eec53

Browse files
Don't normalize projections referencing type error
1 parent eee6b31 commit 01eec53

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/rustc_trait_selection/src/solve/normalize.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
7070
// keep the projection unnormalized. This is the case for projections
7171
// with a `T: Trait` where-clause and opaque types outside of the defining
7272
// scope.
73-
let result = if infcx.predicate_may_hold(&obligation) {
73+
// HACK: if alias_ty references errors, then there's a possibility that the
74+
// normalized type may remain unconstrained. In that case, let's just bail.
75+
// See `dont-try-normalizing-proj-with-errors.rs` in the test suite.
76+
let result = if infcx.predicate_may_hold(&obligation) && !alias.references_error() {
7477
self.fulfill_cx.register_predicate_obligation(infcx, obligation);
7578
let errors = self.fulfill_cx.select_all_or_error(infcx);
7679
if !errors.is_empty() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -Ztrait-solver=next
2+
3+
trait Mirror {
4+
type Assoc: ?Sized;
5+
}
6+
7+
struct Wrapper<T: ?Sized>(T);
8+
impl<T: ?Sized> Mirror for Wrapper<T> {
9+
type Assoc = T;
10+
}
11+
12+
fn mirror<W: Mirror>(_: W) -> Box<W::Assoc> { todo!() }
13+
14+
fn type_error() -> TypeError { todo!() }
15+
//~^ ERROR cannot find type `TypeError` in this scope
16+
17+
fn main() {
18+
let x = mirror(type_error());
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `TypeError` in this scope
2+
--> $DIR/dont-try-normalizing-proj-with-errors.rs:14:20
3+
|
4+
LL | fn type_error() -> TypeError { todo!() }
5+
| ^^^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)