@@ -1888,12 +1888,15 @@ pub enum Operand<'tcx> {
18881888 /// This implies that the type of the place must be `Copy`; this is true
18891889 /// by construction during build, but also checked by the MIR type checker.
18901890 Copy ( Place < ' tcx > ) ,
1891+
18911892 /// Move: The value (including old borrows of it) will not be used again.
18921893 ///
18931894 /// Safe for values of all types (modulo future developments towards `?Move`).
18941895 /// Correct usage patterns are enforced by the borrow checker for safe code.
18951896 /// `Copy` may be converted to `Move` to enable "last-use" optimizations.
18961897 Move ( Place < ' tcx > ) ,
1898+
1899+ /// Synthesizes a constant value.
18971900 Constant ( Box < Constant < ' tcx > > ) ,
18981901}
18991902
@@ -1909,6 +1912,9 @@ impl<'tcx> Debug for Operand<'tcx> {
19091912}
19101913
19111914impl < ' 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.
19121918 pub fn function_handle < ' a > (
19131919 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
19141920 def_id : DefId ,
@@ -1919,6 +1925,7 @@ impl<'tcx> Operand<'tcx> {
19191925 Operand :: Constant ( box Constant {
19201926 span,
19211927 ty,
1928+ user_ty : None ,
19221929 literal : ty:: Const :: zero_sized ( tcx, ty) ,
19231930 } )
19241931 }
@@ -2002,7 +2009,7 @@ pub enum AggregateKind<'tcx> {
20022009 /// active field number and is present only for union expressions
20032010 /// -- e.g. for a union expression `SomeUnion { c: .. }`, the
20042011 /// 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 > ) ,
20062013
20072014 Closure ( DefId , ClosureSubsts < ' tcx > ) ,
20082015 Generator ( DefId , GeneratorSubsts < ' tcx > , hir:: GeneratorMovability ) ,
@@ -2128,7 +2135,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
21282135 _ => fmt_tuple ( fmt, places) ,
21292136 } ,
21302137
2131- AggregateKind :: Adt ( adt_def, variant, substs, _) => {
2138+ AggregateKind :: Adt ( adt_def, variant, substs, _user_ty , _) => {
21322139 let variant_def = & adt_def. variants [ variant] ;
21332140
21342141 ppaux:: parameterized ( fmt, substs, variant_def. did , & [ ] ) ?;
@@ -2207,6 +2214,14 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22072214pub struct Constant < ' tcx > {
22082215 pub span : Span ,
22092216 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+
22102225 pub literal : & ' tcx ty:: Const < ' tcx > ,
22112226}
22122227
@@ -2798,8 +2813,14 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
27982813 let kind = box match * * kind {
27992814 AggregateKind :: Array ( ty) => AggregateKind :: Array ( ty. fold_with ( folder) ) ,
28002815 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+ )
28032824 }
28042825 AggregateKind :: Closure ( id, substs) => {
28052826 AggregateKind :: Closure ( id, substs. fold_with ( folder) )
@@ -2831,7 +2852,8 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
28312852 ( match * * kind {
28322853 AggregateKind :: Array ( ty) => ty. visit_with ( visitor) ,
28332854 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) ,
28352857 AggregateKind :: Closure ( _, substs) => substs. visit_with ( visitor) ,
28362858 AggregateKind :: Generator ( _, substs, _) => substs. visit_with ( visitor) ,
28372859 } ) || fields. visit_with ( visitor)
@@ -2902,6 +2924,7 @@ impl<'tcx> TypeFoldable<'tcx> for Constant<'tcx> {
29022924 Constant {
29032925 span : self . span . clone ( ) ,
29042926 ty : self . ty . fold_with ( folder) ,
2927+ user_ty : self . user_ty . fold_with ( folder) ,
29052928 literal : self . literal . fold_with ( folder) ,
29062929 }
29072930 }
0 commit comments