@@ -473,55 +473,61 @@ impl<'a> LintExtractor<'a> {
473
473
. filter ( |line| line. starts_with ( '{' ) )
474
474
. map ( serde_json:: from_str)
475
475
. collect :: < Result < Vec < serde_json:: Value > , _ > > ( ) ?;
476
+
476
477
// First try to find the messages with the `code` field set to our lint.
477
478
let matches: Vec < _ > = msgs
478
479
. iter ( )
479
480
. filter ( |msg| matches ! ( & msg[ "code" ] [ "code" ] , serde_json:: Value :: String ( s) if s==name) )
480
481
. map ( |msg| msg[ "rendered" ] . as_str ( ) . expect ( "rendered field should exist" ) . to_string ( ) )
481
482
. collect ( ) ;
482
- if matches. is_empty ( ) {
483
- // Try to detect if an unstable lint forgot to enable a `#![feature(..)]`.
484
- if name != "test_unstable_lint" && msgs. iter ( ) . any ( |msg| {
483
+ if !matches. is_empty ( ) {
484
+ return Ok ( matches. join ( "\n " ) ) ;
485
+ }
486
+
487
+ // Try to detect if an unstable lint forgot to enable a `#![feature(..)]`.
488
+ // Specifically exclude `test_unstable_lint` which exercises this on purpose.
489
+ if name != "test_unstable_lint"
490
+ && msgs. iter ( ) . any ( |msg| {
485
491
matches ! ( & msg[ "code" ] [ "code" ] , serde_json:: Value :: String ( s) if s=="unknown_lints" )
486
492
&& matches ! ( & msg[ "message" ] , serde_json:: Value :: String ( s) if s. contains( name) )
487
- } ) {
488
- let rendered: Vec < & str > =
489
- msgs. iter ( ) . filter_map ( |msg| msg[ "rendered" ] . as_str ( ) ) . collect ( ) ;
490
- let non_json: Vec < & str > =
491
- stderr. lines ( ) . filter ( |line| !line. starts_with ( '{' ) ) . collect ( ) ;
492
- Err ( format ! (
493
- "lint `{}` is unstable and must be enabled in example. see:\n {}\n {}" ,
494
- name,
495
- rendered. join( "\n " ) ,
496
- non_json. join( "\n " ) ,
497
- )
498
- . into ( ) )
499
- } else {
500
- // Some lints override their code to something else (E0566).
501
- // Try to find something that looks like it could be our lint.
502
- let matches: Vec < _ > = msgs. iter ( ) . filter ( |msg|
503
- matches ! ( & msg[ "rendered" ] , serde_json:: Value :: String ( s) if s. contains( name) ) )
504
- . map ( |msg| msg[ "rendered" ] . as_str ( ) . expect ( "rendered field should exist" ) . to_string ( ) )
505
- . collect ( ) ;
506
- if matches. is_empty ( ) {
507
- let rendered: Vec < & str > =
508
- msgs. iter ( ) . filter_map ( |msg| msg[ "rendered" ] . as_str ( ) ) . collect ( ) ;
509
- let non_json: Vec < & str > =
510
- stderr. lines ( ) . filter ( |line| !line. starts_with ( '{' ) ) . collect ( ) ;
511
- Err ( format ! (
512
- "did not find lint `{}` in output of example, got:\n {}\n {}" ,
513
- name,
514
- non_json. join( "\n " ) ,
515
- rendered. join( "\n " )
516
- )
517
- . into ( ) )
518
- } else {
519
- Ok ( matches. join ( "\n " ) )
520
- }
521
- }
522
- } else {
523
- Ok ( matches. join ( "\n " ) )
493
+ } )
494
+ {
495
+ let rendered: Vec < & str > =
496
+ msgs. iter ( ) . filter_map ( |msg| msg[ "rendered" ] . as_str ( ) ) . collect ( ) ;
497
+ let non_json: Vec < & str > =
498
+ stderr. lines ( ) . filter ( |line| !line. starts_with ( '{' ) ) . collect ( ) ;
499
+ return Err ( format ! (
500
+ "lint `{}` is unstable and must be enabled in example. see:\n {}\n {}" ,
501
+ name,
502
+ rendered. join( "\n " ) ,
503
+ non_json. join( "\n " ) ,
504
+ )
505
+ . into ( ) ) ;
524
506
}
507
+
508
+ // Some lints override their code to something else (E0566).
509
+ // Try to find something that looks like it could be our lint.
510
+ let matches: Vec < _ > = msgs
511
+ . iter ( )
512
+ . filter (
513
+ |msg| matches ! ( & msg[ "rendered" ] , serde_json:: Value :: String ( s) if s. contains( name) ) ,
514
+ )
515
+ . map ( |msg| msg[ "rendered" ] . as_str ( ) . expect ( "rendered field should exist" ) . to_string ( ) )
516
+ . collect ( ) ;
517
+ if !matches. is_empty ( ) {
518
+ return Ok ( matches. join ( "\n " ) ) ;
519
+ }
520
+
521
+ // Otherwise, give a descriptive error.
522
+ let rendered: Vec < & str > = msgs. iter ( ) . filter_map ( |msg| msg[ "rendered" ] . as_str ( ) ) . collect ( ) ;
523
+ let non_json: Vec < & str > = stderr. lines ( ) . filter ( |line| !line. starts_with ( '{' ) ) . collect ( ) ;
524
+ Err ( format ! (
525
+ "did not find lint `{}` in output of example, got:\n {}\n {}" ,
526
+ name,
527
+ non_json. join( "\n " ) ,
528
+ rendered. join( "\n " )
529
+ )
530
+ . into ( ) )
525
531
}
526
532
527
533
/// Saves the mdbook lint chapters at the given path.
0 commit comments