1
Fork 0

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.
This commit is contained in:
Zalathar 2025-02-16 21:10:04 +11:00
parent a64efc72d0
commit 8bb574fdd3
4 changed files with 13 additions and 24 deletions

View file

@ -456,12 +456,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) { fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
self.super_local_decl(local, local_decl); self.super_local_decl(local, local_decl);
for (user_ty, span) in local_decl for user_ty in
.user_ty local_decl.user_ty.as_deref().into_iter().flat_map(UserTypeProjections::projections)
.as_deref()
.into_iter()
.flat_map(UserTypeProjections::projections_and_spans)
{ {
let span = self.typeck.user_type_annotations[user_ty.base].span;
let ty = if local_decl.is_nonref_binding() { let ty = if local_decl.is_nonref_binding() {
local_decl.ty local_decl.ty
} else if let &ty::Ref(_, rty, _) = local_decl.ty.kind() { } 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> {
ty, ty,
ty::Invariant, ty::Invariant,
user_ty, user_ty,
Locations::All(*span), Locations::All(span),
ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration), ConstraintCategory::TypeAnnotation(AnnotationSource::Declaration),
) { ) {
span_mirbug!( span_mirbug!(

View file

@ -1494,7 +1494,7 @@ pub struct SourceScopeLocalData {
/// &'static str`. /// &'static str`.
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
pub struct UserTypeProjections { pub struct UserTypeProjections {
pub contents: Vec<(UserTypeProjection, Span)>, pub contents: Vec<UserTypeProjection>,
} }
impl<'tcx> UserTypeProjections { impl<'tcx> UserTypeProjections {
@ -1506,26 +1506,17 @@ impl<'tcx> UserTypeProjections {
self.contents.is_empty() self.contents.is_empty()
} }
pub fn projections_and_spans( pub fn projections(&self) -> impl Iterator<Item = &UserTypeProjection> + ExactSizeIterator {
&self,
) -> impl Iterator<Item = &(UserTypeProjection, Span)> + ExactSizeIterator {
self.contents.iter() self.contents.iter()
} }
pub fn projections(&self) -> impl Iterator<Item = &UserTypeProjection> + ExactSizeIterator { pub fn push_user_type(mut self, base_user_type: UserTypeAnnotationIndex) -> Self {
self.contents.iter().map(|&(ref user_type, _span)| user_type) self.contents.push(UserTypeProjection { base: base_user_type, projs: vec![] });
}
pub fn push_user_type(mut self, base_user_ty: UserTypeAnnotationIndex, span: Span) -> Self {
self.contents.push((UserTypeProjection { base: base_user_ty, projs: vec![] }, span));
self self
} }
fn map_projections( fn map_projections(mut self, f: impl FnMut(UserTypeProjection) -> UserTypeProjection) -> Self {
mut self, self.contents = self.contents.into_iter().map(f).collect();
mut f: impl FnMut(UserTypeProjection) -> UserTypeProjection,
) -> Self {
self.contents = self.contents.into_iter().map(|(proj, span)| (f(proj), span)).collect();
self self
} }

View file

@ -857,7 +857,7 @@ macro_rules! make_mir_visitor {
source_info: *source_info, source_info: *source_info,
}); });
if let Some(user_ty) = user_ty { if let Some(user_ty) = user_ty {
for (user_ty, _) in & $($mutability)? user_ty.contents { for user_ty in & $($mutability)? user_ty.contents {
self.visit_user_type_projection(user_ty); self.visit_user_type_projection(user_ty);
} }
} }

View file

@ -927,8 +927,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// of `user_ty` on any bindings contained with subpattern. // of `user_ty` on any bindings contained with subpattern.
let base_user_ty = self.canonical_user_type_annotations.push(annotation.clone()); let base_user_ty = self.canonical_user_type_annotations.push(annotation.clone());
let subpattern_user_ty = let subpattern_user_ty = pattern_user_ty.push_user_type(base_user_ty);
pattern_user_ty.push_user_type(base_user_ty, annotation.span);
self.visit_primary_bindings(subpattern, subpattern_user_ty, f) self.visit_primary_bindings(subpattern, subpattern_user_ty, f)
} }