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