Skip to content

Commit

Permalink
Rollup merge of rust-lang#131537 - hirschenberger:master, r=compiler-…
Browse files Browse the repository at this point in the history
…errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
  • Loading branch information
matthiaskrgr authored Oct 19, 2024
2 parents 98e90f4 + 8f2273e commit 7810951
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4011,6 +4011,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
let instead = res.is_some();
let suggestion = if let Some((start, end)) = this.diag_metadata.in_range
&& path[0].ident.span.lo() == end.span.lo()
&& !matches!(start.kind, ExprKind::Lit(_))
{
let mut sugg = ".";
let mut span = start.span.between(end.span);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/range/misleading-field-access-hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Check if rustc still displays the misleading hint to write `.` instead of `..`
fn main() {
let width = 10;
// ...
for _ in 0..w {
//~^ ERROR cannot find value `w`
}
}
9 changes: 9 additions & 0 deletions tests/ui/range/misleading-field-access-hint.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find value `w` in this scope
--> $DIR/misleading-field-access-hint.rs:5:17
|
LL | for _ in 0..w {
| ^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.

0 comments on commit 7810951

Please sign in to comment.