Skip to content

Commit

Permalink
make suggestion text more legible
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash committed Nov 16, 2023
1 parent 10f1431 commit 5c44314
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
11 changes: 3 additions & 8 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1970,15 +1970,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
{
if !ident_span.from_expansion() {
let (span, text) = match self.r.tcx.sess.source_map().span_to_snippet(ident_span) {
Ok(var_name) => {
Ok(ref name) if let Some(name) = name.strip_prefix("let") => {
// a special case for #117894
let text = var_name.strip_prefix("let").and_then(|rest| {
match rest.starts_with("_") {
true => rest.strip_prefix("_").map(String::from),
false => Some(rest.to_string())
}
}).unwrap_or(var_name);
(ident_span, format!("let {}", text))
let name = name.strip_prefix("_").unwrap_or(name);
(ident_span, format!("let {name}"))
},
_ => (ident_span.shrink_to_lo(), "let ".to_string())
};
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/suggestions/issue-104086-suggest-let.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | x = x = x;
help: you might have meant to introduce a new binding
|
LL | let x = x = x;
| ~~~~~
| +++

error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-104086-suggest-let.rs:2:9
Expand All @@ -30,7 +30,7 @@ LL | x = y = y = y;
help: you might have meant to introduce a new binding
|
LL | let x = y = y = y;
| ~~~~~
| +++

error[E0425]: cannot find value `y` in this scope
--> $DIR/issue-104086-suggest-let.rs:7:9
Expand Down Expand Up @@ -59,7 +59,7 @@ LL | x = y = y;
help: you might have meant to introduce a new binding
|
LL | let x = y = y;
| ~~~~~
| +++

error[E0425]: cannot find value `y` in this scope
--> $DIR/issue-104086-suggest-let.rs:13:9
Expand All @@ -82,7 +82,7 @@ LL | x = x = y;
help: you might have meant to introduce a new binding
|
LL | let x = x = y;
| ~~~~~
| +++

error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-104086-suggest-let.rs:18:9
Expand All @@ -105,7 +105,7 @@ LL | x = x; // will suggest add `let`
help: you might have meant to introduce a new binding
|
LL | let x = x; // will suggest add `let`
| ~~~~~
| +++

error[E0425]: cannot find value `x` in this scope
--> $DIR/issue-104086-suggest-let.rs:23:9
Expand All @@ -122,7 +122,7 @@ LL | x = y // will suggest add `let`
help: you might have meant to introduce a new binding
|
LL | let x = y // will suggest add `let`
| ~~~~~
| +++

error[E0425]: cannot find value `y` in this scope
--> $DIR/issue-104086-suggest-let.rs:27:9
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/suggestions/suggest-let-for-assignment.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | demo = 1;
help: you might have meant to introduce a new binding
|
LL | let demo = 1;
| ~~~~~~~~
| +++

error[E0425]: cannot find value `demo` in this scope
--> $DIR/suggest-let-for-assignment.rs:5:10
Expand All @@ -24,7 +24,7 @@ LL | x = "x";
help: you might have meant to introduce a new binding
|
LL | let x = "x";
| ~~~~~
| +++

error[E0425]: cannot find value `x` in this scope
--> $DIR/suggest-let-for-assignment.rs:8:23
Expand Down Expand Up @@ -81,7 +81,7 @@ LL | y = 1 + 2;
help: you might have meant to introduce a new binding
|
LL | let y = 1 + 2;
| ~~~~~
| +++

error[E0425]: cannot find value `y` in this scope
--> $DIR/suggest-let-for-assignment.rs:22:23
Expand Down

0 comments on commit 5c44314

Please sign in to comment.