Merge pull request #17923 from geoffw0/unreachable4

Rust: More tests for rust/deadcode
This commit is contained in:
Simon Friis Vindum
2024-11-11 08:45:47 +01:00
committed by GitHub
5 changed files with 305 additions and 119 deletions

View File

@@ -89,12 +89,17 @@ uniqueCallEnclosingCallable
| main.rs:522:5:522:14 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:523:5:523:14 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:525:5:525:22 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:527:5:527:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:529:5:529:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:526:5:526:22 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:527:5:527:22 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:528:5:528:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:529:9:529:26 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:530:5:530:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:531:5:531:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:532:5:532:22 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:533:5:533:22 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:531:5:531:22 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:532:5:532:28 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:533:5:533:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:534:5:534:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:535:5:535:23 | CallExpr | Call should have one enclosing callable but has 0. |
| main.rs:536:5:536:28 | CallExpr | Call should have one enclosing callable but has 0. |
| more.rs:45:14:45:26 | CallExpr | Call should have one enclosing callable but has 0. |
| more.rs:46:14:46:25 | CallExpr | Call should have one enclosing callable but has 0. |
| more.rs:47:14:47:26 | CallExpr | Call should have one enclosing callable but has 0. |
@@ -123,68 +128,107 @@ uniqueCallEnclosingCallable
| unreachable.rs:62:8:62:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:71:8:71:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:72:9:72:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:73:16:73:25 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:74:9:74:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:77:8:77:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:78:9:78:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:79:9:79:24 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:80:9:80:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:83:8:83:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:84:9:84:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:85:9:85:15 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:86:9:86:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:89:8:89:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:90:9:90:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:91:9:91:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:75:9:75:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:78:5:78:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:82:9:82:14 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:83:9:83:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:87:5:87:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:91:8:91:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:92:9:92:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:95:8:95:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:98:17:98:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:93:16:93:25 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:94:9:94:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:97:8:97:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:98:9:98:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:99:9:99:24 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:100:9:100:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:102:20:102:25 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:102:29:102:41 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:103:8:103:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:104:9:104:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:108:9:108:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:111:8:111:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:105:9:105:15 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:106:9:106:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:109:8:109:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:110:9:110:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:111:9:111:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:112:9:112:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:114:13:114:20 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:115:9:115:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:116:22:116:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:116:22:116:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:117:9:117:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:120:8:120:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:121:9:121:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:123:13:123:20 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:115:8:115:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:118:17:118:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:120:9:120:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:122:20:122:25 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:122:29:122:41 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:124:9:124:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:125:21:125:28 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:125:21:125:28 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:126:9:126:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:131:11:131:24 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:136:13:136:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:139:5:139:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:141:11:141:24 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:154:9:154:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:159:8:159:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:160:15:160:20 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:161:13:161:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:169:13:169:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:175:12:175:17 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:179:9:179:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:183:12:183:17 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:198:22:198:41 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:199:9:199:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:202:9:202:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:205:5:205:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:207:16:207:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:209:9:209:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:219:19:219:38 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:220:9:220:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:224:5:224:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:226:13:226:32 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:232:5:232:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:236:8:236:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:237:9:237:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:240:9:240:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:243:5:243:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:247:9:247:14 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:248:9:248:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:252:5:252:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:128:9:128:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:131:8:131:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:132:9:132:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:134:13:134:20 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:135:9:135:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:136:22:136:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:136:22:136:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:137:9:137:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:140:8:140:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:141:9:141:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:143:13:143:20 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:144:9:144:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:145:21:145:28 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:145:21:145:28 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:146:9:146:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:163:8:163:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:164:9:164:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:165:16:165:43 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:165:20:165:42 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:169:8:169:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:170:9:170:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:171:9:171:17 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:171:9:171:17 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:175:8:175:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:176:9:176:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:177:17:177:25 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:177:17:177:25 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:179:5:179:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:181:5:181:9 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:185:8:185:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:186:15:186:28 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:191:17:191:30 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:194:9:194:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:197:8:197:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:198:15:198:28 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:209:8:209:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:210:19:210:32 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:214:9:214:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:217:8:217:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:218:13:221:10 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:218:24:218:37 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:222:9:222:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:227:8:227:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:229:13:229:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:235:8:235:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:236:15:236:20 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:237:13:237:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:245:13:245:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:250:8:250:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:252:16:252:21 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:256:13:256:26 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:260:8:260:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:262:16:262:21 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:272:8:272:13 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:278:13:278:15 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:281:9:281:31 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:282:9:282:31 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:283:9:283:33 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:284:9:284:33 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:285:9:285:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:294:13:294:32 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:296:9:296:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:301:13:301:32 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:318:22:318:41 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:319:9:319:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:322:9:322:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:325:5:325:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:327:16:327:29 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:329:9:329:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:339:19:339:38 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:340:9:340:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:344:5:344:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:346:13:346:32 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:352:5:352:18 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:360:9:360:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:362:9:362:22 | CallExpr | Call should have one enclosing callable but has 0. |
| unreachable.rs:368:9:368:22 | CallExpr | Call should have one enclosing callable but has 0. |

