1
Fork 0

Shrink span for bindings with subpatterns.

This commit is contained in:
Camille GILLOT 2022-09-04 00:55:53 +02:00
parent 380addd7d2
commit 5d94d42485
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(