File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ fn never_loop_expr<'tcx>(
148148 local_labels : & mut Vec < ( HirId , bool ) > ,
149149 main_loop_id : HirId ,
150150) -> NeverLoopResult {
151- match expr. kind {
151+ let result = match expr. kind {
152152 ExprKind :: Unary ( _, e)
153153 | ExprKind :: Cast ( e, _)
154154 | ExprKind :: Type ( e, _)
@@ -262,7 +262,14 @@ fn never_loop_expr<'tcx>(
262262 | ExprKind :: ConstBlock ( _)
263263 | ExprKind :: Lit ( _)
264264 | ExprKind :: Err ( _) => NeverLoopResult :: Normal ,
265- }
265+ } ;
266+ combine_seq ( result, || {
267+ if cx. typeck_results ( ) . expr_ty ( expr) . is_never ( ) {
268+ NeverLoopResult :: Diverging
269+ } else {
270+ NeverLoopResult :: Normal
271+ }
272+ } )
266273}
267274
268275fn never_loop_expr_all < ' tcx , T : Iterator < Item = & ' tcx Expr < ' tcx > > > (
Original file line number Diff line number Diff line change @@ -385,6 +385,13 @@ pub fn test31(b: bool) {
385385 }
386386}
387387
388+ pub fn test32 ( b : bool ) {
389+ loop {
390+ //~^ ERROR: this loop never actually loops
391+ panic ! ( "oh no" ) ;
392+ }
393+ }
394+
388395fn main ( ) {
389396 test1 ( ) ;
390397 test2 ( ) ;
Original file line number Diff line number Diff line change @@ -161,5 +161,14 @@ LL | | if b { break 'c } else { break 'b }
161161LL | | }
162162 | |_____________^
163163
164- error: aborting due to 14 previous errors
164+ error: this loop never actually loops
165+ --> $DIR/never_loop.rs:389:5
166+ |
167+ LL | / loop {
168+ LL | |
169+ LL | | panic!("oh no");
170+ LL | | }
171+ | |_____^
172+
173+ error: aborting due to 15 previous errors
165174
You can’t perform that action at this time.
0 commit comments