Skip to content

Commit 8f2273e

Browse files
committedOct 18, 2024
Fix #131471, range misleading field access
Fixes #131471 by checking if the range-start is a literal.
1 parent 1350eea commit 8f2273e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
 

‎compiler/rustc_resolve/src/late.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4011,6 +4011,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
40114011
let instead = res.is_some();
40124012
let suggestion = if let Some((start, end)) = this.diag_metadata.in_range
40134013
&& path[0].ident.span.lo() == end.span.lo()
4014+
&& !matches!(start.kind, ExprKind::Lit(_))
40144015
{
40154016
let mut sugg = ".";
40164017
let mut span = start.span.between(end.span);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Check if rustc still displays the misleading hint to write `.` instead of `..`
2+
fn main() {
3+
let width = 10;
4+
// ...
5+
for _ in 0..w {
6+
//~^ ERROR cannot find value `w`
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0425]: cannot find value `w` in this scope
2+
--> $DIR/misleading-field-access-hint.rs:5:17
3+
|
4+
LL | for _ in 0..w {
5+
| ^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)