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