@@ -24,11 +24,8 @@ pub use self::LintSource::*;
2424use rustc_data_structures:: sync;
2525
2626use crate :: hir;
27- use crate :: hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
28- use crate :: hir:: intravisit;
2927use crate :: lint:: builtin:: BuiltinLintDiagnostics ;
3028use crate :: session:: { DiagnosticMessageId , Session } ;
31- use crate :: ty:: query:: Providers ;
3229use crate :: ty:: TyCtxt ;
3330use crate :: util:: nodemap:: NodeMap ;
3431use errors:: { DiagnosticBuilder , DiagnosticId } ;
@@ -375,7 +372,7 @@ mod context;
375372pub mod internal;
376373mod levels;
377374
378- pub use self :: levels:: { LintLevelMap , LintLevelSets } ;
375+ pub use self :: levels:: { LintLevelMap , LintLevelSets , LintLevelsBuilder } ;
379376
380377#[ derive( Default ) ]
381378pub struct LintBuffer {
@@ -563,122 +560,6 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
563560 attrs. iter ( ) . any ( |attr| Level :: from_symbol ( attr. name_or_empty ( ) ) . is_some ( ) )
564561}
565562
566- fn lint_levels ( tcx : TyCtxt < ' _ > , cnum : CrateNum ) -> & LintLevelMap {
567- assert_eq ! ( cnum, LOCAL_CRATE ) ;
568- let store = & tcx. lint_store ;
569- let mut builder = LintLevelMapBuilder {
570- levels : LintLevelSets :: builder ( tcx. sess , false , & store) ,
571- tcx : tcx,
572- store : store,
573- } ;
574- let krate = tcx. hir ( ) . krate ( ) ;
575-
576- let push = builder. levels . push ( & krate. attrs , & store) ;
577- builder. levels . register_id ( hir:: CRATE_HIR_ID ) ;
578- for macro_def in krate. exported_macros {
579- builder. levels . register_id ( macro_def. hir_id ) ;
580- }
581- intravisit:: walk_crate ( & mut builder, krate) ;
582- builder. levels . pop ( push) ;
583-
584- tcx. arena . alloc ( builder. levels . build_map ( ) )
585- }
586-
587- struct LintLevelMapBuilder < ' a , ' tcx > {
588- levels : levels:: LintLevelsBuilder < ' tcx > ,
589- tcx : TyCtxt < ' tcx > ,
590- store : & ' a LintStore ,
591- }
592-
593- impl LintLevelMapBuilder < ' _ , ' _ > {
594- fn with_lint_attrs < F > ( & mut self , id : hir:: HirId , attrs : & [ ast:: Attribute ] , f : F )
595- where
596- F : FnOnce ( & mut Self ) ,
597- {
598- let push = self . levels . push ( attrs, self . store ) ;
599- if push. changed {
600- self . levels . register_id ( id) ;
601- }
602- f ( self ) ;
603- self . levels . pop ( push) ;
604- }
605- }
606-
607- impl intravisit:: Visitor < ' tcx > for LintLevelMapBuilder < ' _ , ' tcx > {
608- fn nested_visit_map < ' this > ( & ' this mut self ) -> intravisit:: NestedVisitorMap < ' this , ' tcx > {
609- intravisit:: NestedVisitorMap :: All ( & self . tcx . hir ( ) )
610- }
611-
612- fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
613- self . with_lint_attrs ( param. hir_id , & param. attrs , |builder| {
614- intravisit:: walk_param ( builder, param) ;
615- } ) ;
616- }
617-
618- fn visit_item ( & mut self , it : & ' tcx hir:: Item < ' tcx > ) {
619- self . with_lint_attrs ( it. hir_id , & it. attrs , |builder| {
620- intravisit:: walk_item ( builder, it) ;
621- } ) ;
622- }
623-
624- fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
625- self . with_lint_attrs ( it. hir_id , & it. attrs , |builder| {
626- intravisit:: walk_foreign_item ( builder, it) ;
627- } )
628- }
629-
630- fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
631- self . with_lint_attrs ( e. hir_id , & e. attrs , |builder| {
632- intravisit:: walk_expr ( builder, e) ;
633- } )
634- }
635-
636- fn visit_struct_field ( & mut self , s : & ' tcx hir:: StructField < ' tcx > ) {
637- self . with_lint_attrs ( s. hir_id , & s. attrs , |builder| {
638- intravisit:: walk_struct_field ( builder, s) ;
639- } )
640- }
641-
642- fn visit_variant (
643- & mut self ,
644- v : & ' tcx hir:: Variant < ' tcx > ,
645- g : & ' tcx hir:: Generics < ' tcx > ,
646- item_id : hir:: HirId ,
647- ) {
648- self . with_lint_attrs ( v. id , & v. attrs , |builder| {
649- intravisit:: walk_variant ( builder, v, g, item_id) ;
650- } )
651- }
652-
653- fn visit_local ( & mut self , l : & ' tcx hir:: Local < ' tcx > ) {
654- self . with_lint_attrs ( l. hir_id , & l. attrs , |builder| {
655- intravisit:: walk_local ( builder, l) ;
656- } )
657- }
658-
659- fn visit_arm ( & mut self , a : & ' tcx hir:: Arm < ' tcx > ) {
660- self . with_lint_attrs ( a. hir_id , & a. attrs , |builder| {
661- intravisit:: walk_arm ( builder, a) ;
662- } )
663- }
664-
665- fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem < ' tcx > ) {
666- self . with_lint_attrs ( trait_item. hir_id , & trait_item. attrs , |builder| {
667- intravisit:: walk_trait_item ( builder, trait_item) ;
668- } ) ;
669- }
670-
671- fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
672- self . with_lint_attrs ( impl_item. hir_id , & impl_item. attrs , |builder| {
673- intravisit:: walk_impl_item ( builder, impl_item) ;
674- } ) ;
675- }
676- }
677-
678- pub fn provide ( providers : & mut Providers < ' _ > ) {
679- providers. lint_levels = lint_levels;
680- }
681-
682563/// Returns whether `span` originates in a foreign crate's external macro.
683564///
684565/// This is used to test whether a lint should not even begin to figure out whether it should
0 commit comments