diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-04 21:31:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-04 21:31:57 +0200 |
| commit | 6e87f866ec1fd68aa9ca6379491acbbfff09fa6a (patch) | |
| tree | ade1535ae6cf40e3ac931f0e0058a234b4c04e73 /src | |
| parent | 4cc22af56ccd5bc5ced2c025bfb3d4816bf955e5 (diff) | |
| parent | aca22c73fde0a290c8b682e465a0ad28f0690be7 (diff) | |
| download | rust-6e87f866ec1fd68aa9ca6379491acbbfff09fa6a.tar.gz rust-6e87f866ec1fd68aa9ca6379491acbbfff09fa6a.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/expr.rs | 4 | ||||
| -rw-r--r-- | src/matches.rs | 2 | ||||
| -rw-r--r-- | src/utils.rs | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/src/expr.rs b/src/expr.rs index 739afb4e0ac..c3c07f310bf 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -256,7 +256,7 @@ pub(crate) fn format_expr( shape, SeparatorPlace::Back, ), - ast::ExprKind::Index(ref expr, ref index) => { + ast::ExprKind::Index(ref expr, ref index, _) => { rewrite_index(&**expr, &**index, context, shape) } ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair( @@ -1342,7 +1342,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool { | ast::ExprKind::Field(ref expr, _) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr), - ast::ExprKind::Index(ref lhs, ref rhs) => is_simple_expr(lhs) && is_simple_expr(rhs), + ast::ExprKind::Index(ref lhs, ref rhs, _) => is_simple_expr(lhs) && is_simple_expr(rhs), ast::ExprKind::Repeat(ref lhs, ref rhs) => { is_simple_expr(lhs) && is_simple_expr(&*rhs.value) } diff --git a/src/matches.rs b/src/matches.rs index aac5e59b860..4c37116f120 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -594,7 +594,7 @@ fn can_flatten_block_around_this(body: &ast::Expr) -> bool { ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) - | ast::ExprKind::Index(ref expr, _) + | ast::ExprKind::Index(ref expr, _, _) | ast::ExprKind::Cast(ref expr, _) => can_flatten_block_around_this(expr), _ => false, } diff --git a/src/utils.rs b/src/utils.rs index 890a05b8c82..4fc5a9b6896 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -441,7 +441,7 @@ pub(crate) fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr { | ast::ExprKind::Assign(ref e, _, _) | ast::ExprKind::AssignOp(_, ref e, _) | ast::ExprKind::Field(ref e, _) - | ast::ExprKind::Index(ref e, _) + | ast::ExprKind::Index(ref e, _, _) | ast::ExprKind::Range(Some(ref e), _, _) | ast::ExprKind::Try(ref e) => left_most_sub_expr(e), _ => e, @@ -479,7 +479,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::Match(..) => repr.contains('\n'), ast::ExprKind::Paren(ref expr) | ast::ExprKind::Binary(_, _, ref expr) - | ast::ExprKind::Index(_, ref expr) + | ast::ExprKind::Index(_, ref expr, _) | ast::ExprKind::Unary(_, ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Yield(Some(ref expr)) => is_block_expr(context, expr, repr), |
