@@ -9,7 +9,6 @@ use rustc_middle::hir::nested_filter;
9
9
use rustc_middle:: query:: Providers ;
10
10
use rustc_middle:: span_bug;
11
11
use rustc_middle:: ty:: TyCtxt ;
12
- use rustc_session:: Session ;
13
12
use rustc_span:: hygiene:: DesugaringKind ;
14
13
use rustc_span:: { BytePos , Span } ;
15
14
use Context :: * ;
@@ -65,7 +64,6 @@ impl fmt::Display for BreakContextKind {
65
64
66
65
#[ derive( Clone ) ]
67
66
struct CheckLoopVisitor < ' tcx > {
68
- sess : & ' tcx Session ,
69
67
tcx : TyCtxt < ' tcx > ,
70
68
// Keep track of a stack of contexts, so that suggestions
71
69
// are not made for contexts where it would be incorrect,
@@ -76,12 +74,8 @@ struct CheckLoopVisitor<'tcx> {
76
74
}
77
75
78
76
fn check_mod_loops ( tcx : TyCtxt < ' _ > , module_def_id : LocalModDefId ) {
79
- let mut check = CheckLoopVisitor {
80
- sess : tcx. sess ,
81
- tcx,
82
- cx_stack : vec ! [ Normal ] ,
83
- block_breaks : Default :: default ( ) ,
84
- } ;
77
+ let mut check =
78
+ CheckLoopVisitor { tcx, cx_stack : vec ! [ Normal ] , block_breaks : Default :: default ( ) } ;
85
79
tcx. hir ( ) . visit_item_likes_in_module ( module_def_id, & mut check) ;
86
80
check. report_outside_loop_error ( ) ;
87
81
}
@@ -213,7 +207,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
213
207
Ok ( loop_id) => Some ( loop_id) ,
214
208
Err ( hir:: LoopIdError :: OutsideLoopScope ) => None ,
215
209
Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) => {
216
- self . sess . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
210
+ self . tcx . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
217
211
span : e. span ,
218
212
cf_type : "break" ,
219
213
} ) ;
@@ -248,7 +242,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
248
242
. label
249
243
. map_or_else( String :: new, |l| format!( " {}" , l. ident) )
250
244
) ;
251
- self . sess . dcx ( ) . emit_err ( BreakNonLoop {
245
+ self . tcx . dcx ( ) . emit_err ( BreakNonLoop {
252
246
span : e. span ,
253
247
head,
254
248
kind : kind. name ( ) ,
@@ -280,14 +274,14 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
280
274
match destination. target_id {
281
275
Ok ( loop_id) => {
282
276
if let Node :: Block ( block) = self . tcx . hir_node ( loop_id) {
283
- self . sess . dcx ( ) . emit_err ( ContinueLabeledBlock {
277
+ self . tcx . dcx ( ) . emit_err ( ContinueLabeledBlock {
284
278
span : e. span ,
285
279
block_span : block. span ,
286
280
} ) ;
287
281
}
288
282
}
289
283
Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) => {
290
- self . sess . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
284
+ self . tcx . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
291
285
span : e. span ,
292
286
cf_type : "continue" ,
293
287
} ) ;
@@ -326,7 +320,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
326
320
match self . cx_stack [ cx_pos] {
327
321
LabeledBlock | Loop ( _) => { }
328
322
Closure ( closure_span) => {
329
- self . sess . dcx ( ) . emit_err ( BreakInsideClosure {
323
+ self . tcx . dcx ( ) . emit_err ( BreakInsideClosure {
330
324
span,
331
325
closure_span,
332
326
name : & br_cx_kind. to_string ( ) ,
@@ -343,7 +337,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
343
337
hir:: CoroutineSource :: Closure => "closure" ,
344
338
hir:: CoroutineSource :: Fn => "function" ,
345
339
} ;
346
- self . sess . dcx ( ) . emit_err ( BreakInsideCoroutine {
340
+ self . tcx . dcx ( ) . emit_err ( BreakInsideCoroutine {
347
341
span,
348
342
coroutine_span,
349
343
name : & br_cx_kind. to_string ( ) ,
@@ -366,7 +360,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
366
360
self . require_break_cx ( br_cx_kind, span, break_span, cx_pos - 1 ) ;
367
361
}
368
362
Normal | AnonConst | Fn | UnlabeledBlock ( _) | UnlabeledIfBlock ( _) | ConstBlock => {
369
- self . sess . dcx ( ) . emit_err ( OutsideLoop {
363
+ self . tcx . dcx ( ) . emit_err ( OutsideLoop {
370
364
spans : vec ! [ span] ,
371
365
name : & br_cx_kind. to_string ( ) ,
372
366
is_break : br_cx_kind == BreakContextKind :: Break ,
@@ -386,15 +380,15 @@ impl<'hir> CheckLoopVisitor<'hir> {
386
380
&& self . cx_stack . last ( ) == Some ( & LabeledBlock )
387
381
&& label. label . is_none ( )
388
382
{
389
- self . sess . dcx ( ) . emit_err ( UnlabeledInLabeledBlock { span, cf_type } ) ;
383
+ self . tcx . dcx ( ) . emit_err ( UnlabeledInLabeledBlock { span, cf_type } ) ;
390
384
return true ;
391
385
}
392
386
false
393
387
}
394
388
395
389
fn report_outside_loop_error ( & self ) {
396
390
for ( s, block) in & self . block_breaks {
397
- self . sess . dcx ( ) . emit_err ( OutsideLoop {
391
+ self . tcx . dcx ( ) . emit_err ( OutsideLoop {
398
392
spans : block. spans . clone ( ) ,
399
393
name : & block. name ,
400
394
is_break : true ,
0 commit comments