@@ -981,11 +981,19 @@ pub struct ParamEnvAnd<'tcx, T> {
981981pub struct TypingEnv < ' tcx > {
982982 #[ type_foldable( identity) ]
983983 #[ type_visitable( ignore) ]
984- pub typing_mode : EqTypingMode < ' tcx > ,
984+ typing_mode : EqTypingMode < ' tcx > ,
985985 pub param_env : ParamEnv < ' tcx > ,
986986}
987987
988988impl < ' tcx > TypingEnv < ' tcx > {
989+ pub fn new ( param_env : ParamEnv < ' tcx > , typing_mode : TypingMode < ' tcx > ) -> Self {
990+ Self { typing_mode : EqTypingMode ( typing_mode) , param_env }
991+ }
992+
993+ pub fn typing_mode ( & self ) -> TypingMode < ' tcx > {
994+ self . typing_mode . 0
995+ }
996+
989997 /// Create a typing environment with no where-clauses in scope
990998 /// where all opaque types and default associated items are revealed.
991999 ///
@@ -994,10 +1002,7 @@ impl<'tcx> TypingEnv<'tcx> {
9941002 /// use `TypingMode::PostAnalysis`, they may still have where-clauses
9951003 /// in scope.
9961004 pub fn fully_monomorphized ( ) -> TypingEnv < ' tcx > {
997- TypingEnv {
998- typing_mode : EqTypingMode ( TypingMode :: PostAnalysis ) ,
999- param_env : ParamEnv :: empty ( ) ,
1000- }
1005+ Self :: new ( ParamEnv :: empty ( ) , TypingMode :: PostAnalysis )
10011006 }
10021007
10031008 /// Create a typing environment for use during analysis outside of a body.
@@ -1010,10 +1015,7 @@ impl<'tcx> TypingEnv<'tcx> {
10101015 def_id : impl IntoQueryKey < DefId > ,
10111016 ) -> TypingEnv < ' tcx > {
10121017 let def_id = def_id. into_query_key ( ) ;
1013- TypingEnv {
1014- typing_mode : EqTypingMode ( TypingMode :: non_body_analysis ( ) ) ,
1015- param_env : tcx. param_env ( def_id) ,
1016- }
1018+ Self :: new ( tcx. param_env ( def_id) , TypingMode :: non_body_analysis ( ) )
10171019 }
10181020
10191021 pub fn post_analysis ( tcx : TyCtxt < ' tcx > , def_id : impl IntoQueryKey < DefId > ) -> TypingEnv < ' tcx > {
0 commit comments