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