Propagate expected return type instead of real return type in check_binop

This commit is contained in:
Michael Goulet 2023-03-09 17:11:30 +00:00
parent 1b6d6f92d1
commit d4b59a0da2
5 changed files with 37 additions and 18 deletions

View File

@ -148,10 +148,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rhs_ty,
op,
);
self.demand_suptype(expr.span, builtin_return_ty, return_ty);
self.demand_eqtype(expr.span, builtin_return_ty, return_ty);
builtin_return_ty
} else {
return_ty
}
return_ty
}
}
}

View File

@ -1,16 +1,19 @@
fn first() {
second == 1 //~ ERROR binary operation
//~^ ERROR mismatched types
//~| ERROR mismatched types
}
fn second() {
first == 1 //~ ERROR binary operation
//~^ ERROR mismatched types
//~| ERROR mismatched types
}
fn bar() {
bar == 1 //~ ERROR binary operation
//~^ ERROR mismatched types
//~| ERROR mismatched types
}
fn main() {}

View File

@ -15,8 +15,16 @@ LL | second == 1
= note: expected fn item `fn() {second}`
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:2:5
|
LL | fn first() {
| - help: try adding a return type: `-> bool`
LL | second == 1
| ^^^^^^^^^^^ expected `()`, found `bool`
error[E0369]: binary operation `==` cannot be applied to type `fn() {first}`
--> $DIR/issue-66667-function-cmp-cycle.rs:7:11
--> $DIR/issue-66667-function-cmp-cycle.rs:8:11
|
LL | first == 1
| ----- ^^ - {integer}
@ -24,7 +32,7 @@ LL | first == 1
| fn() {first}
error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:7:14
--> $DIR/issue-66667-function-cmp-cycle.rs:8:14
|
LL | first == 1
| ^ expected fn item, found integer
@ -32,8 +40,16 @@ LL | first == 1
= note: expected fn item `fn() {first}`
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:8:5
|
LL | fn second() {
| - help: try adding a return type: `-> bool`
LL | first == 1
| ^^^^^^^^^^ expected `()`, found `bool`
error[E0369]: binary operation `==` cannot be applied to type `fn() {bar}`
--> $DIR/issue-66667-function-cmp-cycle.rs:12:9
--> $DIR/issue-66667-function-cmp-cycle.rs:14:9
|
LL | bar == 1
| --- ^^ - {integer}
@ -41,7 +57,7 @@ LL | bar == 1
| fn() {bar}
error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:12:12
--> $DIR/issue-66667-function-cmp-cycle.rs:14:12
|
LL | bar == 1
| ^ expected fn item, found integer
@ -49,7 +65,15 @@ LL | bar == 1
= note: expected fn item `fn() {bar}`
found type `{integer}`
error: aborting due to 6 previous errors
error[E0308]: mismatched types
--> $DIR/issue-66667-function-cmp-cycle.rs:14:5
|
LL | fn bar() {
| - help: try adding a return type: `-> bool`
LL | bar == 1
| ^^^^^^^^ expected `()`, found `bool`
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0308, E0369.
For more information about an error, try `rustc --explain E0308`.

View File

@ -1,5 +1,5 @@
// compile-flags: -Ztrait-solver=next
// known-bug: unknown
// check-pass
fn main() {
(0u8 + 0u8) as char;

View File

@ -1,9 +0,0 @@
error[E0271]: type mismatch resolving `char == <u8 as Add>::Output`
--> $DIR/cast-checks-handling-projections.rs:5:5
|
LL | (0u8 + 0u8) as char;
| ^^^^^^^^^^^ types differ
error: aborting due to previous error
For more information about this error, try `rustc --explain E0271`.