@@ -80,31 +80,50 @@ pub type Bound<T> = Option<T>;
8080pub type UnitResult < ' tcx > = RelateResult < ' tcx , ( ) > ; // "unify result"
8181pub type FixupResult < ' tcx , T > = Result < T , FixupError < ' tcx > > ; // "fixup result"
8282
83- /// A flag that is used to suppress region errors. This is normally
84- /// false, but sometimes -- when we are doing region checks that the
85- /// NLL borrow checker will also do -- it might be set to true.
86- #[ derive( Copy , Clone , Default , Debug ) ]
87- pub struct SuppressRegionErrors {
88- suppressed : bool ,
83+ /// How we should handle region solving.
84+ ///
85+ /// This is used so that the region values inferred by HIR region solving are
86+ /// not exposed, and so that we can avoid doing work in HIR typeck that MIR
87+ /// typeck will also do.
88+ #[ derive( Copy , Clone , Debug ) ]
89+ pub enum RegionckMode {
90+ /// The default mode: report region errors, don't erase regions.
91+ Solve ,
92+ /// Erase the results of region after solving.
93+ Erase {
94+ /// A flag that is used to suppress region errors, when we are doing
95+ /// region checks that the NLL borrow checker will also do -- it might
96+ /// be set to true.
97+ suppress_errors : bool ,
98+ } ,
99+ }
100+
101+ impl Default for RegionckMode {
102+ fn default ( ) -> Self {
103+ RegionckMode :: Solve
104+ }
89105}
90106
91- impl SuppressRegionErrors {
107+ impl RegionckMode {
92108 pub fn suppressed ( self ) -> bool {
93- self . suppressed
109+ match self {
110+ Self :: Solve => false ,
111+ Self :: Erase { suppress_errors } => suppress_errors,
112+ }
94113 }
95114
96115 /// Indicates that the MIR borrowck will repeat these region
97116 /// checks, so we should ignore errors if NLL is (unconditionally)
98117 /// enabled.
99- pub fn when_nll_is_enabled ( tcx : TyCtxt < ' _ > ) -> Self {
118+ pub fn for_item_body ( tcx : TyCtxt < ' _ > ) -> Self {
100119 // FIXME(Centril): Once we actually remove `::Migrate` also make
101120 // this always `true` and then proceed to eliminate the dead code.
102121 match tcx. borrowck_mode ( ) {
103122 // If we're on Migrate mode, report AST region errors
104- BorrowckMode :: Migrate => SuppressRegionErrors { suppressed : false } ,
123+ BorrowckMode :: Migrate => RegionckMode :: Erase { suppress_errors : false } ,
105124
106125 // If we're on MIR, don't report AST region errors as they should be reported by NLL
107- BorrowckMode :: Mir => SuppressRegionErrors { suppressed : true } ,
126+ BorrowckMode :: Mir => RegionckMode :: Erase { suppress_errors : true } ,
108127 }
109128 }
110129}
@@ -1208,29 +1227,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12081227 region_context : DefId ,
12091228 region_map : & region:: ScopeTree ,
12101229 outlives_env : & OutlivesEnvironment < ' tcx > ,
1211- suppress : SuppressRegionErrors ,
1230+ mode : RegionckMode ,
12121231 ) {
12131232 assert ! (
12141233 self . is_tainted_by_errors( ) || self . inner. borrow( ) . region_obligations. is_empty( ) ,
12151234 "region_obligations not empty: {:#?}" ,
12161235 self . inner. borrow( ) . region_obligations
12171236 ) ;
1218-
1219- let region_rels = & RegionRelations :: new (
1220- self . tcx ,
1221- region_context,
1222- region_map,
1223- outlives_env. free_region_map ( ) ,
1224- ) ;
12251237 let ( var_infos, data) = self
12261238 . inner
12271239 . borrow_mut ( )
12281240 . region_constraints
12291241 . take ( )
12301242 . expect ( "regions already resolved" )
12311243 . into_infos_and_data ( ) ;
1244+
1245+ let region_rels = & RegionRelations :: new (
1246+ self . tcx ,
1247+ region_context,
1248+ region_map,
1249+ outlives_env. free_region_map ( ) ,
1250+ ) ;
1251+
12321252 let ( lexical_region_resolutions, errors) =
1233- lexical_region_resolve:: resolve ( region_rels, var_infos, data) ;
1253+ lexical_region_resolve:: resolve ( region_rels, var_infos, data, mode ) ;
12341254
12351255 let old_value = self . lexical_region_resolutions . replace ( Some ( lexical_region_resolutions) ) ;
12361256 assert ! ( old_value. is_none( ) ) ;
@@ -1241,7 +1261,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12411261 // this infcx was in use. This is totally hokey but
12421262 // otherwise we have a hard time separating legit region
12431263 // errors from silly ones.
1244- self . report_region_errors ( region_map, & errors, suppress ) ;
1264+ self . report_region_errors ( region_map, & errors) ;
12451265 }
12461266 }
12471267
0 commit comments