Only suggest let assignment for type ascription if we find an equals sign

This commit is contained in:
Esteban Küber 2019-03-13 16:07:44 -07:00
parent b1a6c32660
commit 72a3089092
2 changed files with 24 additions and 16 deletions

View File

@ -3314,13 +3314,27 @@ impl<'a> Resolver<'a> {
show_label = false;
}
if let Ok(base_snippet) = base_snippet {
err.span_suggestion(
base_span,
"maybe you meant to write an assignment here",
format!("let {}", base_snippet),
Applicability::MaybeIncorrect,
);
show_label = false;
let mut sp = after_colon_sp;
for _ in 0..100 {
// Try to find an assignment
sp = cm.next_point(sp);
let snippet = cm.span_to_snippet(sp.to(cm.next_point(sp)));
match snippet {
Ok(ref x) if x.as_str() == "=" => {
err.span_suggestion(
base_span,
"maybe you meant to write an assignment here",
format!("let {}", base_snippet),
Applicability::MaybeIncorrect,
);
show_label = false;
break;
}
Ok(ref x) if x.as_str() == "\n" => break,
Err(_) => break,
Ok(_) => {}
}
}
}
}
if show_label {

View File

@ -8,15 +8,9 @@ error[E0423]: expected value, found module `std`
--> $DIR/type-ascription-instead-of-path.rs:2:5
|
LL | std:io::stdin();
| ^^^ not a value
help: maybe you meant to write a path separator here
|
LL | std::io::stdin();
| ^^
help: maybe you meant to write an assignment here
|
LL | let std:io::stdin();
| ^^^^^^^
| ^^^- help: maybe you meant to write a path separator here: `::`
| |
| not a value
error[E0658]: type ascription is experimental (see issue #23416)
--> $DIR/type-ascription-instead-of-path.rs:2:5