View File

@@ -3,14 +3,21 @@
| unreachable.rs:39:9:39:23 | ExprStmt | This code is never reached. |
| unreachable.rs:46:9:46:23 | ExprStmt | This code is never reached. |
| unreachable.rs:67:5:67:19 | ExprStmt | This code is never reached. |
| unreachable.rs:114:13:114:20 | MacroExpr | This code is never reached. |
| unreachable.rs:123:13:123:20 | MacroExpr | This code is never reached. |
| unreachable.rs:149:5:149:19 | ExprStmt | This code is never reached. |
| unreachable.rs:156:9:156:23 | ExprStmt | This code is never reached. |
| unreachable.rs:165:13:165:27 | ExprStmt | This code is never reached. |
| unreachable.rs:171:9:171:23 | ExprStmt | This code is never reached. |
| unreachable.rs:177:13:177:27 | ExprStmt | This code is never reached. |
| unreachable.rs:185:13:185:27 | ExprStmt | This code is never reached. |
| unreachable.rs:188:5:188:19 | ExprStmt | This code is never reached. |
| unreachable.rs:212:9:212:23 | ExprStmt | This code is never reached. |
| unreachable.rs:228:9:228:23 | ExprStmt | This code is never reached. |
| unreachable.rs:134:13:134:20 | MacroExpr | This code is never reached. |
| unreachable.rs:143:13:143:20 | MacroExpr | This code is never reached. |
| unreachable.rs:166:9:166:23 | ExprStmt | This code is never reached. |
| unreachable.rs:171:9:171:17 | MacroExpr | This code is never reached. |
| unreachable.rs:177:9:177:26 | MacroExpr | This code is never reached. |
| unreachable.rs:206:9:206:23 | ExprStmt | This code is never reached. |
| unreachable.rs:231:13:231:27 | ExprStmt | This code is never reached. |
| unreachable.rs:241:13:241:27 | ExprStmt | This code is never reached. |
| unreachable.rs:247:9:247:23 | ExprStmt | This code is never reached. |
| unreachable.rs:254:17:254:31 | ExprStmt | This code is never reached. |
| unreachable.rs:264:17:264:31 | ExprStmt | This code is never reached. |
| unreachable.rs:267:9:267:23 | ExprStmt | This code is never reached. |
| unreachable.rs:303:9:303:23 | ExprStmt | This code is never reached. |
| unreachable.rs:332:9:332:23 | ExprStmt | This code is never reached. |
| unreachable.rs:348:9:348:23 | ExprStmt | This code is never reached. |
| unreachable.rs:370:9:370:23 | ExprStmt | This code is never reached. |
| unreachable.rs:375:5:375:10 | ExprStmt | This code is never reached. |
| unreachable.rs:382:5:382:10 | ExprStmt | This code is never reached. |

View File

@@ -18,3 +18,5 @@
| more.rs:44:9:44:14 | a_ptr4 | Variable $@ is assigned a value that is never used. | more.rs:44:9:44:14 | a_ptr4 | a_ptr4 |
| more.rs:59:9:59:13 | d_ptr | Variable $@ is assigned a value that is never used. | more.rs:59:9:59:13 | d_ptr | d_ptr |
| more.rs:65:9:65:17 | f_ptr | Variable $@ is assigned a value that is never used. | more.rs:65:13:65:17 | f_ptr | f_ptr |
| unreachable.rs:292:9:292:15 | for_ten | Variable $@ is assigned a value that is never used. | unreachable.rs:292:9:292:15 | for_ten | for_ten |
| unreachable.rs:299:9:299:16 | for_ever | Variable $@ is assigned a value that is never used. | unreachable.rs:299:9:299:16 | for_ever | for_ever |

View File

@@ -523,12 +523,15 @@ fn main() {
pointers();
unreachable_if_1();
// unreachable_panic();
unreachable_if_2();
unreachable_if_3();
unreachable_panic();
_ = unreachable_bail();
unreachable_match();
// unreachable_loop();
unreachable_loop();
unreachable_loop_async();
unreachable_paren();
unreachable_let_1();
unreachable_let_2();
unreachable_if_2();
unreachable_if_3();
unreachable_attributes();
}

View File

