File tree 3 files changed +26
-3
lines changed
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>(
148
148
local_labels : & mut Vec < ( HirId , bool ) > ,
149
149
main_loop_id : HirId ,
150
150
) -> NeverLoopResult {
151
- match expr. kind {
151
+ let result = match expr. kind {
152
152
ExprKind :: Unary ( _, e)
153
153
| ExprKind :: Cast ( e, _)
154
154
| ExprKind :: Type ( e, _)
@@ -262,7 +262,14 @@ fn never_loop_expr<'tcx>(
262
262
| ExprKind :: ConstBlock ( _)
263
263
| ExprKind :: Lit ( _)
264
264
| 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
+ } )
266
273
}
267
274
268
275
fn 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) {
385
385
}
386
386
}
387
387
388
+ pub fn test32 ( b : bool ) {
389
+ loop {
390
+ //~^ ERROR: this loop never actually loops
391
+ panic ! ( "oh no" ) ;
392
+ }
393
+ }
394
+
388
395
fn main ( ) {
389
396
test1 ( ) ;
390
397
test2 ( ) ;
Original file line number Diff line number Diff line change @@ -161,5 +161,14 @@ LL | | if b { break 'c } else { break 'b }
161
161
LL | | }
162
162
| |_____________^
163
163
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
165
174
You can’t perform that action at this time.
0 commit comments