mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Propagate expected return type instead of real return type in check_binop
This commit is contained in:
parent
1b6d6f92d1
commit
d4b59a0da2
@ -148,10 +148,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
rhs_ty,
|
rhs_ty,
|
||||||
op,
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
fn first() {
|
fn first() {
|
||||||
second == 1 //~ ERROR binary operation
|
second == 1 //~ ERROR binary operation
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
|
//~| ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
fn second() {
|
fn second() {
|
||||||
first == 1 //~ ERROR binary operation
|
first == 1 //~ ERROR binary operation
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
|
//~| ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar() {
|
fn bar() {
|
||||||
bar == 1 //~ ERROR binary operation
|
bar == 1 //~ ERROR binary operation
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
|
//~| ERROR mismatched types
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -15,8 +15,16 @@ LL | second == 1
|
|||||||
= note: expected fn item `fn() {second}`
|
= note: expected fn item `fn() {second}`
|
||||||
found type `{integer}`
|
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}`
|
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
|
LL | first == 1
|
||||||
| ----- ^^ - {integer}
|
| ----- ^^ - {integer}
|
||||||
@ -24,7 +32,7 @@ LL | first == 1
|
|||||||
| fn() {first}
|
| fn() {first}
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
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
|
LL | first == 1
|
||||||
| ^ expected fn item, found integer
|
| ^ expected fn item, found integer
|
||||||
@ -32,8 +40,16 @@ LL | first == 1
|
|||||||
= note: expected fn item `fn() {first}`
|
= note: expected fn item `fn() {first}`
|
||||||
found type `{integer}`
|
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}`
|
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
|
LL | bar == 1
|
||||||
| --- ^^ - {integer}
|
| --- ^^ - {integer}
|
||||||
@ -41,7 +57,7 @@ LL | bar == 1
|
|||||||
| fn() {bar}
|
| fn() {bar}
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
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
|
LL | bar == 1
|
||||||
| ^ expected fn item, found integer
|
| ^ expected fn item, found integer
|
||||||
@ -49,7 +65,15 @@ LL | bar == 1
|
|||||||
= note: expected fn item `fn() {bar}`
|
= note: expected fn item `fn() {bar}`
|
||||||
found type `{integer}`
|
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.
|
Some errors have detailed explanations: E0308, E0369.
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
For more information about an error, try `rustc --explain E0308`.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// compile-flags: -Ztrait-solver=next
|
// compile-flags: -Ztrait-solver=next
|
||||||
// known-bug: unknown
|
// check-pass
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
(0u8 + 0u8) as char;
|
(0u8 + 0u8) as char;
|
||||||
|
@ -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`.
|
|
Loading…
Reference in New Issue
Block a user