@@ -21,7 +21,6 @@ use hir::def_id::DefId;
2121use middle:: free_region:: RegionRelations ;
2222use middle:: region;
2323use middle:: lang_items;
24- use mir:: tcx:: PlaceTy ;
2524use ty:: subst:: Substs ;
2625use ty:: { TyVid , IntVid , FloatVid } ;
2726use ty:: { self , Ty , TyCtxt } ;
@@ -35,7 +34,7 @@ use std::collections::BTreeMap;
3534use std:: fmt;
3635use syntax:: ast;
3736use errors:: DiagnosticBuilder ;
38- use syntax_pos:: { self , Span , DUMMY_SP } ;
37+ use syntax_pos:: { self , Span } ;
3938use util:: nodemap:: FxHashMap ;
4039use arena:: DroplessArena ;
4140
@@ -493,140 +492,7 @@ pub struct CombinedSnapshot<'a, 'tcx:'a> {
493492 _in_progress_tables : Option < Ref < ' a , ty:: TypeckTables < ' tcx > > > ,
494493}
495494
496- /// Helper trait for shortening the lifetimes inside a
497- /// value for post-type-checking normalization.
498- ///
499- /// This trait offers a normalization method where the inputs and
500- /// outputs both have the `'gcx` lifetime; the implementations
501- /// internally create inference contexts and/or lift as needed.
502- pub trait TransNormalize < ' gcx > : TypeFoldable < ' gcx > {
503- fn trans_normalize < ' a , ' tcx > ( & self ,
504- infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
505- param_env : ty:: ParamEnv < ' tcx > )
506- -> Self ;
507- }
508-
509- macro_rules! items { ( $( $item: item) +) => ( $( $item) +) }
510- macro_rules! impl_trans_normalize {
511- ( $lt_gcx: tt, $( $ty: ty) ,+) => {
512- items!( $( impl <$lt_gcx> TransNormalize <$lt_gcx> for $ty {
513- fn trans_normalize<' a, ' tcx>( & self ,
514- infcx: & InferCtxt <' a, $lt_gcx, ' tcx>,
515- param_env: ty:: ParamEnv <' tcx>)
516- -> Self {
517- infcx. normalize_projections_in( param_env, self )
518- }
519- } ) +) ;
520- }
521- }
522-
523- impl_trans_normalize ! ( ' gcx,
524- Ty <' gcx>,
525- & ' gcx ty:: Const <' gcx>,
526- & ' gcx Substs <' gcx>,
527- ty:: FnSig <' gcx>,
528- ty:: PolyFnSig <' gcx>,
529- ty:: ClosureSubsts <' gcx>,
530- ty:: PolyTraitRef <' gcx>,
531- ty:: ExistentialTraitRef <' gcx>
532- ) ;
533-
534- impl < ' gcx > TransNormalize < ' gcx > for PlaceTy < ' gcx > {
535- fn trans_normalize < ' a , ' tcx > ( & self ,
536- infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
537- param_env : ty:: ParamEnv < ' tcx > )
538- -> Self {
539- match * self {
540- PlaceTy :: Ty { ty } => PlaceTy :: Ty { ty : ty. trans_normalize ( infcx, param_env) } ,
541- PlaceTy :: Downcast { adt_def, substs, variant_index } => {
542- PlaceTy :: Downcast {
543- adt_def,
544- substs : substs. trans_normalize ( infcx, param_env) ,
545- variant_index,
546- }
547- }
548- }
549- }
550- }
551-
552- // NOTE: Callable from trans only!
553- impl < ' a , ' tcx > TyCtxt < ' a , ' tcx , ' tcx > {
554- /// Currently, higher-ranked type bounds inhibit normalization. Therefore,
555- /// each time we erase them in translation, we need to normalize
556- /// the contents.
557- pub fn erase_late_bound_regions_and_normalize < T > ( self , value : & ty:: Binder < T > )
558- -> T
559- where T : TransNormalize < ' tcx >
560- {
561- assert ! ( !value. needs_subst( ) ) ;
562- let value = self . erase_late_bound_regions ( value) ;
563- self . fully_normalize_associated_types_in ( & value)
564- }
565-
566- /// Fully normalizes any associated types in `value`, using an
567- /// empty environment and `Reveal::All` mode (therefore, suitable
568- /// only for monomorphized code during trans, basically).
569- pub fn fully_normalize_associated_types_in < T > ( self , value : & T ) -> T
570- where T : TransNormalize < ' tcx >
571- {
572- debug ! ( "fully_normalize_associated_types_in(t={:?})" , value) ;
573-
574- let param_env = ty:: ParamEnv :: reveal_all ( ) ;
575- let value = self . erase_regions ( value) ;
576-
577- if !value. has_projections ( ) {
578- return value;
579- }
580-
581- self . infer_ctxt ( ) . enter ( |infcx| {
582- value. trans_normalize ( & infcx, param_env)
583- } )
584- }
585-
586- /// Does a best-effort to normalize any associated types in
587- /// `value`; this includes revealing specializable types, so this
588- /// should be not be used during type-checking, but only during
589- /// optimization and code generation.
590- pub fn normalize_associated_type_in_env < T > (
591- self , value : & T , env : ty:: ParamEnv < ' tcx >
592- ) -> T
593- where T : TransNormalize < ' tcx >
594- {
595- debug ! ( "normalize_associated_type_in_env(t={:?})" , value) ;
596-
597- let value = self . erase_regions ( value) ;
598-
599- if !value. has_projections ( ) {
600- return value;
601- }
602-
603- self . infer_ctxt ( ) . enter ( |infcx| {
604- value. trans_normalize ( & infcx, env. with_reveal_all ( ) )
605- } )
606- }
607- }
608-
609495impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
610- fn normalize_projections_in < T > ( & self , param_env : ty:: ParamEnv < ' tcx > , value : & T ) -> T :: Lifted
611- where T : TypeFoldable < ' tcx > + ty:: Lift < ' gcx >
612- {
613- let mut selcx = traits:: SelectionContext :: new ( self ) ;
614- let cause = traits:: ObligationCause :: dummy ( ) ;
615- let traits:: Normalized { value : result, obligations } =
616- traits:: normalize ( & mut selcx, param_env, cause, value) ;
617-
618- debug ! ( "normalize_projections_in: result={:?} obligations={:?}" ,
619- result, obligations) ;
620-
621- let mut fulfill_cx = traits:: FulfillmentContext :: new ( ) ;
622-
623- for obligation in obligations {
624- fulfill_cx. register_predicate_obligation ( self , obligation) ;
625- }
626-
627- self . drain_fulfillment_cx_or_panic ( DUMMY_SP , & mut fulfill_cx, & result)
628- }
629-
630496 /// Finishes processes any obligations that remain in the
631497 /// fulfillment context, and then returns the result with all type
632498 /// variables removed and regions erased. Because this is intended
0 commit comments