@@ -1888,12 +1888,15 @@ pub enum Operand<'tcx> {
1888
1888
/// This implies that the type of the place must be `Copy`; this is true
1889
1889
/// by construction during build, but also checked by the MIR type checker.
1890
1890
Copy ( Place < ' tcx > ) ,
1891
+
1891
1892
/// Move: The value (including old borrows of it) will not be used again.
1892
1893
///
1893
1894
/// Safe for values of all types (modulo future developments towards `?Move`).
1894
1895
/// Correct usage patterns are enforced by the borrow checker for safe code.
1895
1896
/// `Copy` may be converted to `Move` to enable "last-use" optimizations.
1896
1897
Move ( Place < ' tcx > ) ,
1898
+
1899
+ /// Synthesizes a constant value.
1897
1900
Constant ( Box < Constant < ' tcx > > ) ,
1898
1901
}
1899
1902
@@ -1909,6 +1912,9 @@ impl<'tcx> Debug for Operand<'tcx> {
1909
1912
}
1910
1913
1911
1914
impl < ' tcx > Operand < ' tcx > {
1915
+ /// Convenience helper to make a constant that refers to the fn
1916
+ /// with given def-id and substs. Since this is used to synthesize
1917
+ /// MIR, assumes `user_ty` is None.
1912
1918
pub fn function_handle < ' a > (
1913
1919
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1914
1920
def_id : DefId ,
@@ -1919,6 +1925,7 @@ impl<'tcx> Operand<'tcx> {
1919
1925
Operand :: Constant ( box Constant {
1920
1926
span,
1921
1927
ty,
1928
+ user_ty : None ,
1922
1929
literal : ty:: Const :: zero_sized ( tcx, ty) ,
1923
1930
} )
1924
1931
}
@@ -2002,7 +2009,7 @@ pub enum AggregateKind<'tcx> {
2002
2009
/// active field number and is present only for union expressions
2003
2010
/// -- e.g. for a union expression `SomeUnion { c: .. }`, the
2004
2011
/// active field index would identity the field `c`
2005
- Adt ( & ' tcx AdtDef , usize , & ' tcx Substs < ' tcx > , Option < usize > ) ,
2012
+ Adt ( & ' tcx AdtDef , usize , & ' tcx Substs < ' tcx > , Option < CanonicalTy < ' tcx > > , Option < usize > ) ,
2006
2013
2007
2014
Closure ( DefId , ClosureSubsts < ' tcx > ) ,
2008
2015
Generator ( DefId , GeneratorSubsts < ' tcx > , hir:: GeneratorMovability ) ,
@@ -2128,7 +2135,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
2128
2135
_ => fmt_tuple ( fmt, places) ,
2129
2136
} ,
2130
2137
2131
- AggregateKind :: Adt ( adt_def, variant, substs, _) => {
2138
+ AggregateKind :: Adt ( adt_def, variant, substs, _user_ty , _) => {
2132
2139
let variant_def = & adt_def. variants [ variant] ;
2133
2140
2134
2141
ppaux:: parameterized ( fmt, substs, variant_def. did , & [ ] ) ?;
@@ -2207,6 +2214,14 @@ impl<'tcx> Debug for Rvalue<'tcx> {
2207
2214
pub struct Constant < ' tcx > {
2208
2215
pub span : Span ,
2209
2216
pub ty : Ty < ' tcx > ,
2217
+
2218
+ /// Optional user-given type: for something like
2219
+ /// `collect::<Vec<_>>`, this would be present and would
2220
+ /// indicate that `Vec<_>` was explicitly specified.
2221
+ ///
2222
+ /// Needed for NLL to impose user-given type constraints.
2223
+ pub user_ty : Option < CanonicalTy < ' tcx > > ,
2224
+
2210
2225
pub literal : & ' tcx ty:: Const < ' tcx > ,
2211
2226
}
2212
2227
@@ -2798,8 +2813,14 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
2798
2813
let kind = box match * * kind {
2799
2814
AggregateKind :: Array ( ty) => AggregateKind :: Array ( ty. fold_with ( folder) ) ,
2800
2815
AggregateKind :: Tuple => AggregateKind :: Tuple ,
2801
- AggregateKind :: Adt ( def, v, substs, n) => {
2802
- AggregateKind :: Adt ( def, v, substs. fold_with ( folder) , n)
2816
+ AggregateKind :: Adt ( def, v, substs, user_ty, n) => {
2817
+ AggregateKind :: Adt (
2818
+ def,
2819
+ v,
2820
+ substs. fold_with ( folder) ,
2821
+ user_ty. fold_with ( folder) ,
2822
+ n,
2823
+ )
2803
2824
}
2804
2825
AggregateKind :: Closure ( id, substs) => {
2805
2826
AggregateKind :: Closure ( id, substs. fold_with ( folder) )
@@ -2831,7 +2852,8 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
2831
2852
( match * * kind {
2832
2853
AggregateKind :: Array ( ty) => ty. visit_with ( visitor) ,
2833
2854
AggregateKind :: Tuple => false ,
2834
- AggregateKind :: Adt ( _, _, substs, _) => substs. visit_with ( visitor) ,
2855
+ AggregateKind :: Adt ( _, _, substs, user_ty, _) =>
2856
+ substs. visit_with ( visitor) || user_ty. visit_with ( visitor) ,
2835
2857
AggregateKind :: Closure ( _, substs) => substs. visit_with ( visitor) ,
2836
2858
AggregateKind :: Generator ( _, substs, _) => substs. visit_with ( visitor) ,
2837
2859
} ) || fields. visit_with ( visitor)
@@ -2902,6 +2924,7 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
2902
2924
Constant {
2903
2925
span : self . span . clone ( ) ,
2904
2926
ty : self . ty . fold_with ( folder) ,
2927
+ user_ty : self . user_ty . fold_with ( folder) ,
2905
2928
literal : self . literal . fold_with ( folder) ,
2906
2929
}
2907
2930
}
0 commit comments