@@ -307,6 +307,10 @@ impl Lint {
307
307
. map ( |( _, ( l, r, _) ) | ( l, r) )
308
308
. unwrap ( )
309
309
}
310
+
311
+ fn emitted_source ( & self , lint_level : LintLevel , reason : LintLevelReason ) -> String {
312
+ format ! ( "`cargo::{}` is set to `{lint_level}` {reason}" , self . name, )
313
+ }
310
314
}
311
315
312
316
#[ derive( Copy , Clone , Debug , PartialEq ) ]
@@ -329,6 +333,10 @@ impl Display for LintLevel {
329
333
}
330
334
331
335
impl LintLevel {
336
+ pub fn is_error ( & self ) -> bool {
337
+ self == & LintLevel :: Forbid || self == & LintLevel :: Deny
338
+ }
339
+
332
340
pub fn to_diagnostic_level ( self ) -> Level {
333
341
match self {
334
342
LintLevel :: Allow => unreachable ! ( "allow does not map to a diagnostic level" ) ,
@@ -440,15 +448,12 @@ pub fn check_im_a_teapot(
440
448
. package ( )
441
449
. is_some_and ( |p| p. im_a_teapot . is_some ( ) )
442
450
{
443
- if lint_level == LintLevel :: Forbid || lint_level == LintLevel :: Deny {
451
+ if lint_level. is_error ( ) {
444
452
* error_count += 1 ;
445
453
}
446
454
let level = lint_level. to_diagnostic_level ( ) ;
447
455
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) ;
452
457
453
458
let key_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , false ) . unwrap ( ) ;
454
459
let value_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , true ) . unwrap ( ) ;
@@ -514,7 +519,7 @@ fn output_unknown_lints(
514
519
let level = lint_level. to_diagnostic_level ( ) ;
515
520
let mut emitted_source = None ;
516
521
for lint_name in unknown_lints {
517
- if lint_level == LintLevel :: Forbid || lint_level == LintLevel :: Deny {
522
+ if lint_level. is_error ( ) {
518
523
* error_count += 1 ;
519
524
}
520
525
let title = format ! ( "{}: `{lint_name}`" , UNKNOWN_LINTS . desc) ;
@@ -530,6 +535,12 @@ fn output_unknown_lints(
530
535
let help =
531
536
matching. map ( |( name, kind) | format ! ( "there is a {kind} with a similar name: `{name}`" ) ) ;
532
537
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
+
533
544
let mut message = if let Some ( span) =
534
545
get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false )
535
546
{
@@ -564,28 +575,21 @@ fn output_unknown_lints(
564
575
} else {
565
576
Level :: Note . title ( & second_title)
566
577
} ;
578
+ footers. push ( inherited_note) ;
567
579
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
+ )
577
586
} ;
578
587
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
-
587
588
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) ;
589
593
}
590
594
591
595
gctx. shell ( ) . print_message ( message) ?;
0 commit comments