Skip to content

Commit 7145cb1

Browse files
committed
show unit output when there is only output diff in diagnostics
1 parent 11dd90f commit 7145cb1

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
@@ -1165,17 +1165,24 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11651165

11661166
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
11671167
// ^^^^^^^^
1168+
let all_other_same = !lifetime_diff
1169+
&& sig1.c_variadic == sig2.c_variadic
1170+
&& sig1.safety == sig2.safety
1171+
&& sig1.abi == sig2.abi
1172+
&& sig1.inputs() == sig2.inputs();
11681173
let output1 = sig1.output();
11691174
let output2 = sig2.output();
11701175
let (x1, x2) = self.cmp(output1, output2);
1171-
if !output1.is_unit() {
1176+
let only_output_diff = all_other_same && 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
@@ -39,7 +39,7 @@ note: type in trait
3939
LL | fn bar(self) -> Option<()>;
4040
| ^^^^^^^^^^
4141
= note: expected signature `fn(MyFuture) -> Option<()>`
42-
found signature `fn(MyFuture)`
42+
found signature `fn(MyFuture) -> ()`
4343
help: change the output type to match the trait
4444
|
4545
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
@@ -38,7 +38,7 @@ note: type in trait
3838
LL | fn method() -> Self::Ty;
3939
| ^^^^^^^^
4040
= note: expected signature `fn() -> <() as compare_method::Trait>::Ty`
41-
found signature `fn()`
41+
found signature `fn() -> ()`
4242
note: this item must have the opaque type in its signature in order to be able to register hidden types
4343
--> $DIR/in-assoc-type-unconstrained.rs:22:12
4444
|

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)