@@ -1040,6 +1040,17 @@ impl<'tcx> ParamEnv<'tcx> {
10401040 pub fn and < T : TypeVisitable < TyCtxt < ' tcx > > > ( self , value : T ) -> ParamEnvAnd < ' tcx , T > {
10411041 ParamEnvAnd { param_env : self , value }
10421042 }
1043+
1044+ /// Eagerly reveal all opaque types in the `param_env`.
1045+ pub fn with_normalized ( self , tcx : TyCtxt < ' tcx > ) -> ParamEnv < ' tcx > {
1046+ // No need to reveal opaques with the new solver enabled,
1047+ // since we have lazy norm.
1048+ if tcx. next_trait_solver_globally ( ) {
1049+ self
1050+ } else {
1051+ ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( self . caller_bounds ) )
1052+ }
1053+ }
10431054}
10441055
10451056#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable , TypeVisitable ) ]
@@ -1102,31 +1113,44 @@ impl<'tcx> TypingEnv<'tcx> {
11021113 }
11031114
11041115 pub fn post_analysis ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryKey < DefId > ) -> TypingEnv < ' tcx > {
1105- let def_id = def_id. into_query_key ( ) ;
1106- tcx. typing_env_normalized_for_post_analysis ( def_id)
1116+ TypingEnv :: new ( tcx. param_env_normalized_for_post_analysis ( def_id) , TypingMode :: PostAnalysis )
1117+ }
1118+
1119+ pub fn codegen ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryKey < DefId > ) -> TypingEnv < ' tcx > {
1120+ TypingEnv :: new ( tcx. param_env_normalized_for_post_analysis ( def_id) , TypingMode :: Codegen )
11071121 }
11081122
11091123 /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
11101124 /// in the `param_env`.
11111125 pub fn with_post_analysis_normalized ( self , tcx : TyCtxt < ' tcx > ) -> TypingEnv < ' tcx > {
11121126 let TypingEnv { typing_mode, param_env } = self ;
1127+ match typing_mode. 0 . assert_not_erased ( ) {
1128+ TypingMode :: Coherence
1129+ | TypingMode :: Analysis { .. }
1130+ | TypingMode :: Borrowck { .. }
1131+ | TypingMode :: PostBorrowckAnalysis { .. } => { }
1132+ TypingMode :: PostAnalysis | TypingMode :: Codegen => return self ,
1133+ }
11131134
1114- // No need to reveal opaques with the new solver enabled,
1115- // since we have lazy norm.
1116- let param_env = if tcx. next_trait_solver_globally ( ) {
1117- param_env
1118- } else {
1119- match typing_mode. 0 . assert_not_erased ( ) {
1120- TypingMode :: Coherence
1121- | TypingMode :: Analysis { .. }
1122- | TypingMode :: Borrowck { .. }
1123- | TypingMode :: PostBorrowckAnalysis { .. } => { }
1124- TypingMode :: PostAnalysis | TypingMode :: Codegen => return self ,
1125- }
1135+ let param_env = param_env. with_normalized ( tcx) ;
1136+ TypingEnv :: new ( param_env, TypingMode :: PostAnalysis )
1137+ }
11261138
1127- ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( param_env. caller_bounds ( ) ) )
1128- } ;
1129- TypingEnv { typing_mode : TypingModeEqWrapper ( TypingMode :: PostAnalysis ) , param_env }
1139+ /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
1140+ /// in the `param_env`.
1141+ pub fn with_codegen_normalized ( self , tcx : TyCtxt < ' tcx > ) -> TypingEnv < ' tcx > {
1142+ let TypingEnv { typing_mode, param_env } = self ;
1143+ match typing_mode. 0 . assert_not_erased ( ) {
1144+ TypingMode :: Coherence
1145+ | TypingMode :: Analysis { .. }
1146+ | TypingMode :: Borrowck { .. }
1147+ | TypingMode :: PostBorrowckAnalysis { .. }
1148+ | TypingMode :: PostAnalysis => { }
1149+ TypingMode :: Codegen => return self ,
1150+ }
1151+
1152+ let param_env = param_env. with_normalized ( tcx) ;
1153+ TypingEnv :: new ( param_env, TypingMode :: Codegen )
11301154 }
11311155
11321156 /// Combine this typing environment with the given `value` to be used by
0 commit comments