@@ -1003,6 +1003,17 @@ impl<'tcx> ParamEnv<'tcx> {
1003
1003
pub fn and < T : TypeVisitable < TyCtxt < ' tcx > > > ( self , value : T ) -> ParamEnvAnd < ' tcx , T > {
1004
1004
ParamEnvAnd { param_env : self , value }
1005
1005
}
1006
+
1007
+ /// Eagerly reveal all opaque types in the `param_env`.
1008
+ pub fn with_normalized ( self , tcx : TyCtxt < ' tcx > ) -> ParamEnv < ' tcx > {
1009
+ // No need to reveal opaques with the new solver enabled,
1010
+ // since we have lazy norm.
1011
+ if tcx. next_trait_solver_globally ( ) {
1012
+ self
1013
+ } else {
1014
+ ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( self . caller_bounds ) )
1015
+ }
1016
+ }
1006
1017
}
1007
1018
1008
1019
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TypeFoldable , TypeVisitable ) ]
@@ -1056,7 +1067,17 @@ impl<'tcx> TypingEnv<'tcx> {
1056
1067
}
1057
1068
1058
1069
pub fn post_analysis ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryParam < DefId > ) -> TypingEnv < ' tcx > {
1059
- tcx. typing_env_normalized_for_post_analysis ( def_id)
1070
+ TypingEnv {
1071
+ typing_mode : TypingMode :: PostAnalysis ,
1072
+ param_env : tcx. param_env_normalized_for_post_analysis ( def_id) ,
1073
+ }
1074
+ }
1075
+
1076
+ pub fn codegen ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryParam < DefId > ) -> TypingEnv < ' tcx > {
1077
+ TypingEnv {
1078
+ typing_mode : TypingMode :: Codegen ,
1079
+ param_env : tcx. param_env_normalized_for_post_analysis ( def_id) ,
1080
+ }
1060
1081
}
1061
1082
1062
1083
/// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
@@ -1067,16 +1088,22 @@ impl<'tcx> TypingEnv<'tcx> {
1067
1088
return self ;
1068
1089
}
1069
1090
1070
- // No need to reveal opaques with the new solver enabled,
1071
- // since we have lazy norm.
1072
- let param_env = if tcx. next_trait_solver_globally ( ) {
1073
- param_env
1074
- } else {
1075
- ParamEnv :: new ( tcx. reveal_opaque_types_in_bounds ( param_env. caller_bounds ( ) ) )
1076
- } ;
1091
+ let param_env = param_env. with_normalized ( tcx) ;
1077
1092
TypingEnv { typing_mode : TypingMode :: PostAnalysis , param_env }
1078
1093
}
1079
1094
1095
+ /// Modify the `typing_mode` to `PostAnalysis` or `Codegen` and eagerly reveal all opaque types
1096
+ /// in the `param_env`.
1097
+ pub fn with_codegen_normalized ( self , tcx : TyCtxt < ' tcx > ) -> TypingEnv < ' tcx > {
1098
+ let TypingEnv { typing_mode, param_env } = self ;
1099
+ if let TypingMode :: Codegen = typing_mode {
1100
+ return self ;
1101
+ }
1102
+
1103
+ let param_env = param_env. with_normalized ( tcx) ;
1104
+ TypingEnv { typing_mode : TypingMode :: Codegen , param_env }
1105
+ }
1106
+
1080
1107
/// Combine this typing environment with the given `value` to be used by
1081
1108
/// not (yet) canonicalized queries. This only works if the value does not
1082
1109
/// contain anything local to some `InferCtxt`, i.e. inference variables or
0 commit comments