@@ -480,26 +480,44 @@ impl<'a> LintExtractor<'a> {
480
480
. map ( |msg| msg[ "rendered" ] . as_str ( ) . expect ( "rendered field should exist" ) . to_string ( ) )
481
481
. collect ( ) ;
482
482
if matches. is_empty ( ) {
483
- // Some lints override their code to something else (E0566).
484
- // Try to find something that looks like it could be our lint.
485
- let matches: Vec < _ > = msgs. iter ( ) . filter ( |msg|
486
- matches ! ( & msg[ "rendered" ] , serde_json:: Value :: String ( s) if s. contains( name) ) )
487
- . map ( |msg| msg[ "rendered" ] . as_str ( ) . expect ( "rendered field should exist" ) . to_string ( ) )
488
- . collect ( ) ;
489
- 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| {
485
+ matches ! ( & msg[ "code" ] [ "code" ] , serde_json:: Value :: String ( s) if s=="unknown_lints" )
486
+ && matches ! ( & msg[ "message" ] , serde_json:: Value :: String ( s) if s. contains( name) )
487
+ } ) {
490
488
let rendered: Vec < & str > =
491
489
msgs. iter ( ) . filter_map ( |msg| msg[ "rendered" ] . as_str ( ) ) . collect ( ) ;
492
490
let non_json: Vec < & str > =
493
491
stderr. lines ( ) . filter ( |line| !line. starts_with ( '{' ) ) . collect ( ) ;
494
492
Err ( format ! (
495
- "did not find lint `{}` in output of example, got :\n {}\n {}" ,
493
+ "lint `{}` is unstable and must be enabled in example. see :\n {}\n {}" ,
496
494
name,
495
+ rendered. join( "\n " ) ,
497
496
non_json. join( "\n " ) ,
498
- rendered. join( "\n " )
499
497
)
500
498
. into ( ) )
501
499
} else {
502
- Ok ( matches. join ( "\n " ) )
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
+ }
503
521
}
504
522
} else {
505
523
Ok ( matches. join ( "\n " ) )
0 commit comments