Skip to content

Commit 9f3fdb1

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 96ca7bb commit 9f3fdb1

File tree

3 files changed

+12
-23
lines changed
  • compiler
    • rustc_borrowck/src/type_check
    • rustc_middle/src/mir
    • rustc_mir_build/src/builder/matches

3 files changed

+12
-23
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

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

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

compiler/rustc_middle/src/mir/mod.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ pub struct SourceScopeLocalData {
15601560
/// &'static str`.
15611561
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
15621562
pub struct UserTypeProjections {
1563-
pub contents: Vec<(UserTypeProjection, Span)>,
1563+
pub contents: Vec<UserTypeProjection>,
15641564
}
15651565

15661566
impl<'tcx> UserTypeProjections {
@@ -1572,26 +1572,17 @@ impl<'tcx> UserTypeProjections {
15721572
self.contents.is_empty()
15731573
}
15741574

1575-
pub fn projections_and_spans(
1576-
&self,
1577-
) -> impl Iterator<Item = &(UserTypeProjection, Span)> + ExactSizeIterator {
1578-
self.contents.iter()
1579-
}
1580-
15811575
pub fn projections(&self) -> impl Iterator<Item = &UserTypeProjection> + ExactSizeIterator {
1582-
self.contents.iter().map(|&(ref user_type, _span)| user_type)
1576+
self.contents.iter()
15831577
}
15841578

1585-
pub fn push_user_type(mut self, base_user_ty: UserTypeAnnotationIndex, span: Span) -> Self {
1586-
self.contents.push((UserTypeProjection { base: base_user_ty, projs: vec![] }, span));
1579+
pub fn push_user_type(mut self, base_user_type: UserTypeAnnotationIndex) -> Self {
1580+
self.contents.push(UserTypeProjection { base: base_user_type, projs: vec![] });
15871581
self
15881582
}
15891583

1590-
fn map_projections(
1591-
mut self,
1592-
mut f: impl FnMut(UserTypeProjection) -> UserTypeProjection,
1593-
) -> Self {
1594-
self.contents = self.contents.into_iter().map(|(proj, span)| (f(proj), span)).collect();
1584+
fn map_projections(mut self, f: impl FnMut(UserTypeProjection) -> UserTypeProjection) -> Self {
1585+
self.contents = self.contents.into_iter().map(f).collect();
15951586
self
15961587
}
15971588

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)