Skip to content

Commit f46c412

Browse files
committed
show unit output when there is only output diff in diagnostics
1 parent 28cc0b6 commit f46c412

File tree

7 files changed

+46
-6
lines changed

7 files changed

+46
-6
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11681168
let output1 = sig1.output();
11691169
let output2 = sig2.output();
11701170
let (x1, x2) = self.cmp(output1, output2);
1171-
if !output1.is_unit() {
1171+
let only_output_diff = !lifetime_diff
1172+
&& sig1.c_variadic == sig2.c_variadic
1173+
&& sig1.safety == sig2.safety
1174+
&& sig1.abi == sig2.abi
1175+
&& sig1.inputs() == sig2.inputs()
1176+
&& x1 != x2;
1177+
if !output1.is_unit() || only_output_diff {
11721178
values.0.push_normal(" -> ");
11731179
(values.0).0.extend(x1.0);
11741180
}
1175-
if !output2.is_unit() {
1181+
if !output2.is_unit() || only_output_diff {
11761182
values.1.push_normal(" -> ");
11771183
(values.1).0.extend(x2.0);
11781184
}
1185+
11791186
values
11801187
}
11811188

tests/ui/compare-method/bad-self-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ note: type in trait
4141
LL | fn bar(self) -> Option<()>;
4242
| ^^^^^^^^^^
4343
= note: expected signature `fn(MyFuture) -> Option<()>`
44-
found signature `fn(MyFuture)`
44+
found signature `fn(MyFuture) -> ()`
4545
help: change the output type to match the trait
4646
|
4747
LL | fn bar(self) -> Option<()> {}

tests/ui/error-codes/E0308.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn size_of<T>();
55
| ^ expected `usize`, found `()`
66
|
77
= note: expected signature `extern "rust-intrinsic" fn() -> usize`
8-
found signature `extern "rust-intrinsic" fn()`
8+
found signature `extern "rust-intrinsic" fn() -> ()`
99

1010
error: aborting due to 1 previous error
1111

tests/ui/impl-trait/in-assoc-type-unconstrained.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ note: type in trait
3535
LL | fn method() -> Self::Ty;
3636
| ^^^^^^^^
3737
= note: expected signature `fn() -> <() as compare_method::Trait>::Ty`
38-
found signature `fn()`
38+
found signature `fn() -> ()`
3939
note: this item must have the opaque type in its signature in order to be able to register hidden types
4040
--> $DIR/in-assoc-type-unconstrained.rs:22:12
4141
|

tests/ui/lang-items/start_lang_item_args.missing_ret.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpi
55
| ^ expected `isize`, found `()`
66
|
77
= note: expected signature `fn(fn() -> _, _, _, _) -> isize`
8-
found signature `fn(fn() -> _, _, _, _)`
8+
found signature `fn(fn() -> _, _, _, _) -> ()`
99

1010
error: aborting due to 1 previous error
1111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn bar() {}
2+
fn foo(x: i32) -> u32 {
3+
0
4+
}
5+
fn main() {
6+
let b: fn() -> u32 = bar; //~ ERROR mismatched types [E0308]
7+
let f: fn(i32) = foo; //~ ERROR mismatched types [E0308]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/method-output-diff-issue-127263.rs:6:26
3+
|
4+
LL | let b: fn() -> u32 = bar;
5+
| ----------- ^^^ expected fn pointer, found fn item
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected fn pointer `fn() -> u32`
10+
found fn item `fn() -> () {bar}`
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/method-output-diff-issue-127263.rs:7:22
14+
|
15+
LL | let f: fn(i32) = foo;
16+
| ------- ^^^ expected fn pointer, found fn item
17+
| |
18+
| expected due to this
19+
|
20+
= note: expected fn pointer `fn(_) -> ()`
21+
found fn item `fn(_) -> u32 {foo}`
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)