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