@@ -1002,6 +1002,17 @@ impl<'tcx> ParamEnv<'tcx> {
1002
1002
pub fn and < T : TypeVisitable < TyCtxt < ' tcx > > > ( self , value : T ) -> ParamEnvAnd < ' tcx , T > {
1003
1003
ParamEnvAnd { param_env : self , value }
1004
1004
}
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
+ }
1005
1016
}
1006
1017
1007
1018
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable , TypeVisitable ) ]
@@ -1055,7 +1066,17 @@ impl<'tcx> TypingEnv<'tcx> {
1055
1066
}
1056
1067
1057
1068
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
+ }
1059
1080
}
1060
1081
1061
1082
/// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
@@ -1066,16 +1087,22 @@ impl<'tcx> TypingEnv<'tcx> {
1066
1087
return self ;
1067
1088
}
1068
1089
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) ;
1076
1091
TypingEnv { typing_mode : TypingMode :: PostAnalysis , param_env }
1077
1092
}
1078
1093
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
+
1079
1106
/// Combine this typing environment with the given `value` to be used by
1080
1107
/// not (yet) canonicalized queries. This only works if the value does not
1081
1108
/// contain anything local to some `InferCtxt`, i.e. inference variables or
0 commit comments