@@ -174,11 +174,6 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
174174 // avoid reporting the same error twice.
175175 pub reported_trait_errors : RefCell < FxHashSet < traits:: TraitErrorKey < ' tcx > > > ,
176176
177- // Sadly, the behavior of projection varies a bit depending on the
178- // stage of compilation. The specifics are given in the
179- // documentation for `Reveal`.
180- projection_mode : Reveal ,
181-
182177 // When an error occurs, we want to avoid reporting "derived"
183178 // errors that are due to this original failure. Normally, we
184179 // handle this with the `err_count_on_creation` count, which
@@ -406,54 +401,54 @@ pub trait InferEnv<'a, 'tcx> {
406401 fn to_parts ( self , tcx : TyCtxt < ' a , ' tcx , ' tcx > )
407402 -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
408403 Option < ty:: TypeckTables < ' tcx > > ,
409- Option < ty:: ParamEnv < ' tcx > > ) ;
404+ ty:: ParamEnv < ' tcx > ) ;
410405}
411406
412- impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for ( ) {
407+ impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for Reveal {
413408 fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
414409 -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
415410 Option < ty:: TypeckTables < ' tcx > > ,
416- Option < ty:: ParamEnv < ' tcx > > ) {
417- ( None , None , None )
411+ ty:: ParamEnv < ' tcx > ) {
412+ ( None , None , ty :: ParamEnv :: empty ( self ) )
418413 }
419414}
420415
421416impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for ty:: ParamEnv < ' tcx > {
422417 fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
423418 -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
424419 Option < ty:: TypeckTables < ' tcx > > ,
425- Option < ty:: ParamEnv < ' tcx > > ) {
426- ( None , None , Some ( self ) )
420+ ty:: ParamEnv < ' tcx > ) {
421+ ( None , None , self )
427422 }
428423}
429424
430425impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for ( & ' a ty:: TypeckTables < ' tcx > , ty:: ParamEnv < ' tcx > ) {
431426 fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
432427 -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
433428 Option < ty:: TypeckTables < ' tcx > > ,
434- Option < ty:: ParamEnv < ' tcx > > ) {
435- ( Some ( self . 0 ) , None , Some ( self . 1 ) )
429+ ty:: ParamEnv < ' tcx > ) {
430+ ( Some ( self . 0 ) , None , self . 1 )
436431 }
437432}
438433
439434impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for ( ty:: TypeckTables < ' tcx > , ty:: ParamEnv < ' tcx > ) {
440435 fn to_parts ( self , _: TyCtxt < ' a , ' tcx , ' tcx > )
441436 -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
442437 Option < ty:: TypeckTables < ' tcx > > ,
443- Option < ty:: ParamEnv < ' tcx > > ) {
444- ( None , Some ( self . 0 ) , Some ( self . 1 ) )
438+ ty:: ParamEnv < ' tcx > ) {
439+ ( None , Some ( self . 0 ) , self . 1 )
445440 }
446441}
447442
448443impl < ' a , ' tcx > InferEnv < ' a , ' tcx > for hir:: BodyId {
449444 fn to_parts ( self , tcx : TyCtxt < ' a , ' tcx , ' tcx > )
450445 -> ( Option < & ' a ty:: TypeckTables < ' tcx > > ,
451446 Option < ty:: TypeckTables < ' tcx > > ,
452- Option < ty:: ParamEnv < ' tcx > > ) {
447+ ty:: ParamEnv < ' tcx > ) {
453448 let def_id = tcx. hir . body_owner_def_id ( self ) ;
454449 ( Some ( tcx. typeck_tables_of ( def_id) ) ,
455450 None ,
456- Some ( tcx. param_env ( def_id) ) )
451+ tcx. param_env ( def_id) )
457452 }
458453}
459454
@@ -465,23 +460,18 @@ pub struct InferCtxtBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
465460 arena : DroplessArena ,
466461 fresh_tables : Option < RefCell < ty:: TypeckTables < ' tcx > > > ,
467462 tables : Option < & ' a ty:: TypeckTables < ' gcx > > ,
468- param_env : Option < ty:: ParamEnv < ' gcx > > ,
469- projection_mode : Reveal ,
463+ param_env : ty:: ParamEnv < ' gcx > ,
470464}
471465
472466impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' gcx > {
473- pub fn infer_ctxt < E : InferEnv < ' a , ' gcx > > ( self ,
474- env : E ,
475- projection_mode : Reveal )
476- -> InferCtxtBuilder < ' a , ' gcx , ' tcx > {
467+ pub fn infer_ctxt < E : InferEnv < ' a , ' gcx > > ( self , env : E ) -> InferCtxtBuilder < ' a , ' gcx , ' tcx > {
477468 let ( tables, fresh_tables, param_env) = env. to_parts ( self ) ;
478469 InferCtxtBuilder {
479470 global_tcx : self ,
480471 arena : DroplessArena :: new ( ) ,
481472 fresh_tables : fresh_tables. map ( RefCell :: new) ,
482473 tables : tables,
483474 param_env : param_env,
484- projection_mode : projection_mode,
485475 }
486476 }
487477
@@ -498,12 +488,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
498488 int_unification_table : RefCell :: new ( UnificationTable :: new ( ) ) ,
499489 float_unification_table : RefCell :: new ( UnificationTable :: new ( ) ) ,
500490 region_vars : RegionVarBindings :: new ( self ) ,
501- param_env : param_env. unwrap ( ) ,
491+ param_env : param_env,
502492 selection_cache : traits:: SelectionCache :: new ( ) ,
503493 evaluation_cache : traits:: EvaluationCache :: new ( ) ,
504494 projection_cache : RefCell :: new ( traits:: ProjectionCache :: new ( ) ) ,
505495 reported_trait_errors : RefCell :: new ( FxHashSet ( ) ) ,
506- projection_mode : Reveal :: UserFacing ,
507496 tainted_by_errors_flag : Cell :: new ( false ) ,
508497 err_count_on_creation : self . sess . err_count ( ) ,
509498 in_snapshot : Cell :: new ( false ) ,
@@ -520,13 +509,11 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
520509 ref arena,
521510 ref fresh_tables,
522511 tables,
523- ref mut param_env,
524- projection_mode,
512+ param_env,
525513 } = * self ;
526514 let tables = tables. map ( InferTables :: Interned ) . unwrap_or_else ( || {
527515 fresh_tables. as_ref ( ) . map_or ( InferTables :: Missing , InferTables :: InProgress )
528516 } ) ;
529- let param_env = param_env. take ( ) . unwrap_or_else ( || ty:: ParamEnv :: empty ( ) ) ;
530517 global_tcx. enter_local ( arena, |tcx| f ( InferCtxt {
531518 tcx : tcx,
532519 tables : tables,
@@ -539,7 +526,6 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
539526 selection_cache : traits:: SelectionCache :: new ( ) ,
540527 evaluation_cache : traits:: EvaluationCache :: new ( ) ,
541528 reported_trait_errors : RefCell :: new ( FxHashSet ( ) ) ,
542- projection_mode : projection_mode,
543529 tainted_by_errors_flag : Cell :: new ( false ) ,
544530 err_count_on_creation : tcx. sess . err_count ( ) ,
545531 in_snapshot : Cell :: new ( false ) ,
@@ -643,11 +629,15 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
643629 return value;
644630 }
645631
646- self . infer_ctxt ( ( ) , Reveal :: All ) . enter ( |infcx| {
632+ self . infer_ctxt ( Reveal :: All ) . enter ( |infcx| {
647633 value. trans_normalize ( & infcx)
648634 } )
649635 }
650636
637+ /// Does a best-effort to normalize any associated types in
638+ /// `value`; this includes revealing specializable types, so this
639+ /// should be not be used during type-checking, but only during
640+ /// optimization and code generation.
651641 pub fn normalize_associated_type_in_env < T > (
652642 self , value : & T , env : ty:: ParamEnv < ' tcx >
653643 ) -> T
@@ -661,7 +651,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
661651 return value;
662652 }
663653
664- self . infer_ctxt ( env, Reveal :: All ) . enter ( |infcx| {
654+ self . infer_ctxt ( env. reveal_all ( ) ) . enter ( |infcx| {
665655 value. trans_normalize ( & infcx)
666656 } )
667657 }
@@ -728,10 +718,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
728718 }
729719 }
730720
731- pub fn projection_mode ( & self ) -> Reveal {
732- self . projection_mode
733- }
734-
735721 pub fn is_in_snapshot ( & self ) -> bool {
736722 self . in_snapshot . get ( )
737723 }
0 commit comments