@@ -9,7 +9,6 @@ use rustc_middle::hir::nested_filter;
99use rustc_middle:: query:: Providers ;
1010use rustc_middle:: span_bug;
1111use rustc_middle:: ty:: TyCtxt ;
12- use rustc_session:: Session ;
1312use rustc_span:: hygiene:: DesugaringKind ;
1413use rustc_span:: { BytePos , Span } ;
1514use Context :: * ;
@@ -65,7 +64,6 @@ impl fmt::Display for BreakContextKind {
6564
6665#[ derive( Clone ) ]
6766struct CheckLoopVisitor < ' tcx > {
68- sess : & ' tcx Session ,
6967 tcx : TyCtxt < ' tcx > ,
7068 // Keep track of a stack of contexts, so that suggestions
7169 // are not made for contexts where it would be incorrect,
@@ -76,12 +74,8 @@ struct CheckLoopVisitor<'tcx> {
7674}
7775
7876fn 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 ( ) } ;
8579 tcx. hir ( ) . visit_item_likes_in_module ( module_def_id, & mut check) ;
8680 check. report_outside_loop_error ( ) ;
8781}
@@ -213,7 +207,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
213207 Ok ( loop_id) => Some ( loop_id) ,
214208 Err ( hir:: LoopIdError :: OutsideLoopScope ) => None ,
215209 Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) => {
216- self . sess . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
210+ self . tcx . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
217211 span : e. span ,
218212 cf_type : "break" ,
219213 } ) ;
@@ -248,7 +242,7 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
248242 . label
249243 . map_or_else( String :: new, |l| format!( " {}" , l. ident) )
250244 ) ;
251- self . sess . dcx ( ) . emit_err ( BreakNonLoop {
245+ self . tcx . dcx ( ) . emit_err ( BreakNonLoop {
252246 span : e. span ,
253247 head,
254248 kind : kind. name ( ) ,
@@ -280,14 +274,14 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
280274 match destination. target_id {
281275 Ok ( loop_id) => {
282276 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 {
284278 span : e. span ,
285279 block_span : block. span ,
286280 } ) ;
287281 }
288282 }
289283 Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) => {
290- self . sess . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
284+ self . tcx . dcx ( ) . emit_err ( UnlabeledCfInWhileCondition {
291285 span : e. span ,
292286 cf_type : "continue" ,
293287 } ) ;
@@ -326,7 +320,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
326320 match self . cx_stack [ cx_pos] {
327321 LabeledBlock | Loop ( _) => { }
328322 Closure ( closure_span) => {
329- self . sess . dcx ( ) . emit_err ( BreakInsideClosure {
323+ self . tcx . dcx ( ) . emit_err ( BreakInsideClosure {
330324 span,
331325 closure_span,
332326 name : & br_cx_kind. to_string ( ) ,
@@ -343,7 +337,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
343337 hir:: CoroutineSource :: Closure => "closure" ,
344338 hir:: CoroutineSource :: Fn => "function" ,
345339 } ;
346- self . sess . dcx ( ) . emit_err ( BreakInsideCoroutine {
340+ self . tcx . dcx ( ) . emit_err ( BreakInsideCoroutine {
347341 span,
348342 coroutine_span,
349343 name : & br_cx_kind. to_string ( ) ,
@@ -366,7 +360,7 @@ impl<'hir> CheckLoopVisitor<'hir> {
366360 self . require_break_cx ( br_cx_kind, span, break_span, cx_pos - 1 ) ;
367361 }
368362 Normal | AnonConst | Fn | UnlabeledBlock ( _) | UnlabeledIfBlock ( _) | ConstBlock => {
369- self . sess . dcx ( ) . emit_err ( OutsideLoop {
363+ self . tcx . dcx ( ) . emit_err ( OutsideLoop {
370364 spans : vec ! [ span] ,
371365 name : & br_cx_kind. to_string ( ) ,
372366 is_break : br_cx_kind == BreakContextKind :: Break ,
@@ -386,15 +380,15 @@ impl<'hir> CheckLoopVisitor<'hir> {
386380 && self . cx_stack . last ( ) == Some ( & LabeledBlock )
387381 && label. label . is_none ( )
388382 {
389- self . sess . dcx ( ) . emit_err ( UnlabeledInLabeledBlock { span, cf_type } ) ;
383+ self . tcx . dcx ( ) . emit_err ( UnlabeledInLabeledBlock { span, cf_type } ) ;
390384 return true ;
391385 }
392386 false
393387 }
394388
395389 fn report_outside_loop_error ( & self ) {
396390 for ( s, block) in & self . block_breaks {
397- self . sess . dcx ( ) . emit_err ( OutsideLoop {
391+ self . tcx . dcx ( ) . emit_err ( OutsideLoop {
398392 spans : block. spans . clone ( ) ,
399393 name : & block. name ,
400394 is_break : true ,
0 commit comments