Skip to content

Commit 8bb574f

Browse files
committed
Don't store a redundant span in user-type projections
This span is already present in the corresponding `CanonicalUserTypeAnnotation`, and can be retrieved via the annotation's ID.
1 parent a64efc7 commit 8bb574f

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
456456
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
457457
self.super_local_decl(local, local_decl);
458458

459-
for (user_ty, span) in local_decl
460-
.user_ty
461-
.as_deref()
462-
.into_iter()
463-
.flat_map(UserTypeProjections::projections_and_spans)
459+
for user_ty in
460+
local_decl.user_ty.as_deref().into_iter().flat_map(UserTypeProjections::projections)
464461
{
462+
let span = self.typeck.user_type_annotations[user_ty.base].span;
463+
465464
let ty = if local_decl.is_nonref_binding() {
466465
local_decl.ty
467466
} else if let &ty::Ref(_, rty, _) = local_decl.ty.kind() {
@@ -477,7 +476,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
477476
ty,
478477
ty::Invariant,
479478
user_ty,
480-
Locations::All(*span),
479+
Locations::All(span),
481480
ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
482481
) {
483482
span_mirbug!(

compiler/rustc_middle/src/mir/mod.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ pub struct SourceScopeLocalData {
14941494
/// &'static str`.
14951495
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
14961496
pub struct UserTypeProjections {
1497-
pub contents: Vec<(UserTypeProjection, Span)>,
1497+
pub contents: Vec<UserTypeProjection>,
14981498
}
14991499

15001500
impl<'tcx> UserTypeProjections {
@@ -1506,26 +1506,17 @@ impl<'tcx> UserTypeProjections {
15061506
self.contents.is_empty()
15071507
}
15081508

1509-
pub fn projections_and_spans(
1510-
&self,
1511-
) -> impl Iterator<Item = &(UserTypeProjection, Span)> + ExactSizeIterator {
1512-
self.contents.iter()
1513-
}
1514-
15151509
pub fn projections(&self) -> impl Iterator<Item = &UserTypeProjection> + ExactSizeIterator {
1516-
self.contents.iter().map(|&(ref user_type, _span)| user_type)
1510+
self.contents.iter()
15171511
}
15181512

1519-
pub fn push_user_type(mut self, base_user_ty: UserTypeAnnotationIndex, span: Span) -> Self {
1520-
self.contents.push((UserTypeProjection { base: base_user_ty, projs: vec![] }, span));
1513+
pub fn push_user_type(mut self, base_user_type: UserTypeAnnotationIndex) -> Self {
1514+
self.contents.push(UserTypeProjection { base: base_user_type, projs: vec![] });
15211515
self
15221516
}
15231517

1524-
fn map_projections(
1525-
mut self,
1526-
mut f: impl FnMut(UserTypeProjection) -> UserTypeProjection,
1527-
) -> Self {
1528-
self.contents = self.contents.into_iter().map(|(proj, span)| (f(proj), span)).collect();
1518+
fn map_projections(mut self, f: impl FnMut(UserTypeProjection) -> UserTypeProjection) -> Self {
1519+
self.contents = self.contents.into_iter().map(f).collect();
15291520
self
15301521
}
15311522

compiler/rustc_middle/src/mir/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ macro_rules! make_mir_visitor {
857857
source_info: *source_info,
858858
});
859859
if let Some(user_ty) = user_ty {
860-
for (user_ty, _) in & $($mutability)? user_ty.contents {
860+
for user_ty in & $($mutability)? user_ty.contents {
861861
self.visit_user_type_projection(user_ty);
862862
}
863863
}

compiler/rustc_mir_build/src/builder/matches/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
927927
// of `user_ty` on any bindings contained with subpattern.
928928

929929
let base_user_ty = self.canonical_user_type_annotations.push(annotation.clone());
930-
let subpattern_user_ty =
931-
pattern_user_ty.push_user_type(base_user_ty, annotation.span);
930+
let subpattern_user_ty = pattern_user_ty.push_user_type(base_user_ty);
932931
self.visit_primary_bindings(subpattern, subpattern_user_ty, f)
933932
}
934933

0 commit comments

Comments
 (0)