@@ -33,7 +33,7 @@ use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
33
33
use middle:: stability;
34
34
use mir:: { self , Mir , interpret} ;
35
35
use mir:: interpret:: Allocation ;
36
- use ty:: subst:: { Kind , Substs , Subst } ;
36
+ use ty:: subst:: { CanonicalSubsts , Kind , Substs , Subst } ;
37
37
use ty:: ReprOptions ;
38
38
use traits;
39
39
use traits:: { Clause , Clauses , Goal , Goals } ;
@@ -371,6 +371,18 @@ pub struct TypeckTables<'tcx> {
371
371
/// other items.
372
372
node_substs : ItemLocalMap < & ' tcx Substs < ' tcx > > ,
373
373
374
+ /// Stores the substitutions that the user explicit gave (if any)
375
+ /// attached to `id`. These will not include any inferred
376
+ /// values. The canonical form is used to capture things like `_`
377
+ /// or other unspecified values.
378
+ ///
379
+ /// Example:
380
+ ///
381
+ /// If the user wrote `foo.collect::<Vec<_>>()`, then the
382
+ /// canonical substitutions would include only `for<X> { Vec<X>
383
+ /// }`.
384
+ user_substs : ItemLocalMap < CanonicalSubsts < ' tcx > > ,
385
+
374
386
adjustments : ItemLocalMap < Vec < ty:: adjustment:: Adjustment < ' tcx > > > ,
375
387
376
388
/// Stores the actual binding mode for all instances of hir::BindingAnnotation.
@@ -444,6 +456,7 @@ impl<'tcx> TypeckTables<'tcx> {
444
456
user_provided_tys : ItemLocalMap ( ) ,
445
457
node_types : ItemLocalMap ( ) ,
446
458
node_substs : ItemLocalMap ( ) ,
459
+ user_substs : ItemLocalMap ( ) ,
447
460
adjustments : ItemLocalMap ( ) ,
448
461
pat_binding_modes : ItemLocalMap ( ) ,
449
462
pat_adjustments : ItemLocalMap ( ) ,
@@ -561,6 +574,18 @@ impl<'tcx> TypeckTables<'tcx> {
561
574
self . node_substs . get ( & id. local_id ) . cloned ( )
562
575
}
563
576
577
+ pub fn user_substs_mut ( & mut self ) -> LocalTableInContextMut < CanonicalSubsts < ' tcx > > {
578
+ LocalTableInContextMut {
579
+ local_id_root : self . local_id_root ,
580
+ data : & mut self . user_substs
581
+ }
582
+ }
583
+
584
+ pub fn user_substs ( & self , id : hir:: HirId ) -> Option < CanonicalSubsts < ' tcx > > {
585
+ validate_hir_id_for_typeck_tables ( self . local_id_root , id, false ) ;
586
+ self . user_substs . get ( & id. local_id ) . cloned ( )
587
+ }
588
+
564
589
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
565
590
// doesn't provide type parameter substitutions.
566
591
pub fn pat_ty ( & self , pat : & hir:: Pat ) -> Ty < ' tcx > {
@@ -740,6 +765,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
740
765
ref user_provided_tys,
741
766
ref node_types,
742
767
ref node_substs,
768
+ ref user_substs,
743
769
ref adjustments,
744
770
ref pat_binding_modes,
745
771
ref pat_adjustments,
@@ -762,6 +788,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
762
788
user_provided_tys. hash_stable ( hcx, hasher) ;
763
789
node_types. hash_stable ( hcx, hasher) ;
764
790
node_substs. hash_stable ( hcx, hasher) ;
791
+ user_substs. hash_stable ( hcx, hasher) ;
765
792
adjustments. hash_stable ( hcx, hasher) ;
766
793
pat_binding_modes. hash_stable ( hcx, hasher) ;
767
794
pat_adjustments. hash_stable ( hcx, hasher) ;
0 commit comments