@@ -1354,8 +1354,6 @@ impl DiagCtxtInner {
13541354
13551355 // Return value is only `Some` if the level is `Error` or `DelayedBug`.
13561356 fn emit_diagnostic ( & mut self , mut diagnostic : DiagInner ) -> Option < ErrorGuaranteed > {
1357- assert ! ( diagnostic. level. can_be_top_or_sub( ) . 0 ) ;
1358-
13591357 if diagnostic. has_future_breakage ( ) {
13601358 // Future breakages aren't emitted if they're Level::Allow,
13611359 // but they still need to be constructed and stashed below,
@@ -1368,9 +1366,12 @@ impl DiagCtxtInner {
13681366 // return early *and* have some kind of side-effect, except where
13691367 // noted.
13701368 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+ }
13741375 }
13751376 DelayedBug => {
13761377 // Note that because we check these conditions first,
@@ -1405,14 +1406,21 @@ impl DiagCtxtInner {
14051406 } ;
14061407 }
14071408 }
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 ;
14121418 }
1413- return None ;
14141419 }
1420+ Note | Help | FailureNote => { }
1421+ OnceNote | OnceHelp => panic ! ( "bad level: {:?}" , diagnostic. level) ,
14151422 Allow => {
1423+ // Nothing emitted for allowed lints.
14161424 if diagnostic. has_future_breakage ( ) {
14171425 // The side-effect is at the top of this method.
14181426 TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
@@ -1434,12 +1442,12 @@ impl DiagCtxtInner {
14341442 }
14351443 self . fulfilled_expectations . insert ( expect_id. normalize ( ) ) ;
14361444 if let Expect ( _) = diagnostic. level {
1445+ // Nothing emitted here for expected lints.
14371446 TRACK_DIAGNOSTIC ( diagnostic, & mut |_| None ) ;
14381447 self . suppressed_expected_diag = true ;
14391448 return None ;
14401449 }
14411450 }
1442- _ => { }
14431451 }
14441452
14451453 TRACK_DIAGNOSTIC ( diagnostic, & mut |mut diagnostic| {
@@ -1816,16 +1824,13 @@ impl Level {
18161824 matches ! ( * self , FailureNote )
18171825 }
18181826
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 {
18221829 match self {
18231830 Bug | DelayedBug | Fatal | Error | ForceWarning ( _) | FailureNote | Allow
1824- | Expect ( _) => ( true , false ) ,
1825-
1826- Warning | Note | Help => ( true , true ) ,
1831+ | Expect ( _) => false ,
18271832
1828- OnceNote | OnceHelp => ( false , true ) ,
1833+ Warning | Note | Help | OnceNote | OnceHelp => true ,
18291834 }
18301835 }
18311836}
0 commit comments