Skip to content

Commit 413345c

Browse files
Rollup merge of #127417 - chenyukang:yukang-method-output-diff, r=oli-obk
Show fnsig's unit output explicitly when there is output diff in diagnostics Fixes #127263
2 parents 9352026 + 81c86dd commit 413345c

12 files changed

+48
-13
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,16 @@ 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 output_diff = x1 != x2;
1172+
if !output1.is_unit() || output_diff {
11721173
values.0.push_normal(" -> ");
11731174
(values.0).0.extend(x1.0);
11741175
}
1175-
if !output2.is_unit() {
1176+
if !output2.is_unit() || output_diff {
11761177
values.1.push_normal(" -> ");
11771178
(values.1).0.extend(x2.0);
11781179
}
1180+
11791181
values
11801182
}
11811183

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/feature-gates/feature-gate-unboxed-closures-manual-impls.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ LL | extern "rust-call" fn call(self, args: ()) -> () {}
9292
| ^^^^ expected `&Foo`, found `Foo`
9393
|
9494
= note: expected signature `extern "rust-call" fn(&Foo, ()) -> _`
95-
found signature `extern "rust-call" fn(Foo, ())`
95+
found signature `extern "rust-call" fn(Foo, ()) -> ()`
9696
help: change the self-receiver type to match the trait
9797
|
9898
LL | extern "rust-call" fn call(&self, args: ()) -> () {}
@@ -162,7 +162,7 @@ LL | extern "rust-call" fn call_mut(&self, args: ()) -> () {}
162162
| ^^^^^ types differ in mutability
163163
|
164164
= note: expected signature `extern "rust-call" fn(&mut Bar, ()) -> _`
165-
found signature `extern "rust-call" fn(&Bar, ())`
165+
found signature `extern "rust-call" fn(&Bar, ()) -> ()`
166166
help: change the self-receiver type to match the trait
167167
|
168168
LL | extern "rust-call" fn call_mut(&mut self, args: ()) -> () {}

tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | x = foo::<()>;
1010
| ^^^^^^^^^ expected fn item, found a different fn item
1111
|
1212
= note: expected fn item `fn(F) -> F {bar::<F>}`
13-
found fn item `fn(()) {foo::<()>}`
13+
found fn item `fn(()) -> () {foo::<()>}`
1414

1515
error[E0308]: mismatched types
1616
--> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:27:9
@@ -26,7 +26,7 @@ LL | let mut x = bar::<()>;
2626
LL | x = foo::<I>;
2727
| ^^^^^^^^ expected fn item, found a different fn item
2828
|
29-
= note: expected fn item `fn(()) {bar::<()>}`
29+
= note: expected fn item `fn(()) -> () {bar::<()>}`
3030
found fn item `fn(I) -> I {foo::<I>}`
3131
help: use parentheses to call this function
3232
|

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/impl-trait/trait_type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn fmt(&self, x: &str) -> () { }
55
| ^^^^ types differ in mutability
66
|
77
= note: expected signature `fn(&MyType, &mut Formatter<'_>) -> Result<(), std::fmt::Error>`
8-
found signature `fn(&MyType, &str)`
8+
found signature `fn(&MyType, &str) -> ()`
99
help: change the parameter type to match the trait
1010
|
1111
LL | fn fmt(&self, x: &mut Formatter<'_>) -> () { }

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`.

tests/ui/panic-handler/panic-handler-bad-signature-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | fn panic(info: PanicInfo) -> () {}
55
| ^^^^^^^^^ expected `&PanicInfo<'_>`, found `PanicInfo<'_>`
66
|
77
= note: expected signature `for<'a, 'b> fn(&'a PanicInfo<'b>) -> !`
8-
found signature `for<'a> fn(PanicInfo<'a>)`
8+
found signature `for<'a> fn(PanicInfo<'a>) -> ()`
99

1010
error: aborting due to 1 previous error
1111

tests/ui/traits/impl-method-mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: type in trait
1010
LL | fn jumbo(&self, x: &usize) -> usize;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= note: expected signature `fn(&_, &_) -> usize`
13-
found signature `unsafe fn(&_, &_)`
13+
found signature `unsafe fn(&_, &_) -> ()`
1414

1515
error: aborting due to 1 previous error
1616

0 commit comments

Comments
 (0)