@@ -1003,6 +1003,17 @@ impl<'tcx> ParamEnv<'tcx> {
10031003 pub fn and < T : TypeVisitable < TyCtxt < ' tcx > > > ( self , value : T ) -> ParamEnvAnd < ' tcx , T > {
10041004 ParamEnvAnd { param_env : self , value }
10051005 }
1006+
1007+ /// Eagerly reveal all opaque types in the `param_env`.
1008+ pub fn with_normalized ( self , tcx : TyCtxt < ' tcx > ) -> ParamEnv < ' tcx > {
1009+ // No need to reveal opaques with the new solver enabled,
1010+ // since we have lazy norm.
1011+ if tcx. next_trait_solver_globally ( ) {
1012+ self
1013+ } else {
1014+ ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( self . caller_bounds ) )
1015+ }
1016+ }
10061017}
10071018
10081019#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable , TypeVisitable ) ]
@@ -1056,7 +1067,17 @@ impl<'tcx> TypingEnv<'tcx> {
10561067 }
10571068
10581069 pub fn post_analysis ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryParam < DefId > ) -> TypingEnv < ' tcx > {
1059- tcx. typing_env_normalized_for_post_analysis ( def_id)
1070+ TypingEnv {
1071+ typing_mode : TypingMode :: PostAnalysis ,
1072+ param_env : tcx. param_env_normalized_for_post_analysis ( def_id) ,
1073+ }
1074+ }
1075+
1076+ pub fn codegen ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryParam < DefId > ) -> TypingEnv < ' tcx > {
1077+ TypingEnv {
1078+ typing_mode : TypingMode :: Codegen ,
1079+ param_env : tcx. param_env_normalized_for_post_analysis ( def_id) ,
1080+ }
10601081 }
10611082
10621083 /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
@@ -1067,16 +1088,22 @@ impl<'tcx> TypingEnv<'tcx> {
10671088 return self ;
10681089 }
10691090
1070- // No need to reveal opaques with the new solver enabled,
1071- // since we have lazy norm.
1072- let param_env = if tcx. next_trait_solver_globally ( ) {
1073- param_env
1074- } else {
1075- ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( param_env. caller_bounds ( ) ) )
1076- } ;
1091+ let param_env = param_env. with_normalized ( tcx) ;
10771092 TypingEnv { typing_mode : TypingMode :: PostAnalysis , param_env }
10781093 }
10791094
1095+ /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
1096+ /// in the `param_env`.
1097+ pub fn with_codegen_normalized ( self , tcx : TyCtxt < ' tcx > ) -> TypingEnv < ' tcx > {
1098+ let TypingEnv { typing_mode, param_env } = self ;
1099+ if let TypingMode :: Codegen = typing_mode {
1100+ return self ;
1101+ }
1102+
1103+ let param_env = param_env. with_normalized ( tcx) ;
1104+ TypingEnv { typing_mode : TypingMode :: Codegen , param_env }
1105+ }
1106+
10801107 /// Combine this typing environment with the given `value` to be used by
10811108 /// not (yet) canonicalized queries. This only works if the value does not
10821109 /// contain anything local to some `InferCtxt`, i.e. inference variables or
0 commit comments