From 72a3089092da16c247d57915f5e4b99adf2fea4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 13 Mar 2019 16:07:44 -0700 Subject: [PATCH] Only suggest let assignment for type ascription if we find an equals sign --- src/librustc_resolve/lib.rs | 28 ++++++++++++++----- .../type-ascription-instead-of-path.stderr | 12 ++------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 5c5a27a6b43d..12ded62a5d9a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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 { diff --git a/src/test/ui/suggestions/type-ascription-instead-of-path.stderr b/src/test/ui/suggestions/type-ascription-instead-of-path.stderr index 9fe0c3b743c1..9908b3f67989 100644 --- a/src/test/ui/suggestions/type-ascription-instead-of-path.stderr +++ b/src/test/ui/suggestions/type-ascription-instead-of-path.stderr @@ -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