@@ -72,7 +72,7 @@ use syntax::parse::token;
72
72
use syntax:: visit:: Visitor ;
73
73
use syntax:: { ast, ast_util, visit} ;
74
74
75
- #[ deriving( Clone , Show , Eq , Ord , TotalEq , TotalOrd , Hash ) ]
75
+ #[ deriving( Clone , Eq , Ord , TotalEq , TotalOrd ) ]
76
76
pub enum Lint {
77
77
CTypes ,
78
78
UnusedImports ,
@@ -94,7 +94,6 @@ pub enum Lint {
94
94
UnknownFeatures ,
95
95
UnknownCrateType ,
96
96
UnsignedNegate ,
97
- VariantSizeDifference ,
98
97
99
98
ManagedHeapMemory ,
100
99
OwnedHeapMemory ,
@@ -148,9 +147,8 @@ pub struct LintSpec {
148
147
149
148
pub type LintDict = HashMap < & ' static str , LintSpec > ;
150
149
151
- // this is public for the lints that run in trans
152
150
#[ deriving( Eq ) ]
153
- pub enum LintSource {
151
+ enum LintSource {
154
152
Node ( Span ) ,
155
153
Default ,
156
154
CommandLine
@@ -409,13 +407,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
409
407
default : Warn
410
408
} ) ,
411
409
412
- ( "variant_size_difference" ,
413
- LintSpec {
414
- lint : VariantSizeDifference ,
415
- desc : "detects enums with widely varying variant sizes" ,
416
- default : Allow ,
417
- } ) ,
418
-
419
410
( "unused_must_use" ,
420
411
LintSpec {
421
412
lint : UnusedMustUse ,
@@ -454,78 +445,30 @@ pub fn get_lint_dict() -> LintDict {
454
445
}
455
446
456
447
struct Context < ' a > {
457
- /// All known lint modes (string versions)
448
+ // All known lint modes (string versions)
458
449
dict : LintDict ,
459
- /// Current levels of each lint warning
450
+ // Current levels of each lint warning
460
451
cur : SmallIntMap < ( Level , LintSource ) > ,
461
- /// Context we're checking in (used to access fields like sess)
452
+ // context we're checking in (used to access fields like sess)
462
453
tcx : & ' a ty:: ctxt ,
463
- /// Items exported by the crate; used by the missing_doc lint.
454
+ // Items exported by the crate; used by the missing_doc lint.
464
455
exported_items : & ' a privacy:: ExportedItems ,
465
- /// The id of the current `ast::StructDef` being walked.
456
+ // The id of the current `ast::StructDef` being walked.
466
457
cur_struct_def_id : ast:: NodeId ,
467
- /// Whether some ancestor of the current node was marked
468
- /// #[doc(hidden)].
458
+ // Whether some ancestor of the current node was marked
459
+ // #[doc(hidden)].
469
460
is_doc_hidden : bool ,
470
461
471
- /// When recursing into an attributed node of the ast which modifies lint
472
- /// levels, this stack keeps track of the previous lint levels of whatever
473
- /// was modified.
462
+ // When recursing into an attributed node of the ast which modifies lint
463
+ // levels, this stack keeps track of the previous lint levels of whatever
464
+ // was modified.
474
465
lint_stack : Vec < ( Lint , Level , LintSource ) > ,
475
466
476
- /// Id of the last visited negated expression
467
+ // id of the last visited negated expression
477
468
negated_expr_id : ast:: NodeId ,
478
469
479
- /// Ids of structs/enums which have been checked for raw_pointer_deriving
470
+ // ids of structs/enums which have been checked for raw_pointer_deriving
480
471
checked_raw_pointers : NodeSet ,
481
-
482
- /// Level of lints for certain NodeIds, stored here because the body of
483
- /// the lint needs to run in trans.
484
- node_levels : HashMap < ( ast:: NodeId , Lint ) , ( Level , LintSource ) > ,
485
- }
486
-
487
- pub fn emit_lint ( level : Level , src : LintSource , msg : & str , span : Span ,
488
- lint_str : & str , tcx : & ty:: ctxt ) {
489
- if level == Allow { return }
490
-
491
- let mut note = None ;
492
- let msg = match src {
493
- Default => {
494
- format ! ( "{}, \\ #[{}({})] on by default" , msg,
495
- level_to_str( level) , lint_str)
496
- } ,
497
- CommandLine => {
498
- format ! ( "{} [-{} {}]" , msg,
499
- match level {
500
- Warn => 'W' , Deny => 'D' , Forbid => 'F' ,
501
- Allow => fail!( )
502
- } , lint_str. replace( "_" , "-" ) )
503
- } ,
504
- Node ( src) => {
505
- note = Some ( src) ;
506
- msg. to_str ( )
507
- }
508
- } ;
509
-
510
- match level {
511
- Warn => { tcx. sess . span_warn ( span, msg. as_slice ( ) ) ; }
512
- Deny | Forbid => { tcx. sess . span_err ( span, msg. as_slice ( ) ) ; }
513
- Allow => fail ! ( ) ,
514
- }
515
-
516
- for & span in note. iter ( ) {
517
- tcx. sess . span_note ( span, "lint level defined here" ) ;
518
- }
519
- }
520
-
521
- pub fn lint_to_str ( lint : Lint ) -> & ' static str {
522
- for & ( name, lspec) in lint_table. iter ( ) {
523
- if lspec. lint == lint {
524
- return name;
525
- }
526
- }
527
-
528
- fail ! ( "unrecognized lint: {}" , lint) ;
529
472
}
530
473
531
474
impl < ' a > Context < ' a > {
@@ -557,7 +500,7 @@ impl<'a> Context<'a> {
557
500
return * k;
558
501
}
559
502
}
560
- fail ! ( "unregistered lint {}" , lint) ;
503
+ fail ! ( "unregistered lint {:? }" , lint) ;
561
504
}
562
505
563
506
fn span_lint ( & self , lint : Lint , span : Span , msg : & str ) {
@@ -566,8 +509,37 @@ impl<'a> Context<'a> {
566
509
Some ( & ( Warn , src) ) => ( self . get_level ( Warnings ) , src) ,
567
510
Some ( & pair) => pair,
568
511
} ;
512
+ if level == Allow { return }
513
+
514
+ let mut note = None ;
515
+ let msg = match src {
516
+ Default => {
517
+ format_strbuf ! ( "{}, \\ #[{}({})] on by default" ,
518
+ msg,
519
+ level_to_str( level) ,
520
+ self . lint_to_str( lint) )
521
+ } ,
522
+ CommandLine => {
523
+ format ! ( "{} [-{} {}]" , msg,
524
+ match level {
525
+ Warn => 'W' , Deny => 'D' , Forbid => 'F' ,
526
+ Allow => fail!( )
527
+ } , self . lint_to_str( lint) . replace( "_" , "-" ) )
528
+ } ,
529
+ Node ( src) => {
530
+ note = Some ( src) ;
531
+ msg. to_str ( )
532
+ }
533
+ } ;
534
+ match level {
535
+ Warn => self . tcx . sess . span_warn ( span, msg. as_slice ( ) ) ,
536
+ Deny | Forbid => self . tcx . sess . span_err ( span, msg. as_slice ( ) ) ,
537
+ Allow => fail ! ( ) ,
538
+ }
569
539
570
- emit_lint ( level, src, msg, span, self . lint_to_str ( lint) , self . tcx ) ;
540
+ for & span in note. iter ( ) {
541
+ self . tcx . sess . span_note ( span, "lint level defined here" ) ;
542
+ }
571
543
}
572
544
573
545
/**
@@ -646,8 +618,8 @@ impl<'a> Context<'a> {
646
618
}
647
619
}
648
620
649
- /// Check that every lint from the list of attributes satisfies `f`.
650
- /// Return true if that's the case. Otherwise return false.
621
+ // Check that every lint from the list of attributes satisfies `f`.
622
+ // Return true if that's the case. Otherwise return false.
651
623
pub fn each_lint ( sess : & session:: Session ,
652
624
attrs : & [ ast:: Attribute ] ,
653
625
f : |@ast:: MetaItem , Level , InternedString | -> bool)
@@ -681,8 +653,8 @@ pub fn each_lint(sess: &session::Session,
681
653
true
682
654
}
683
655
684
- /// Check from a list of attributes if it contains the appropriate
685
- /// `#[level(lintname)]` attribute (e.g. `#[allow(dead_code)]).
656
+ // Check from a list of attributes if it contains the appropriate
657
+ // `#[level(lintname)]` attribute (e.g. `#[allow(dead_code)]).
686
658
pub fn contains_lint ( attrs : & [ ast:: Attribute ] ,
687
659
level : Level ,
688
660
lintname : & ' static str )
@@ -1767,24 +1739,9 @@ fn check_stability(cx: &Context, e: &ast::Expr) {
1767
1739
cx. span_lint ( lint, e. span , msg. as_slice ( ) ) ;
1768
1740
}
1769
1741
1770
- fn check_enum_variant_sizes ( cx : & mut Context , it : & ast:: Item ) {
1771
- match it. node {
1772
- ast:: ItemEnum ( ..) => {
1773
- match cx. cur . find ( & ( VariantSizeDifference as uint ) ) {
1774
- Some ( & ( lvl, src) ) if lvl != Allow => {
1775
- cx. node_levels . insert ( ( it. id , VariantSizeDifference ) , ( lvl, src) ) ;
1776
- } ,
1777
- _ => { }
1778
- }
1779
- } ,
1780
- _ => { }
1781
- }
1782
- }
1783
-
1784
1742
impl < ' a > Visitor < ( ) > for Context < ' a > {
1785
1743
fn visit_item ( & mut self , it : & ast:: Item , _: ( ) ) {
1786
1744
self . with_lint_attrs ( it. attrs . as_slice ( ) , |cx| {
1787
- check_enum_variant_sizes ( cx, it) ;
1788
1745
check_item_ctypes ( cx, it) ;
1789
1746
check_item_non_camel_case_types ( cx, it) ;
1790
1747
check_item_non_uppercase_statics ( cx, it) ;
@@ -1976,7 +1933,6 @@ pub fn check_crate(tcx: &ty::ctxt,
1976
1933
lint_stack : Vec :: new ( ) ,
1977
1934
negated_expr_id : -1 ,
1978
1935
checked_raw_pointers : NodeSet :: new ( ) ,
1979
- node_levels : HashMap :: new ( ) ,
1980
1936
} ;
1981
1937
1982
1938
// Install default lint levels, followed by the command line levels, and
@@ -2013,11 +1969,13 @@ pub fn check_crate(tcx: &ty::ctxt,
2013
1969
// in the iteration code.
2014
1970
for ( id, v) in tcx. sess . lints . borrow ( ) . iter ( ) {
2015
1971
for & ( lint, span, ref msg) in v. iter ( ) {
2016
- tcx. sess . span_bug ( span, format ! ( "unprocessed lint {} at {}: {}" ,
2017
- lint, tcx. map. node_to_str( * id) , * msg) . as_slice ( ) )
1972
+ tcx. sess . span_bug ( span,
1973
+ format ! ( "unprocessed lint {:?} at {}: {}" ,
1974
+ lint,
1975
+ tcx. map. node_to_str( * id) ,
1976
+ * msg) . as_slice ( ) )
2018
1977
}
2019
1978
}
2020
1979
2021
1980
tcx. sess . abort_if_errors ( ) ;
2022
- * tcx. node_lint_levels . borrow_mut ( ) = cx. node_levels ;
2023
1981
}
0 commit comments