Improve spans for indexing expressions
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.
This commit is contained in:
parent
fcf3006e01
commit
5706be1854
82 changed files with 192 additions and 149 deletions
|
@ -1754,7 +1754,7 @@ impl Expr<'_> {
|
|||
|
||||
ExprKind::Unary(UnOp::Deref, _) => true,
|
||||
|
||||
ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _) => {
|
||||
ExprKind::Field(ref base, _) | ExprKind::Index(ref base, _, _) => {
|
||||
allow_projections_from(base) || base.is_place_expr(allow_projections_from)
|
||||
}
|
||||
|
||||
|
@ -1831,7 +1831,7 @@ impl Expr<'_> {
|
|||
ExprKind::Type(base, _)
|
||||
| ExprKind::Unary(_, base)
|
||||
| ExprKind::Field(base, _)
|
||||
| ExprKind::Index(base, _)
|
||||
| ExprKind::Index(base, _, _)
|
||||
| ExprKind::AddrOf(.., base)
|
||||
| ExprKind::Cast(base, _) => {
|
||||
// This isn't exactly true for `Index` and all `Unary`, but we are using this
|
||||
|
@ -2015,7 +2015,9 @@ pub enum ExprKind<'hir> {
|
|||
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct or tuple field.
|
||||
Field(&'hir Expr<'hir>, Ident),
|
||||
/// An indexing operation (`foo[2]`).
|
||||
Index(&'hir Expr<'hir>, &'hir Expr<'hir>),
|
||||
/// Similar to [`ExprKind::MethodCall`], the final `Span` represents the span of the brackets
|
||||
/// and index.
|
||||
Index(&'hir Expr<'hir>, &'hir Expr<'hir>, Span),
|
||||
|
||||
/// Path to a definition, possibly containing lifetime or type parameters.
|
||||
Path(QPath<'hir>),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue