Skip to content

Commit 72a3089

Browse files
committed
Only suggest let assignment for type ascription if we find an equals sign
1 parent b1a6c32 commit 72a3089

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/librustc_resolve/lib.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,13 +3314,27 @@ impl<'a> Resolver<'a> {
33143314
show_label = false;
33153315
}
33163316
if let Ok(base_snippet) = base_snippet {
3317-
err.span_suggestion(
3318-
base_span,
3319-
"maybe you meant to write an assignment here",
3320-
format!("let {}", base_snippet),
3321-
Applicability::MaybeIncorrect,
3322-
);
3323-
show_label = false;
3317+
let mut sp = after_colon_sp;
3318+
for _ in 0..100 {
3319+
// Try to find an assignment
3320+
sp = cm.next_point(sp);
3321+
let snippet = cm.span_to_snippet(sp.to(cm.next_point(sp)));
3322+
match snippet {
3323+
Ok(ref x) if x.as_str() == "=" => {
3324+
err.span_suggestion(
3325+
base_span,
3326+
"maybe you meant to write an assignment here",
3327+
format!("let {}", base_snippet),
3328+
Applicability::MaybeIncorrect,
3329+
);
3330+
show_label = false;
3331+
break;
3332+
}
3333+
Ok(ref x) if x.as_str() == "\n" => break,
3334+
Err(_) => break,
3335+
Ok(_) => {}
3336+
}
3337+
}
33243338
}
33253339
}
33263340
if show_label {

src/test/ui/suggestions/type-ascription-instead-of-path.stderr

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@ error[E0423]: expected value, found module `std`
88
--> $DIR/type-ascription-instead-of-path.rs:2:5
99
|
1010
LL | std:io::stdin();
11-
| ^^^ not a value
12-
help: maybe you meant to write a path separator here
13-
|
14-
LL | std::io::stdin();
15-
| ^^
16-
help: maybe you meant to write an assignment here
17-
|
18-
LL | let std:io::stdin();
19-
| ^^^^^^^
11+
| ^^^- help: maybe you meant to write a path separator here: `::`
12+
| |
13+
| not a value
2014

2115
error[E0658]: type ascription is experimental (see issue #23416)
2216
--> $DIR/type-ascription-instead-of-path.rs:2:5

0 commit comments

Comments
 (0)