1
Fork 0

Rollup merge of #101399 - cjgillot:borrowck-binding-span, r=estebank

Shrink span for bindings with subpatterns.

Bindings with nested patterns (`binding @ pat` syntax) currently point to the full pattern.  This PR proposes to shrink the span to stop before the ````@`.```  This makes the diagnostics for move/mutability conflicts clearer, as they not point to the `binding` only, instead of the full pat.

r? ```@estebank```
This commit is contained in:
Dylan DPC 2022-09-08 11:55:06 +05:30 committed by GitHub
commit 0d61a507f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 190 additions and 236 deletions

View file

@ -1036,7 +1036,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
VarBindingForm {
binding_mode,
opt_ty_info,
opt_match_place: Some((Some(place), span)),
opt_match_place: Some((None, span)),
pat_span: span,
},
)))))

View file

@ -202,6 +202,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
let mut ty = self.typeck_results.node_type(pat.hir_id);
let mut span = pat.span;
let kind = match pat.kind {
hir::PatKind::Wild => PatKind::Wild,
@ -262,6 +263,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
}
hir::PatKind::Binding(_, id, ident, ref sub) => {
if let Some(ident_span) = ident.span.find_ancestor_inside(span) {
span = span.with_hi(ident_span.hi());
}
let bm = *self
.typeck_results
.pat_binding_modes()
@ -326,7 +331,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
hir::PatKind::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
};
Box::new(Pat { span: pat.span, ty, kind })
Box::new(Pat { span, ty, kind })
}
fn lower_tuple_subpats(