Skip to content

Commit 6e8aa1f

Browse files
committed
review comments: wording and style
1 parent f84b7e1 commit 6e8aa1f

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

src/librustc_typeck/check/mod.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -5502,7 +5502,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
55025502
expected: Ty<'tcx>,
55035503
found: Ty<'tcx>,
55045504
) {
5505-
match (&expected.kind, &found.kind) {
5505+
let (sig, did, substs) = match (&expected.kind, &found.kind) {
55065506
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
55075507
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
55085508
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
@@ -5513,29 +5513,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
55135513
"different `fn` items always have unique types, even if their signatures are \
55145514
the same",
55155515
);
5516-
err.help(&format!("change the expectation to require function pointer `{}`", sig1));
5517-
err.help(&format!(
5518-
"if the expectation is due to type inference, cast the expected `fn` to a \
5519-
function pointer: `{} as {}`",
5520-
self.tcx.def_path_str_with_substs(*did1, substs1),
5521-
sig1
5522-
));
5516+
(sig1, *did1, substs1)
55235517
}
55245518
(ty::FnDef(did, substs), ty::FnPtr(sig2)) => {
55255519
let sig1 = self.tcx.fn_sig(*did).subst(self.tcx, substs);
55265520
if sig1 != *sig2 {
55275521
return;
55285522
}
5529-
err.help(&format!("change the expectation to require function pointer `{}`", sig1));
5530-
err.help(&format!(
5531-
"if the expectation is due to type inference, cast the expected `fn` to a \
5532-
function pointer: `{} as {}`",
5533-
self.tcx.def_path_str_with_substs(*did, substs),
5534-
sig1
5535-
));
5523+
(sig1, *did, substs)
55365524
}
5537-
_ => {}
5538-
}
5525+
_ => return,
5526+
};
5527+
err.help(&format!("change the expected type to be function pointer `{}`", sig));
5528+
err.help(&format!(
5529+
"if the expected type is due to type inference, cast the expected `fn` to a function \
5530+
pointer: `{} as {}`",
5531+
self.tcx.def_path_str_with_substs(did, substs),
5532+
sig
5533+
));
55395534
}
55405535

55415536
/// A common error is to add an extra semicolon:

src/test/ui/fn/fn-item-type.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,40 @@ fn main() {
1616
//~| found fn item `fn(_) -> _ {bar::<u8>}`
1717
//~| expected fn item, found a different fn item
1818
//~| different `fn` items always have unique types, even if their signatures are the same
19-
//~| change the expectation to require function pointer
20-
//~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
19+
//~| change the expected type to be function pointer
20+
//~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
2121

2222
eq(foo::<u8>, foo::<i8>);
2323
//~^ ERROR mismatched types
2424
//~| expected `u8`, found `i8`
2525
//~| different `fn` items always have unique types, even if their signatures are the same
26-
//~| change the expectation to require function pointer
27-
//~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
26+
//~| change the expected type to be function pointer
27+
//~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
2828

2929
eq(bar::<String>, bar::<Vec<u8>>);
3030
//~^ ERROR mismatched types
3131
//~| expected fn item `fn(_) -> _ {bar::<std::string::String>}`
3232
//~| found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
3333
//~| expected struct `std::string::String`, found struct `std::vec::Vec`
3434
//~| different `fn` items always have unique types, even if their signatures are the same
35-
//~| change the expectation to require function pointer
36-
//~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
35+
//~| change the expected type to be function pointer
36+
//~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
3737

3838
// Make sure we distinguish between trait methods correctly.
3939
eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
4040
//~^ ERROR mismatched types
4141
//~| expected `u8`, found `u16`
4242
//~| different `fn` items always have unique types, even if their signatures are the same
43-
//~| change the expectation to require function pointer
44-
//~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
43+
//~| change the expected type to be function pointer
44+
//~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
4545

4646
eq(foo::<u8>, bar::<u8> as fn(isize) -> isize);
4747
//~^ ERROR mismatched types
4848
//~| expected fn item `fn(_) -> _ {foo::<u8>}`
4949
//~| found fn pointer `fn(_) -> _`
5050
//~| expected fn item, found fn pointer
51-
//~| change the expectation to require function pointer
52-
//~| if the expectation is due to type inference, cast the expected `fn` to a function pointer
51+
//~| change the expected type to be function pointer
52+
//~| if the expected type is due to type inference, cast the expected `fn` to a function pointer
5353

5454
eq(foo::<u8> as fn(isize) -> isize, bar::<u8>); // ok!
5555
}

