@@ -1354,8 +1354,6 @@ impl DiagCtxtInner {
1354
1354
1355
1355
// Return value is only `Some` if the level is `Error` or `DelayedBug`.
1356
1356
fn emit_diagnostic(&mut self, mut diagnostic: DiagInner) -> Option<ErrorGuaranteed> {
1357
- assert!(diagnostic.level.can_be_top_or_sub().0);
1358
-
1359
1357
if diagnostic.has_future_breakage() {
1360
1358
// Future breakages aren't emitted if they're Level::Allow,
1361
1359
// but they still need to be constructed and stashed below,
@@ -1368,9 +1366,12 @@ impl DiagCtxtInner {
1368
1366
// return early *and* have some kind of side-effect, except where
1369
1367
// noted.
1370
1368
match diagnostic.level {
1371
- Fatal | Error if self.treat_next_err_as_bug() => {
1372
- // `Fatal` and `Error` can be promoted to `Bug`.
1373
- diagnostic.level = Bug;
1369
+ Bug => {}
1370
+ Fatal | Error => {
1371
+ if self.treat_next_err_as_bug() {
1372
+ // `Fatal` and `Error` can be promoted to `Bug`.
1373
+ diagnostic.level = Bug;
1374
+ }
1374
1375
}
1375
1376
DelayedBug => {
1376
1377
// Note that because we check these conditions first,
@@ -1405,14 +1406,21 @@ impl DiagCtxtInner {
1405
1406
};
1406
1407
}
1407
1408
}
1408
- Warning if !self.flags.can_emit_warnings => {
1409
- if diagnostic.has_future_breakage() {
1410
- // The side-effect is at the top of this method.
1411
- TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
1409
+ ForceWarning(None) => {} // `ForceWarning(Some(...))` is below, with `Expect`
1410
+ Warning => {
1411
+ if !self.flags.can_emit_warnings {
1412
+ // We are not emitting warnings.
1413
+ if diagnostic.has_future_breakage() {
1414
+ // The side-effect is at the top of this method.
1415
+ TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
1416
+ }
1417
+ return None;
1412
1418
}
1413
- return None;
1414
1419
}
1420
+ Note | Help | FailureNote => {}
1421
+ OnceNote | OnceHelp => panic!("bad level: {:?}", diagnostic.level),
1415
1422
Allow => {
1423
+ // Nothing emitted for allowed lints.
1416
1424
if diagnostic.has_future_breakage() {
1417
1425
// The side-effect is at the top of this method.
1418
1426
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
@@ -1434,12 +1442,12 @@ impl DiagCtxtInner {
1434
1442
}
1435
1443
self.fulfilled_expectations.insert(expect_id.normalize());
1436
1444
if let Expect(_) = diagnostic.level {
1445
+ // Nothing emitted here for expected lints.
1437
1446
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
1438
1447
self.suppressed_expected_diag = true;
1439
1448
return None;
1440
1449
}
1441
1450
}
1442
- _ => {}
1443
1451
}
1444
1452
1445
1453
TRACK_DIAGNOSTIC(diagnostic, &mut |mut diagnostic| {
@@ -1816,16 +1824,13 @@ impl Level {
1816
1824
matches!(*self, FailureNote)
1817
1825
}
1818
1826
1819
- // Can this level be used in a top-level diagnostic message and/or a
1820
- // subdiagnostic message?
1821
- fn can_be_top_or_sub(&self) -> (bool, bool) {
1827
+ // Can this level be used in a subdiagnostic message?
1828
+ fn can_be_subdiag(&self) -> bool {
1822
1829
match self {
1823
1830
Bug | DelayedBug | Fatal | Error | ForceWarning(_) | FailureNote | Allow
1824
- | Expect(_) => (true, false),
1825
-
1826
- Warning | Note | Help => (true, true),
1831
+ | Expect(_) => false,
1827
1832
1828
- OnceNote | OnceHelp => (false, true) ,
1833
+ Warning | Note | Help | OnceNote | OnceHelp => true,
1829
1834
}
1830
1835
}
1831
1836
}
0 commit comments