@@ -67,6 +67,26 @@ pub fn unreachable_if_1() {
do_something(); // $ Alert[rust/dead-code]
}
pub fn unreachable_if_2() {
if cond() {
do_something();
return;
} else {
do_something();
}
do_something();
}
pub fn unreachable_if_3() {
if !cond() {
do_something();
return;
}
do_something();
}
pub fn unreachable_panic() {
if cond() {
do_something();
@@ -127,33 +147,89 @@ pub fn unreachable_panic() {
}
}
pub fn unreachable_match() {
match get_a_number() {
1 => {
return;
}
_ => {
do_something();
}
macro_rules! bail_1 {
() => {
return Err(String::from("message"))
};
}
macro_rules! bail_2 {
($message:literal) => {
return Err(String::from($message))
};
}
pub fn unreachable_bail() -> Result<i32, String> {
if cond() {
do_something();
return Err(String::from("message"));
do_something(); // $ Alert[rust/dead-code]
}
if cond() {
do_something();
bail_1!(); // $ SPURIOUS: Alert[rust/dead-code]
do_something(); // $ MISSING: Alert[rust/dead-code]
}
if cond() {
do_something();
bail_2!("message"); // $ SPURIOUS: Alert[rust/dead-code]
}
do_something();
match get_a_number() {
1 => {
return;
}
_ => {
return;
Ok(1)
}
pub fn unreachable_match() {
if cond() {
match get_a_number() {
1 => {
return;
}
_ => {
do_something();
}
}
do_something();
}
if cond() {
match get_a_number() {
1 => {
return;
}
_ => {
return;
}
}
do_something(); // $ Alert[rust/dead-code]
}
if cond() {
_ = match get_a_number() {
1 => "One",
_ => "Some"
};
do_something();
}
if cond() {
_ = Some(match get_a_number() {
1 => "One",
_ => "Some"
});
do_something();
}
do_something(); // $ Alert[rust/dead-code]
}
pub fn unreachable_loop() {
loop {
do_something();
break;
do_something(); // $ Alert[rust/dead-code]
if cond() {
loop {
do_something();
break;
do_something(); // $ Alert[rust/dead-code]
}
}
if cond() {
@@ -171,23 +247,67 @@ pub fn unreachable_loop() {
do_something(); // $ Alert[rust/dead-code]
}
for _ in 1..10 {
if cond() {
continue;
do_something(); // $ Alert[rust/dead-code]
if cond() {
for _ in 1..10 {
if cond() {
continue;
do_something(); // $ Alert[rust/dead-code]
}
do_something();
}
}
if cond() {
loop {
if cond() {
return;
do_something(); // $ Alert[rust/dead-code]
}
}
do_something(); // $ Alert[rust/dead-code]
do_something();
do_something();
}
loop {
if cond() {
return;
do_something(); // $ Alert[rust/dead-code]
}
if cond() {
fn do_nothing() { };
fn loop_forever() { loop {} };
fn take_a_fn(_: fn() -> ()) {
};
fn call_a_fn(f: fn() -> ()) {
f();
};
take_a_fn( do_nothing );
call_a_fn( do_nothing );
take_a_fn( loop_forever );
call_a_fn( loop_forever );
do_something(); // $ MISSING: Alert[rust/dead-code]
}
do_something(); // $ Alert[rust/dead-code]
}
async fn do_something_async() {}
pub async fn unreachable_loop_async() {
let for_ten = async { // $ SPURIOUS: Alert[rust/unused-value]
for _ in 1..10 {
do_something_async().await;
}
do_something();
};
let for_ever = async { // $ SPURIOUS: Alert[rust/unused-value]
loop {
do_something_async().await;
}
do_something(); // $ Alert[rust/dead-code]
};
do_something();
for_ten.await;
do_something();
for_ever.await;
do_something(); // $ MISSING: Alert[rust/dead-code]
}
pub fn unreachable_paren() {
@@ -232,22 +352,32 @@ pub fn unreachable_let_2() {
do_something();
}
pub fn unreachable_if_2() {
if cond() {
#[cfg(not(foo))]
pub fn unreachable_attributes() {
// `#[cfg` and `cfg!` checks can go either way, we should not assume this
// function or either branch below is unreachable.
if cfg!(bar) {
do_something();
return;
} else {
do_something();
}
do_something();
}
#[doc="This is a doc comment declared through an attribute."]
pub fn unreachable_if_3() {
if !cond() {
if (true) {
do_something();
return;
} else {
do_something(); // $ Alert[rust/dead-code]
}
do_something();
}
const _: () = {
_ = 1; // $ SPURIOUS: Alert[rust/dead-code]
};
const _: () = {
const fn foo() {
_ = 1;
};
foo(); // $ SPURIOUS: Alert[rust/dead-code]
};