@@ -79,31 +79,50 @@ pub type Bound<T> = Option<T>;
79
79
pub type UnitResult < ' tcx > = RelateResult < ' tcx , ( ) > ; // "unify result"
80
80
pub type FixupResult < ' tcx , T > = Result < T , FixupError < ' tcx > > ; // "fixup result"
81
81
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
+ }
88
104
}
89
105
90
- impl SuppressRegionErrors {
106
+ impl RegionckMode {
91
107
pub fn suppressed ( self ) -> bool {
92
- self . suppressed
108
+ match self {
109
+ Self :: Solve => false ,
110
+ Self :: Erase { suppress_errors } => suppress_errors,
111
+ }
93
112
}
94
113
95
114
/// Indicates that the MIR borrowck will repeat these region
96
115
/// checks, so we should ignore errors if NLL is (unconditionally)
97
116
/// enabled.
98
- pub fn when_nll_is_enabled ( tcx : TyCtxt < ' _ > ) -> Self {
117
+ pub fn for_item_body ( tcx : TyCtxt < ' _ > ) -> Self {
99
118
// FIXME(Centril): Once we actually remove `::Migrate` also make
100
119
// this always `true` and then proceed to eliminate the dead code.
101
120
match tcx. borrowck_mode ( ) {
102
121
// If we're on Migrate mode, report AST region errors
103
- BorrowckMode :: Migrate => SuppressRegionErrors { suppressed : false } ,
122
+ BorrowckMode :: Migrate => RegionckMode :: Erase { suppress_errors : false } ,
104
123
105
124
// 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 } ,
107
126
}
108
127
}
109
128
}
@@ -1207,29 +1226,30 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1207
1226
region_context : DefId ,
1208
1227
region_map : & region:: ScopeTree ,
1209
1228
outlives_env : & OutlivesEnvironment < ' tcx > ,
1210
- suppress : SuppressRegionErrors ,
1229
+ mode : RegionckMode ,
1211
1230
) {
1212
1231
assert ! (
1213
1232
self . is_tainted_by_errors( ) || self . inner. borrow( ) . region_obligations. is_empty( ) ,
1214
1233
"region_obligations not empty: {:#?}" ,
1215
1234
self . inner. borrow( ) . region_obligations
1216
1235
) ;
1217
-
1218
- let region_rels = & RegionRelations :: new (
1219
- self . tcx ,
1220
- region_context,
1221
- region_map,
1222
- outlives_env. free_region_map ( ) ,
1223
- ) ;
1224
1236
let ( var_infos, data) = self
1225
1237
. inner
1226
1238
. borrow_mut ( )
1227
1239
. region_constraints
1228
1240
. take ( )
1229
1241
. expect ( "regions already resolved" )
1230
1242
. 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
+
1231
1251
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 ) ;
1233
1253
1234
1254
let old_value = self . lexical_region_resolutions . replace ( Some ( lexical_region_resolutions) ) ;
1235
1255
assert ! ( old_value. is_none( ) ) ;
@@ -1240,7 +1260,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1240
1260
// this infcx was in use. This is totally hokey but
1241
1261
// otherwise we have a hard time separating legit region
1242
1262
// errors from silly ones.
1243
- self . report_region_errors ( region_map, & errors, suppress ) ;
1263
+ self . report_region_errors ( region_map, & errors) ;
1244
1264
}
1245
1265
}
1246
1266
0 commit comments