Skip to content

Commit 5d73e5b

Browse files
committed
Newtype for AscribeUserType semi-traversable tuple
1 parent 28219e1 commit 5d73e5b

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12971297
);
12981298
}
12991299
}
1300-
StatementKind::AscribeUserType(box (place, projection), variance) => {
1300+
StatementKind::AscribeUserType(box AscribeUserType(place, projection), variance) => {
13011301
let place_ty = place.ty(body, tcx).ty;
13021302
if let Err(terr) = self.relate_type_and_user_type(
13031303
place_ty,

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,10 @@ impl<'tcx> UserTypeProjections {
14771477
}
14781478
}
14791479

1480+
#[derive(Clone, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
1481+
#[derive(TypeFoldable, TypeVisitable)]
1482+
pub struct AscribeUserType<'tcx>(pub Place<'tcx>, pub UserTypeProjection);
1483+
14801484
/// Encodes the effect of a user-supplied type annotation on the
14811485
/// subcomponents of a pattern. The effect is determined by applying the
14821486
/// given list of projections to some underlying base type. Often,
@@ -1493,7 +1497,6 @@ impl<'tcx> UserTypeProjections {
14931497
/// `field[0]` (aka `.0`), indicating that the type of `s` is
14941498
/// determined by finding the type of the `.0` field from `T`.
14951499
#[derive(Clone, Debug, TyEncodable, TyDecodable, Hash, HashStable, PartialEq)]
1496-
#[derive(TypeFoldable, TypeVisitable)]
14971500
pub struct UserTypeProjection {
14981501
pub base: UserTypeAnnotationIndex,
14991502
pub projs: Vec<ProjectionKind>,

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ impl Debug for Statement<'_> {
703703
PlaceMention(ref place) => {
704704
write!(fmt, "PlaceMention({place:?})")
705705
}
706-
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
706+
AscribeUserType(box self::AscribeUserType(ref place, ref c_ty), ref variance) => {
707707
write!(fmt, "AscribeUserType({place:?}, {variance:?}, {c_ty:?})")
708708
}
709709
Coverage(box mir::Coverage { ref kind }) => write!(fmt, "Coverage::{kind:?}"),

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This is in a dedicated file so that changes to this file can be reviewed more carefully.
44
//! The intention is that this file only contains datatype declarations, no code.
55
6-
use super::{BasicBlock, Const, Local, UserTypeProjection};
6+
use super::{AscribeUserType, BasicBlock, Const, Local};
77

88
use crate::mir::coverage::CoverageKind;
99
use crate::traits::Reveal;
@@ -359,7 +359,7 @@ pub enum StatementKind<'tcx> {
359359
/// When executed at runtime this is a nop.
360360
///
361361
/// Disallowed after drop elaboration.
362-
AscribeUserType(Box<(Place<'tcx>, UserTypeProjection)>, ty::Variance),
362+
AscribeUserType(Box<AscribeUserType<'tcx>>, ty::Variance),
363363

364364
/// Carries control-flow-sensitive information injected by `-Cinstrument-coverage`,
365365
/// such as where to generate physical coverage-counter-increments during codegen.

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ macro_rules! make_mir_visitor {
425425
);
426426
}
427427
StatementKind::AscribeUserType(
428-
box (place, user_ty),
428+
box AscribeUserType(place, user_ty),
429429
variance
430430
) => {
431431
self.visit_ascribe_user_ty(place, $(& $mutability)? *variance, user_ty, location);

compiler/rustc_mir_build/src/build/expr/as_place.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
482482
Statement {
483483
source_info,
484484
kind: StatementKind::AscribeUserType(
485-
Box::new((
485+
Box::new(AscribeUserType(
486486
place,
487487
UserTypeProjection { base: annotation_index, projs: vec![] },
488488
)),
@@ -509,7 +509,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
509509
Statement {
510510
source_info,
511511
kind: StatementKind::AscribeUserType(
512-
Box::new((
512+
Box::new(AscribeUserType(
513513
Place::from(temp),
514514
UserTypeProjection { base: annotation_index, projs: vec![] },
515515
)),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
586586
Statement {
587587
source_info: ty_source_info,
588588
kind: StatementKind::AscribeUserType(
589-
Box::new((place, UserTypeProjection { base, projs: Vec::new() })),
589+
Box::new(AscribeUserType(
590+
place,
591+
UserTypeProjection { base, projs: Vec::new() },
592+
)),
590593
// We always use invariant as the variance here. This is because the
591594
// variance field from the ascription refers to the variance to use
592595
// when applying the type to the value being matched, but this
@@ -2149,7 +2152,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
21492152
Statement {
21502153
source_info,
21512154
kind: StatementKind::AscribeUserType(
2152-
Box::new((
2155+
Box::new(AscribeUserType(
21532156
ascription.source,
21542157
UserTypeProjection { base, projs: Vec::new() },
21552158
)),

compiler/rustc_mir_transform/src/remove_zsts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
110110
}
111111
StatementKind::Deinit(box place)
112112
| StatementKind::SetDiscriminant { box place, variant_index: _ }
113-
| StatementKind::AscribeUserType(box (place, _), _)
113+
| StatementKind::AscribeUserType(box AscribeUserType(place, _), _)
114114
| StatementKind::Retag(_, box place)
115115
| StatementKind::PlaceMention(box place)
116116
| StatementKind::FakeRead(box FakeReadCauseAndPlace(_, place)) => Some(place),

0 commit comments

Comments
 (0)