src/test/ui/fn/fn-item-type.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | eq(foo::<u8>, bar::<u8>);
77
= note: expected fn item `fn(_) -> _ {foo::<u8>}`
88
found fn item `fn(_) -> _ {bar::<u8>}`
99
= note: different `fn` items always have unique types, even if their signatures are the same
10-
= help: change the expectation to require function pointer `fn(isize) -> isize`
11-
= help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
10+
= help: change the expected type to be function pointer `fn(isize) -> isize`
11+
= help: if the expected type is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
1212

1313
error[E0308]: mismatched types
1414
--> $DIR/fn-item-type.rs:22:19
@@ -19,8 +19,8 @@ LL | eq(foo::<u8>, foo::<i8>);
1919
= note: expected fn item `fn(_) -> _ {foo::<u8>}`
2020
found fn item `fn(_) -> _ {foo::<i8>}`
2121
= note: different `fn` items always have unique types, even if their signatures are the same
22-
= help: change the expectation to require function pointer `fn(isize) -> isize`
23-
= help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
22+
= help: change the expected type to be function pointer `fn(isize) -> isize`
23+
= help: if the expected type is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
2424

2525
error[E0308]: mismatched types
2626
--> $DIR/fn-item-type.rs:29:23
@@ -31,8 +31,8 @@ LL | eq(bar::<String>, bar::<Vec<u8>>);
3131
= note: expected fn item `fn(_) -> _ {bar::<std::string::String>}`
3232
found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
3333
= note: different `fn` items always have unique types, even if their signatures are the same
34-
= help: change the expectation to require function pointer `fn(isize) -> isize`
35-
= help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `bar::<std::string::String> as fn(isize) -> isize`
34+
= help: change the expected type to be function pointer `fn(isize) -> isize`
35+
= help: if the expected type is due to type inference, cast the expected `fn` to a function pointer: `bar::<std::string::String> as fn(isize) -> isize`
3636

3737
error[E0308]: mismatched types
3838
--> $DIR/fn-item-type.rs:39:26
@@ -43,8 +43,8 @@ LL | eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
4343
= note: expected fn item `fn() {<u8 as Foo>::foo}`
4444
found fn item `fn() {<u16 as Foo>::foo}`
4545
= note: different `fn` items always have unique types, even if their signatures are the same
46-
= help: change the expectation to require function pointer `fn()`
47-
= help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `<u8 as Foo>::foo as fn()`
46+
= help: change the expected type to be function pointer `fn()`
47+
= help: if the expected type is due to type inference, cast the expected `fn` to a function pointer: `<u8 as Foo>::foo as fn()`
4848

4949
error[E0308]: mismatched types
5050
--> $DIR/fn-item-type.rs:46:19
@@ -54,8 +54,8 @@ LL | eq(foo::<u8>, bar::<u8> as fn(isize) -> isize);
5454
|
5555
= note: expected fn item `fn(_) -> _ {foo::<u8>}`
5656
found fn pointer `fn(_) -> _`
57-
= help: change the expectation to require function pointer `fn(isize) -> isize`
58-
= help: if the expectation is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
57+
= help: change the expected type to be function pointer `fn(isize) -> isize`
58+
= help: if the expected type is due to type inference, cast the expected `fn` to a function pointer: `foo::<u8> as fn(isize) -> isize`
5959

6060
error: aborting due to 5 previous errors
6161

0 commit comments

Comments
 (0)