@@ -307,6 +307,10 @@ impl Lint {
307307 . map ( |( _, ( l, r, _) ) | ( l, r) )
308308 . unwrap ( )
309309 }
310+
311+ fn emitted_source ( & self , lint_level : LintLevel , reason : LintLevelReason ) -> String {
312+ format ! ( "`cargo::{}` is set to `{lint_level}` {reason}" , self . name, )
313+ }
310314}
311315
312316#[ derive( Copy , Clone , Debug , PartialEq ) ]
@@ -329,6 +333,10 @@ impl Display for LintLevel {
329333}
330334
331335impl LintLevel {
336+ pub fn is_error ( & self ) -> bool {
337+ self == & LintLevel :: Forbid || self == & LintLevel :: Deny
338+ }
339+
332340 pub fn to_diagnostic_level ( self ) -> Level {
333341 match self {
334342 LintLevel :: Allow => unreachable ! ( "allow does not map to a diagnostic level" ) ,
@@ -440,15 +448,12 @@ pub fn check_im_a_teapot(
440448 . package ( )
441449 . is_some_and ( |p| p. im_a_teapot . is_some ( ) )
442450 {
443- if lint_level == LintLevel :: Forbid || lint_level == LintLevel :: Deny {
451+ if lint_level. is_error ( ) {
444452 * error_count += 1 ;
445453 }
446454 let level = lint_level. to_diagnostic_level ( ) ;
447455 let manifest_path = rel_cwd_manifest_path ( path, gctx) ;
448- let emitted_reason = format ! (
449- "`cargo::{}` is set to `{lint_level}` {reason}" ,
450- IM_A_TEAPOT . name
451- ) ;
456+ let emitted_reason = IM_A_TEAPOT . emitted_source ( lint_level, reason) ;
452457
453458 let key_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , false ) . unwrap ( ) ;
454459 let value_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , true ) . unwrap ( ) ;
@@ -514,7 +519,7 @@ fn output_unknown_lints(
514519 let level = lint_level. to_diagnostic_level ( ) ;
515520 let mut emitted_source = None ;
516521 for lint_name in unknown_lints {
517- if lint_level == LintLevel :: Forbid || lint_level == LintLevel :: Deny {
522+ if lint_level. is_error ( ) {
518523 * error_count += 1 ;
519524 }
520525 let title = format ! ( "{}: `{lint_name}`" , UNKNOWN_LINTS . desc) ;
@@ -530,6 +535,12 @@ fn output_unknown_lints(
530535 let help =
531536 matching. map ( |( name, kind) | format ! ( "there is a {kind} with a similar name: `{name}`" ) ) ;
532537
538+ let mut footers = Vec :: new ( ) ;
539+ if emitted_source. is_none ( ) {
540+ emitted_source = Some ( UNKNOWN_LINTS . emitted_source ( lint_level, reason) ) ;
541+ footers. push ( Level :: Note . title ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
542+ }
543+
533544 let mut message = if let Some ( span) =
534545 get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false )
535546 {
@@ -564,28 +575,21 @@ fn output_unknown_lints(
564575 } else {
565576 Level :: Note . title ( & second_title)
566577 } ;
578+ footers. push ( inherited_note) ;
567579
568- level
569- . title ( & title)
570- . snippet (
571- Snippet :: source ( ws_contents)
572- . origin ( & ws_path)
573- . annotation ( Level :: Error . span ( lint_span) )
574- . fold ( true ) ,
575- )
576- . footer ( inherited_note)
580+ level. title ( & title) . snippet (
581+ Snippet :: source ( ws_contents)
582+ . origin ( & ws_path)
583+ . annotation ( Level :: Error . span ( lint_span) )
584+ . fold ( true ) ,
585+ )
577586 } ;
578587
579- if emitted_source. is_none ( ) {
580- emitted_source = Some ( format ! (
581- "`cargo::{}` is set to `{lint_level}` {reason}" ,
582- UNKNOWN_LINTS . name
583- ) ) ;
584- message = message. footer ( Level :: Note . title ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
585- }
586-
587588 if let Some ( help) = help. as_ref ( ) {
588- message = message. footer ( Level :: Help . title ( help) ) ;
589+ footers. push ( Level :: Help . title ( help) ) ;
590+ }
591+ for footer in footers {
592+ message = message. footer ( footer) ;
589593 }
590594
591595 gctx. shell ( ) . print_message ( message) ?;
0 commit comments