Skip to content

Commit d4b59a0

Browse files
Propagate expected return type instead of real return type in check_binop
1 parent 1b6d6f9 commit d4b59a0

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

compiler/rustc_hir_typeck/src/op.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
148148
rhs_ty,
149149
op,
150150
);
151-
self.demand_suptype(expr.span, builtin_return_ty, return_ty);
151+
self.demand_eqtype(expr.span, builtin_return_ty, return_ty);
152+
builtin_return_ty
153+
} else {
154+
return_ty
152155
}
153-
154-
return_ty
155156
}
156157
}
157158
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
fn first() {
22
second == 1 //~ ERROR binary operation
33
//~^ ERROR mismatched types
4+
//~| ERROR mismatched types
45
}
56

67
fn second() {
78
first == 1 //~ ERROR binary operation
89
//~^ ERROR mismatched types
10+
//~| ERROR mismatched types
911
}
1012

1113
fn bar() {
1214
bar == 1 //~ ERROR binary operation
1315
//~^ ERROR mismatched types
16+
//~| ERROR mismatched types
1417
}
1518

1619
fn main() {}

tests/ui/issues/issue-66667-function-cmp-cycle.stderr

+29-5
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,65 @@ LL | second == 1
1515
= note: expected fn item `fn() {second}`
1616
found type `{integer}`
1717

18+
error[E0308]: mismatched types
19+
--> $DIR/issue-66667-function-cmp-cycle.rs:2:5
20+
|
21+
LL | fn first() {
22+
| - help: try adding a return type: `-> bool`
23+
LL | second == 1
24+
| ^^^^^^^^^^^ expected `()`, found `bool`
25+
1826
error[E0369]: binary operation `==` cannot be applied to type `fn() {first}`
19-
--> $DIR/issue-66667-function-cmp-cycle.rs:7:11
27+
--> $DIR/issue-66667-function-cmp-cycle.rs:8:11
2028
|
2129
LL | first == 1
2230
| ----- ^^ - {integer}
2331
| |
2432
| fn() {first}
2533

2634
error[E0308]: mismatched types
27-
--> $DIR/issue-66667-function-cmp-cycle.rs:7:14
35+
--> $DIR/issue-66667-function-cmp-cycle.rs:8:14
2836
|
2937
LL | first == 1
3038
| ^ expected fn item, found integer
3139
|
3240
= note: expected fn item `fn() {first}`
3341
found type `{integer}`
3442

43+
error[E0308]: mismatched types
44+
--> $DIR/issue-66667-function-cmp-cycle.rs:8:5
45+
|
46+
LL | fn second() {
47+
| - help: try adding a return type: `-> bool`
48+
LL | first == 1
49+
| ^^^^^^^^^^ expected `()`, found `bool`
50+
3551
error[E0369]: binary operation `==` cannot be applied to type `fn() {bar}`
36-
--> $DIR/issue-66667-function-cmp-cycle.rs:12:9
52+
--> $DIR/issue-66667-function-cmp-cycle.rs:14:9
3753
|
3854
LL | bar == 1
3955
| --- ^^ - {integer}
4056
| |
4157
| fn() {bar}
4258

4359
error[E0308]: mismatched types
44-
--> $DIR/issue-66667-function-cmp-cycle.rs:12:12
60+
--> $DIR/issue-66667-function-cmp-cycle.rs:14:12
4561
|
4662
LL | bar == 1
4763
| ^ expected fn item, found integer
4864
|
4965
= note: expected fn item `fn() {bar}`
5066
found type `{integer}`
5167

52-
error: aborting due to 6 previous errors
68+
error[E0308]: mismatched types
69+
--> $DIR/issue-66667-function-cmp-cycle.rs:14:5
70+
|
71+
LL | fn bar() {
72+
| - help: try adding a return type: `-> bool`
73+
LL | bar == 1
74+
| ^^^^^^^^ expected `()`, found `bool`
75+
76+
error: aborting due to 9 previous errors
5377

5478
Some errors have detailed explanations: E0308, E0369.
5579
For more information about an error, try `rustc --explain E0308`.

tests/ui/typeck/lazy-norm/cast-checks-handling-projections.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -Ztrait-solver=next
2-
// known-bug: unknown
2+
// check-pass
33

44
fn main() {
55
(0u8 + 0u8) as char;

tests/ui/typeck/lazy-norm/cast-checks-handling-projections.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)