Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 99e4127

Browse files
authoredAug 4, 2023
Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31
Improve spans for indexing expressions fixes #114388 Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR. r? compiler-errors
2 parents 4669905 + 5706be1 commit 99e4127

File tree

82 files changed

+192
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+192
-149
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,8 @@ pub enum ExprKind {
14621462
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
14631463
Field(P<Expr>, Ident),
14641464
/// An indexing operation (e.g., `foo[2]`).
1465-
Index(P<Expr>, P<Expr>),
1465+
/// The span represents the span of the `[2]`, including brackets.
1466+
Index(P<Expr>, P<Expr>, Span),
14661467
/// A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`; and `..` in destructuring assignment).
14671468
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits),
14681469
/// An underscore, used in destructuring assignment to ignore a value.

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,14 +1400,15 @@ pub fn noop_visit_expr<T: MutVisitor>(
14001400
fn_decl,
14011401
body,
14021402
fn_decl_span,
1403-
fn_arg_span: _,
1403+
fn_arg_span,
14041404
}) => {
14051405
vis.visit_closure_binder(binder);
14061406
visit_constness(constness, vis);
14071407
vis.visit_asyncness(asyncness);
14081408
vis.visit_fn_decl(fn_decl);
14091409
vis.visit_expr(body);
14101410
vis.visit_span(fn_decl_span);
1411+
vis.visit_span(fn_arg_span);
14111412
}
14121413
ExprKind::Block(blk, label) => {
14131414
vis.visit_block(blk);
@@ -1420,9 +1421,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
14201421
vis.visit_expr(expr);
14211422
vis.visit_span(await_kw_span);
14221423
}
1423-
ExprKind::Assign(el, er, _) => {
1424+
ExprKind::Assign(el, er, span) => {
14241425
vis.visit_expr(el);
14251426
vis.visit_expr(er);
1427+
vis.visit_span(span);
14261428
}
14271429
ExprKind::AssignOp(_op, el, er) => {
14281430
vis.visit_expr(el);
@@ -1432,9 +1434,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
14321434
vis.visit_expr(el);
14331435
vis.visit_ident(ident);
14341436
}
1435-
ExprKind::Index(el, er) => {
1437+
ExprKind::Index(el, er, brackets_span) => {
14361438
vis.visit_expr(el);
14371439
vis.visit_expr(er);
1440+
vis.visit_span(brackets_span);
14381441
}
14391442
ExprKind::Range(e1, e2, _lim) => {
14401443
visit_opt(e1, |e1| vis.visit_expr(e1));

0 commit comments

Comments
 (0)
Please sign in to comment.