Skip to content

Commit 1db02b8

Browse files
committed
Change wording of missing return type suggestion
1 parent b09420f commit 1db02b8

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
530530
err.span_suggestion(
531531
span,
532532
"try adding a return type",
533-
format!("-> {} ", self.resolve_vars_with_obligations(found)),
533+
format!("-> {} ", found),
534534
Applicability::MachineApplicable,
535535
);
536536
true
537537
}
538538
(&hir::FnRetTy::DefaultReturn(span), false, true, true) => {
539-
err.span_label(span, "possibly return type missing here?");
539+
// FIXME: if `found` could be `impl Iterator` or `impl Fn*`, we should suggest
540+
// that.
541+
err.span_suggestion(
542+
span,
543+
"a return type might be missing here",
544+
"-> _ ".to_string(),
545+
Applicability::HasPlaceholders,
546+
);
540547
true
541548
}
542549
(&hir::FnRetTy::DefaultReturn(span), _, false, true) => {

src/test/ui/block-result/issue-20862.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-20862.rs:2:5
33
|
44
LL | fn foo(x: i32) {
5-
| - possibly return type missing here?
5+
| - help: a return type might be missing here: `-> _`
66
LL | |y| x + y
77
| ^^^^^^^^^ expected `()`, found closure
88
|

src/test/ui/never_type/diverging-tuple-parts-39485.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
error[E0308]: mismatched types
22
--> $DIR/diverging-tuple-parts-39485.rs:8:5
33
|
4-
LL | fn g() {
5-
| - possibly return type missing here?
64
LL | &panic!()
75
| ^^^^^^^^^ expected `()`, found reference
86
|
97
= note: expected unit type `()`
108
found reference `&_`
9+
help: a return type might be missing here
10+
|
11+
LL | fn g() -> _ {
12+
| ++++
1113
help: consider removing the borrow
1214
|
1315
LL - &panic!()

src/test/ui/typeck/issue-91334.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ error[E0308]: mismatched types
4040
LL | fn f(){||yield(((){),
4141
| -^^^^^^^^^^^^^^^ expected `()`, found generator
4242
| |
43-
| possibly return type missing here?
43+
| help: a return type might be missing here: `-> _`
4444
|
4545
= note: expected unit type `()`
4646
found generator `[generator@$DIR/issue-91334.rs:10:8: 10:23]`
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#[allow(unused)]
2-
fn foo() {
3-
//~^ NOTE possibly return type missing here?
2+
fn foo() { //~ HELP a return type might be missing here
43
vec!['a'].iter().map(|c| c)
54
//~^ ERROR mismatched types [E0308]
65
//~| NOTE expected `()`, found struct `Map`
76
//~| NOTE expected unit type `()`
7+
//~| HELP consider using a semicolon here
88
}
99

1010
fn main() {}

src/test/ui/typeck/return_type_containing_closure.stderr

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
error[E0308]: mismatched types
2-
--> $DIR/return_type_containing_closure.rs:4:5
2+
--> $DIR/return_type_containing_closure.rs:3:5
33
|
4-
LL | fn foo() {
5-
| - possibly return type missing here?
6-
LL |
74
LL | vec!['a'].iter().map(|c| c)
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
9-
| |
10-
| expected `()`, found struct `Map`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Map`
116
|
127
= note: expected unit type `()`
13-
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:4:26: 4:31]>`
8+
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:3:26: 3:31]>`
9+
help: consider using a semicolon here
10+
|
11+
LL | vec!['a'].iter().map(|c| c);
12+
| +
13+
help: a return type might be missing here
14+
|
15+
LL | fn foo() -> _ {
16+
| ++++
1417

1518
error: aborting due to previous error
1619

0 commit comments

Comments
 (0)