@@ -1009,6 +1009,17 @@ impl<'tcx> ParamEnv<'tcx> {
1009
1009
pub fn and < T : TypeVisitable < TyCtxt < ' tcx > > > ( self , value : T ) -> ParamEnvAnd < ' tcx , T > {
1010
1010
ParamEnvAnd { param_env : self , value }
1011
1011
}
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
+ }
1012
1023
}
1013
1024
1014
1025
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable , TypeVisitable ) ]
@@ -1062,7 +1073,17 @@ impl<'tcx> TypingEnv<'tcx> {
1062
1073
}
1063
1074
1064
1075
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
+ }
1066
1087
}
1067
1088
1068
1089
/// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
@@ -1073,16 +1094,22 @@ impl<'tcx> TypingEnv<'tcx> {
1073
1094
return self ;
1074
1095
}
1075
1096
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) ;
1083
1098
TypingEnv { typing_mode : TypingMode :: PostAnalysis , param_env }
1084
1099
}
1085
1100
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
+
1086
1113
/// Combine this typing environment with the given `value` to be used by
1087
1114
/// not (yet) canonicalized queries. This only works if the value does not
1088
1115
/// contain anything local to some `InferCtxt`, i.e. inference variables or
0 commit comments