Change wording of missing return type suggestion
This commit is contained in:
parent
b09420f95a
commit
1db02b8a43
6 changed files with 28 additions and 16 deletions
|
@ -530,13 +530,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
err.span_suggestion(
|
||||
span,
|
||||
"try adding a return type",
|
||||
format!("-> {} ", self.resolve_vars_with_obligations(found)),
|
||||
format!("-> {} ", found),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
true
|
||||
}
|
||||
(&hir::FnRetTy::DefaultReturn(span), false, true, true) => {
|
||||
err.span_label(span, "possibly return type missing here?");
|
||||
// FIXME: if `found` could be `impl Iterator` or `impl Fn*`, we should suggest
|
||||
// that.
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"a return type might be missing here",
|
||||
"-> _ ".to_string(),
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
true
|
||||
}
|
||||
(&hir::FnRetTy::DefaultReturn(span), _, false, true) => {
|
||||
|
|
|
@ -2,7 +2,7 @@ error[E0308]: mismatched types
|
|||
--> $DIR/issue-20862.rs:2:5
|
||||
|
|
||||
LL | fn foo(x: i32) {
|
||||
| - possibly return type missing here?
|
||||
| - help: a return type might be missing here: `-> _`
|
||||
LL | |y| x + y
|
||||
| ^^^^^^^^^ expected `()`, found closure
|
||||
|
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/diverging-tuple-parts-39485.rs:8:5
|
||||
|
|
||||
LL | fn g() {
|
||||
| - possibly return type missing here?
|
||||
LL | &panic!()
|
||||
| ^^^^^^^^^ expected `()`, found reference
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found reference `&_`
|
||||
help: a return type might be missing here
|
||||
|
|
||||
LL | fn g() -> _ {
|
||||
| ++++
|
||||
help: consider removing the borrow
|
||||
|
|
||||
LL - &panic!()
|
||||
|
|
|
@ -40,7 +40,7 @@ error[E0308]: mismatched types
|
|||
LL | fn f(){||yield(((){),
|
||||
| -^^^^^^^^^^^^^^^ expected `()`, found generator
|
||||
| |
|
||||
| possibly return type missing here?
|
||||
| help: a return type might be missing here: `-> _`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found generator `[generator@$DIR/issue-91334.rs:10:8: 10:23]`
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#[allow(unused)]
|
||||
fn foo() {
|
||||
//~^ NOTE possibly return type missing here?
|
||||
fn foo() { //~ HELP a return type might be missing here
|
||||
vec!['a'].iter().map(|c| c)
|
||||
//~^ ERROR mismatched types [E0308]
|
||||
//~| NOTE expected `()`, found struct `Map`
|
||||
//~| NOTE expected unit type `()`
|
||||
//~| HELP consider using a semicolon here
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/return_type_containing_closure.rs:4:5
|
||||
--> $DIR/return_type_containing_closure.rs:3:5
|
||||
|
|
||||
LL | fn foo() {
|
||||
| - possibly return type missing here?
|
||||
LL |
|
||||
LL | vec!['a'].iter().map(|c| c)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
|
||||
| |
|
||||
| expected `()`, found struct `Map`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Map`
|
||||
|
|
||||
= note: expected unit type `()`
|
||||
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:4:26: 4:31]>`
|
||||
found struct `Map<std::slice::Iter<'_, char>, [closure@$DIR/return_type_containing_closure.rs:3:26: 3:31]>`
|
||||
help: consider using a semicolon here
|
||||
|
|
||||
LL | vec!['a'].iter().map(|c| c);
|
||||
| +
|
||||
help: a return type might be missing here
|
||||
|
|
||||
LL | fn foo() -> _ {
|
||||
| ++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue