@@ -291,16 +291,13 @@ impl LintStore {
291
291
self . by_name . insert ( name. into ( ) , Removed ( reason. into ( ) ) ) ;
292
292
}
293
293
294
- #[ allow( unused_variables) ]
295
- fn find_lint ( & self , lint_name : & str , sess : & Session , span : Option < Span > )
296
- -> Result < LintId , FindLintError >
297
- {
294
+ fn find_lint ( & self , lint_name : & str ) -> Result < LintId , FindLintError > {
298
295
match self . by_name . get ( lint_name) {
299
296
Some ( & Id ( lint_id) ) => Ok ( lint_id) ,
300
297
Some ( & Renamed ( _, lint_id) ) => {
301
298
Ok ( lint_id)
302
299
} ,
303
- Some ( & Removed ( ref reason ) ) => {
300
+ Some ( & Removed ( _ ) ) => {
304
301
Err ( FindLintError :: Removed )
305
302
} ,
306
303
None => Err ( FindLintError :: NotFound )
@@ -313,7 +310,7 @@ impl LintStore {
313
310
& lint_name[ ..] , level) ;
314
311
315
312
let lint_flag_val = Symbol :: intern ( & lint_name) ;
316
- match self . find_lint ( & lint_name[ ..] , sess , None ) {
313
+ match self . find_lint ( & lint_name[ ..] ) {
317
314
Ok ( lint_id) => self . levels . set ( lint_id, ( level, CommandLine ( lint_flag_val) ) ) ,
318
315
Err ( FindLintError :: Removed ) => { }
319
316
Err ( _) => {
@@ -724,21 +721,22 @@ pub trait LintContext<'tcx>: Sized {
724
721
let mut pushed = 0 ;
725
722
726
723
for result in gather_attrs ( attrs) {
727
- let v = match result {
724
+ let ( is_group , lint_level_spans ) = match result {
728
725
Err ( span) => {
729
726
span_err ! ( self . sess( ) , span, E0452 ,
730
727
"malformed lint attribute" ) ;
731
728
continue ;
732
729
}
733
730
Ok ( ( lint_name, level, span) ) => {
734
- match self . lints ( ) . find_lint ( & lint_name. as_str ( ) , & self . sess ( ) , Some ( span ) ) {
735
- Ok ( lint_id) => vec ! [ ( lint_id, level, span) ] ,
731
+ match self . lints ( ) . find_lint ( & lint_name. as_str ( ) ) {
732
+ Ok ( lint_id) => ( false , vec ! [ ( lint_id, level, span) ] ) ,
736
733
Err ( FindLintError :: NotFound ) => {
737
734
match self . lints ( ) . lint_groups . get ( & * lint_name. as_str ( ) ) {
738
- Some ( & ( ref v, _) ) => v. iter ( )
735
+ Some ( & ( ref v, _) ) => ( true ,
736
+ v. iter ( )
739
737
. map ( |lint_id : & LintId |
740
738
( * lint_id, level, span) )
741
- . collect ( ) ,
739
+ . collect ( ) ) ,
742
740
None => {
743
741
// The lint or lint group doesn't exist.
744
742
// This is an error, but it was handled
@@ -754,14 +752,18 @@ pub trait LintContext<'tcx>: Sized {
754
752
755
753
let lint_attr_name = result. expect ( "lint attribute should be well-formed" ) . 0 ;
756
754
757
- for ( lint_id, level, span) in v {
755
+ for ( lint_id, level, span) in lint_level_spans {
758
756
let ( now, now_source) = self . lint_sess ( ) . get_source ( lint_id) ;
759
757
if now == Forbid && level != Forbid {
760
- let lint_name = lint_id. to_string ( ) ;
758
+ let forbidden_lint_name = match now_source {
759
+ LintSource :: Default => lint_id. to_string ( ) ,
760
+ LintSource :: Node ( name, _) => name. to_string ( ) ,
761
+ LintSource :: CommandLine ( name) => name. to_string ( ) ,
762
+ } ;
761
763
let mut diag_builder = struct_span_err ! ( self . sess( ) , span, E0453 ,
762
764
"{}({}) overruled by outer forbid({})" ,
763
- level. as_str( ) , lint_name ,
764
- lint_name ) ;
765
+ level. as_str( ) , lint_attr_name ,
766
+ forbidden_lint_name ) ;
765
767
diag_builder. span_label ( span, "overruled by previous forbid" ) ;
766
768
match now_source {
767
769
LintSource :: Default => & mut diag_builder,
@@ -772,7 +774,10 @@ pub trait LintContext<'tcx>: Sized {
772
774
LintSource :: CommandLine ( _) => {
773
775
diag_builder. note ( "`forbid` lint level was set on command line" )
774
776
}
775
- } . emit ( )
777
+ } . emit ( ) ;
778
+ if is_group { // don't set a separate error for every lint in the group
779
+ break ;
780
+ }
776
781
} else if now != level {
777
782
let cx = self . lint_sess_mut ( ) ;
778
783
cx. stack . push ( ( lint_id, ( now, now_source) ) ) ;
@@ -1420,7 +1425,7 @@ impl Decodable for LintId {
1420
1425
fn decode < D : Decoder > ( d : & mut D ) -> Result < LintId , D :: Error > {
1421
1426
let s = d. read_str ( ) ?;
1422
1427
ty:: tls:: with ( |tcx| {
1423
- match tcx. sess . lint_store . borrow ( ) . find_lint ( & s, tcx . sess , None ) {
1428
+ match tcx. sess . lint_store . borrow ( ) . find_lint ( & s) {
1424
1429
Ok ( id) => Ok ( id) ,
1425
1430
Err ( _) => panic ! ( "invalid lint-id `{}`" , s) ,
1426
1431
}
0 commit comments