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
This commit is contained in:
Matthias Krüger 2023-08-04 21:31:57 +02:00 committed by GitHub
commit 99e4127d85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
82 changed files with 192 additions and 149 deletions

View file

@ -2854,7 +2854,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
err.note("all local variables must have a statically known size");
}
Some(Node::Local(hir::Local {
init: Some(hir::Expr { kind: hir::ExprKind::Index(_, _), span, .. }),
init: Some(hir::Expr { kind: hir::ExprKind::Index(..), span, .. }),
..
})) => {
// When encountering an assignment of an unsized trait, like