Skip to content

Commit 251293e

Browse files
authored
Rollup merge of #108287 - compiler-errors:new-solver-bad-cast, r=spastorino
Add test for bad cast with deferred projection equality 1. Unification during coercion (`Coerce::unify`) needs to consider deferred projection obligations (at least pass over them with `predicate_may_hold` or something, to disqualify any totally wrong unifications) -- otherwise, we'll shallowly consider `<u8 as Add>::Output` and `char` as coercible during `FnCtxt::try_coerce`, which will fail later when the nested obligations are registered and processed. 2. Cast checking needs to be able to structurally normalize types so it sees `u8` instead of `<u8 as Add>::Output`. Otherwise it'll always consider the latter as part of a non-primitive cast. Currently `FnCtxt::normalize` doesn't do anything useful here, interestingly. I tried looking into both of these and it's not immediately clear where to refactor existing typeck code to fix this (at least the latter), but I'm gonna commit a test for it at least so we don't forget. This is one of the issues that's keeping us from building larger projects.
2 parents 440113d + eb1f9ba commit 251293e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// known-bug: unknown
3+
4+
fn main() {
5+
(0u8 + 0u8) as char;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0271]: type mismatch resolving `char == <u8 as Add>::Output`
2+
--> $DIR/cast-checks-handling-projections.rs:5:5
3+
|
4+
LL | (0u8 + 0u8) as char;
5+
| ^^^^^^^^^^^ types differ
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)