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