@@ -25,7 +25,7 @@ use std::slice;
25
25
use std:: vec:: IntoIter ;
26
26
use std:: { iter, mem, option, u32} ;
27
27
use syntax:: ast:: { self , Name } ;
28
- use syntax:: symbol:: InternedString ;
28
+ use syntax:: symbol:: { InternedString , Symbol } ;
29
29
use syntax_pos:: { Span , DUMMY_SP } ;
30
30
use crate :: ty:: fold:: { TypeFoldable , TypeFolder , TypeVisitor } ;
31
31
use crate :: ty:: subst:: { Subst , SubstsRef } ;
@@ -772,7 +772,7 @@ pub struct LocalDecl<'tcx> {
772
772
/// e.g., via `let x: T`, then we carry that type here. The MIR
773
773
/// borrow checker needs this information since it can affect
774
774
/// region inference.
775
- pub user_ty : UserTypeProjections < ' tcx > ,
775
+ pub user_ty : UserTypeProjections ,
776
776
777
777
/// Name of the local, used in debuginfo and pretty-printing.
778
778
///
@@ -1805,7 +1805,7 @@ pub enum StatementKind<'tcx> {
1805
1805
/// - `Contravariant` -- requires that `T_y :> T`
1806
1806
/// - `Invariant` -- requires that `T_y == T`
1807
1807
/// - `Bivariant` -- no effect
1808
- AscribeUserType ( Place < ' tcx > , ty:: Variance , Box < UserTypeProjection < ' tcx > > ) ,
1808
+ AscribeUserType ( Place < ' tcx > , ty:: Variance , Box < UserTypeProjection > ) ,
1809
1809
1810
1810
/// No-op. Useful for deleting instructions without affecting statement indices.
1811
1811
Nop ,
@@ -1939,14 +1939,14 @@ impl_stable_hash_for!(struct Static<'tcx> {
1939
1939
/// `PlaceProjection` etc below.
1940
1940
#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ,
1941
1941
Hash , RustcEncodable , RustcDecodable , HashStable ) ]
1942
- pub struct Projection < ' tcx , B , V , T > {
1942
+ pub struct Projection < B , V , T > {
1943
1943
pub base : B ,
1944
- pub elem : ProjectionElem < ' tcx , V , T > ,
1944
+ pub elem : ProjectionElem < V , T > ,
1945
1945
}
1946
1946
1947
1947
#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ,
1948
1948
Hash , RustcEncodable , RustcDecodable , HashStable ) ]
1949
- pub enum ProjectionElem < ' tcx , V , T > {
1949
+ pub enum ProjectionElem < V , T > {
1950
1950
Deref ,
1951
1951
Field ( Field , T ) ,
1952
1952
Index ( V ) ,
@@ -1980,16 +1980,18 @@ pub enum ProjectionElem<'tcx, V, T> {
1980
1980
/// "Downcast" to a variant of an ADT. Currently, we only introduce
1981
1981
/// this for ADTs with more than one variant. It may be better to
1982
1982
/// just introduce it always, or always for enums.
1983
- Downcast ( & ' tcx AdtDef , VariantIdx ) ,
1983
+ ///
1984
+ /// The included Symbol is the name of the variant, used for printing MIR.
1985
+ Downcast ( Option < Symbol > , VariantIdx ) ,
1984
1986
}
1985
1987
1986
1988
/// Alias for projections as they appear in places, where the base is a place
1987
1989
/// and the index is a local.
1988
- pub type PlaceProjection < ' tcx > = Projection < ' tcx , Place < ' tcx > , Local , Ty < ' tcx > > ;
1990
+ pub type PlaceProjection < ' tcx > = Projection < Place < ' tcx > , Local , Ty < ' tcx > > ;
1989
1991
1990
1992
/// Alias for projections as they appear in places, where the base is a place
1991
1993
/// and the index is a local.
1992
- pub type PlaceElem < ' tcx > = ProjectionElem < ' tcx , Local , Ty < ' tcx > > ;
1994
+ pub type PlaceElem < ' tcx > = ProjectionElem < Local , Ty < ' tcx > > ;
1993
1995
1994
1996
// at least on 64 bit systems, `PlaceElem` should not be larger than two pointers
1995
1997
static_assert ! ( PROJECTION_ELEM_IS_2_PTRS_LARGE :
@@ -1998,7 +2000,7 @@ static_assert!(PROJECTION_ELEM_IS_2_PTRS_LARGE:
1998
2000
1999
2001
/// Alias for projections as they appear in `UserTypeProjection`, where we
2000
2002
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
2001
- pub type ProjectionKind < ' tcx > = ProjectionElem < ' tcx , ( ) , ( ) > ;
2003
+ pub type ProjectionKind = ProjectionElem < ( ) , ( ) > ;
2002
2004
2003
2005
newtype_index ! {
2004
2006
pub struct Field {
@@ -2019,7 +2021,9 @@ impl<'tcx> Place<'tcx> {
2019
2021
}
2020
2022
2021
2023
pub fn downcast ( self , adt_def : & ' tcx AdtDef , variant_index : VariantIdx ) -> Place < ' tcx > {
2022
- self . elem ( ProjectionElem :: Downcast ( adt_def, variant_index) )
2024
+ self . elem ( ProjectionElem :: Downcast (
2025
+ Some ( adt_def. variants [ variant_index] . ident . name ) ,
2026
+ variant_index) )
2023
2027
}
2024
2028
2025
2029
pub fn index ( self , index : Local ) -> Place < ' tcx > {
@@ -2080,8 +2084,11 @@ impl<'tcx> Debug for Place<'tcx> {
2080
2084
)
2081
2085
} ,
2082
2086
Projection ( ref data) => match data. elem {
2083
- ProjectionElem :: Downcast ( ref adt_def, index) => {
2084
- write ! ( fmt, "({:?} as {})" , data. base, adt_def. variants[ index] . ident)
2087
+ ProjectionElem :: Downcast ( Some ( name) , _index) => {
2088
+ write ! ( fmt, "({:?} as {})" , data. base, name)
2089
+ }
2090
+ ProjectionElem :: Downcast ( None , index) => {
2091
+ write ! ( fmt, "({:?} as variant#{:?})" , data. base, index)
2085
2092
}
2086
2093
ProjectionElem :: Deref => write ! ( fmt, "(*{:?})" , data. base) ,
2087
2094
ProjectionElem :: Field ( field, ty) => {
@@ -2542,36 +2549,36 @@ pub struct Constant<'tcx> {
2542
2549
/// inferred region `'1`). The second will lead to the constraint `w:
2543
2550
/// &'static str`.
2544
2551
#[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , HashStable ) ]
2545
- pub struct UserTypeProjections < ' tcx > {
2546
- pub ( crate ) contents : Vec < ( UserTypeProjection < ' tcx > , Span ) > ,
2552
+ pub struct UserTypeProjections {
2553
+ pub ( crate ) contents : Vec < ( UserTypeProjection , Span ) > ,
2547
2554
}
2548
2555
2549
2556
BraceStructTypeFoldableImpl ! {
2550
- impl <' tcx> TypeFoldable <' tcx> for UserTypeProjections < ' tcx> {
2557
+ impl <' tcx> TypeFoldable <' tcx> for UserTypeProjections {
2551
2558
contents
2552
2559
}
2553
2560
}
2554
2561
2555
- impl < ' tcx > UserTypeProjections < ' tcx > {
2562
+ impl < ' tcx > UserTypeProjections {
2556
2563
pub fn none ( ) -> Self {
2557
2564
UserTypeProjections { contents : vec ! [ ] }
2558
2565
}
2559
2566
2560
- pub fn from_projections ( projs : impl Iterator < Item =( UserTypeProjection < ' tcx > , Span ) > ) -> Self {
2567
+ pub fn from_projections ( projs : impl Iterator < Item =( UserTypeProjection , Span ) > ) -> Self {
2561
2568
UserTypeProjections { contents : projs. collect ( ) }
2562
2569
}
2563
2570
2564
- pub fn projections_and_spans ( & self ) -> impl Iterator < Item =& ( UserTypeProjection < ' tcx > , Span ) > {
2571
+ pub fn projections_and_spans ( & self ) -> impl Iterator < Item =& ( UserTypeProjection , Span ) > {
2565
2572
self . contents . iter ( )
2566
2573
}
2567
2574
2568
- pub fn projections ( & self ) -> impl Iterator < Item =& UserTypeProjection < ' tcx > > {
2575
+ pub fn projections ( & self ) -> impl Iterator < Item =& UserTypeProjection > {
2569
2576
self . contents . iter ( ) . map ( |& ( ref user_type, _span) | user_type)
2570
2577
}
2571
2578
2572
2579
pub fn push_projection (
2573
2580
mut self ,
2574
- user_ty : & UserTypeProjection < ' tcx > ,
2581
+ user_ty : & UserTypeProjection ,
2575
2582
span : Span ,
2576
2583
) -> Self {
2577
2584
self . contents . push ( ( user_ty. clone ( ) , span) ) ;
@@ -2580,7 +2587,7 @@ impl<'tcx> UserTypeProjections<'tcx> {
2580
2587
2581
2588
fn map_projections (
2582
2589
mut self ,
2583
- mut f : impl FnMut ( UserTypeProjection < ' tcx > ) -> UserTypeProjection < ' tcx >
2590
+ mut f : impl FnMut ( UserTypeProjection ) -> UserTypeProjection
2584
2591
) -> Self {
2585
2592
self . contents = self . contents . drain ( ..) . map ( |( proj, span) | ( f ( proj) , span) ) . collect ( ) ;
2586
2593
self
@@ -2628,14 +2635,14 @@ impl<'tcx> UserTypeProjections<'tcx> {
2628
2635
/// `field[0]` (aka `.0`), indicating that the type of `s` is
2629
2636
/// determined by finding the type of the `.0` field from `T`.
2630
2637
#[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , HashStable ) ]
2631
- pub struct UserTypeProjection < ' tcx > {
2638
+ pub struct UserTypeProjection {
2632
2639
pub base : UserTypeAnnotationIndex ,
2633
- pub projs : Vec < ProjectionElem < ' tcx , ( ) , ( ) > > ,
2640
+ pub projs : Vec < ProjectionElem < ( ) , ( ) > > ,
2634
2641
}
2635
2642
2636
- impl < ' tcx > Copy for ProjectionKind < ' tcx > { }
2643
+ impl Copy for ProjectionKind { }
2637
2644
2638
- impl < ' tcx > UserTypeProjection < ' tcx > {
2645
+ impl UserTypeProjection {
2639
2646
pub ( crate ) fn index ( mut self ) -> Self {
2640
2647
self . projs . push ( ProjectionElem :: Index ( ( ) ) ) ;
2641
2648
self
@@ -2662,15 +2669,17 @@ impl<'tcx> UserTypeProjection<'tcx> {
2662
2669
variant_index : VariantIdx ,
2663
2670
field : Field ,
2664
2671
) -> Self {
2665
- self . projs . push ( ProjectionElem :: Downcast ( adt_def, variant_index) ) ;
2672
+ self . projs . push ( ProjectionElem :: Downcast (
2673
+ Some ( adt_def. variants [ variant_index] . ident . name ) ,
2674
+ variant_index) ) ;
2666
2675
self . projs . push ( ProjectionElem :: Field ( field, ( ) ) ) ;
2667
2676
self
2668
2677
}
2669
2678
}
2670
2679
2671
- CloneTypeFoldableAndLiftImpls ! { ProjectionKind < ' tcx> , }
2680
+ CloneTypeFoldableAndLiftImpls ! { ProjectionKind , }
2672
2681
2673
- impl < ' tcx > TypeFoldable < ' tcx > for UserTypeProjection < ' tcx > {
2682
+ impl < ' tcx > TypeFoldable < ' tcx > for UserTypeProjection {
2674
2683
fn super_fold_with < ' gcx : ' tcx , F : TypeFolder < ' gcx , ' tcx > > ( & self , folder : & mut F ) -> Self {
2675
2684
use crate :: mir:: ProjectionElem :: * ;
2676
2685
@@ -3428,7 +3437,7 @@ impl<'tcx> TypeFoldable<'tcx> for Operand<'tcx> {
3428
3437
}
3429
3438
}
3430
3439
3431
- impl < ' tcx , B , V , T > TypeFoldable < ' tcx > for Projection < ' tcx , B , V , T >
3440
+ impl < ' tcx , B , V , T > TypeFoldable < ' tcx > for Projection < B , V , T >
3432
3441
where
3433
3442
B : TypeFoldable < ' tcx > ,
3434
3443
V : TypeFoldable < ' tcx > ,
0 commit comments