@@ -1009,6 +1009,17 @@ impl<'tcx> ParamEnv<'tcx> {
10091009 pub fn and < T : TypeVisitable < TyCtxt < ' tcx > > > ( self , value : T ) -> ParamEnvAnd < ' tcx , T > {
10101010 ParamEnvAnd { param_env : self , value }
10111011 }
1012+
1013+ /// Eagerly reveal all opaque types in the `param_env`.
1014+ pub fn with_normalized ( self , tcx : TyCtxt < ' tcx > ) -> ParamEnv < ' tcx > {
1015+ // No need to reveal opaques with the new solver enabled,
1016+ // since we have lazy norm.
1017+ if tcx. next_trait_solver_globally ( ) {
1018+ self
1019+ } else {
1020+ ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( self . caller_bounds ) )
1021+ }
1022+ }
10121023}
10131024
10141025#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable , TypeVisitable ) ]
@@ -1062,7 +1073,17 @@ impl<'tcx> TypingEnv<'tcx> {
10621073 }
10631074
10641075 pub fn post_analysis ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryParam < DefId > ) -> TypingEnv < ' tcx > {
1065- tcx. typing_env_normalized_for_post_analysis ( def_id)
1076+ TypingEnv {
1077+ typing_mode : TypingMode :: PostAnalysis ,
1078+ param_env : tcx. param_env_normalized_for_post_analysis ( def_id) ,
1079+ }
1080+ }
1081+
1082+ pub fn codegen ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryParam < DefId > ) -> TypingEnv < ' tcx > {
1083+ TypingEnv {
1084+ typing_mode : TypingMode :: Codegen ,
1085+ param_env : tcx. param_env_normalized_for_post_analysis ( def_id) ,
1086+ }
10661087 }
10671088
10681089 /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
@@ -1073,16 +1094,22 @@ impl<'tcx> TypingEnv<'tcx> {
10731094 return self ;
10741095 }
10751096
1076- // No need to reveal opaques with the new solver enabled,
1077- // since we have lazy norm.
1078- let param_env = if tcx. next_trait_solver_globally ( ) {
1079- param_env
1080- } else {
1081- ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( param_env. caller_bounds ( ) ) )
1082- } ;
1097+ let param_env = param_env. with_normalized ( tcx) ;
10831098 TypingEnv { typing_mode : TypingMode :: PostAnalysis , param_env }
10841099 }
10851100
1101+ /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
1102+ /// in the `param_env`.
1103+ pub fn with_codegen_normalized ( self , tcx : TyCtxt < ' tcx > ) -> TypingEnv < ' tcx > {
1104+ let TypingEnv { typing_mode, param_env } = self ;
1105+ if let TypingMode :: Codegen = typing_mode {
1106+ return self ;
1107+ }
1108+
1109+ let param_env = param_env. with_normalized ( tcx) ;
1110+ TypingEnv { typing_mode : TypingMode :: Codegen , param_env }
1111+ }
1112+
10861113 /// Combine this typing environment with the given `value` to be used by
10871114 /// not (yet) canonicalized queries. This only works if the value does not
10881115 /// contain anything local to some `InferCtxt`, i.e. inference variables or
0 commit comments