@@ -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 } ;
@@ -39,8 +36,7 @@ use rustc_span::Span;
3936use syntax:: ast;
4037
4138pub use crate :: lint:: context:: {
42- check_ast_crate, check_crate, late_lint_mod, BufferedEarlyLint , CheckLintNameResult ,
43- EarlyContext , LateContext , LintContext , LintStore ,
39+ BufferedEarlyLint , CheckLintNameResult , EarlyContext , LateContext , LintContext , LintStore ,
4440} ;
4541
4642pub use rustc_session:: lint:: { FutureIncompatibleInfo , Level , Lint , LintId } ;
@@ -376,11 +372,11 @@ mod context;
376372pub mod internal;
377373mod levels;
378374
379- pub use self :: levels:: { LintLevelMap , LintLevelSets } ;
375+ pub use self :: levels:: { LintLevelMap , LintLevelSets , LintLevelsBuilder } ;
380376
381377#[ derive( Default ) ]
382378pub struct LintBuffer {
383- map : NodeMap < Vec < BufferedEarlyLint > > ,
379+ pub map : NodeMap < Vec < BufferedEarlyLint > > ,
384380}
385381
386382impl LintBuffer {
@@ -405,7 +401,7 @@ impl LintBuffer {
405401 }
406402 }
407403
408- fn take ( & mut self , id : ast:: NodeId ) -> Vec < BufferedEarlyLint > {
404+ pub fn take ( & mut self , id : ast:: NodeId ) -> Vec < BufferedEarlyLint > {
409405 self . map . remove ( & id) . unwrap_or_default ( )
410406 }
411407
@@ -564,122 +560,6 @@ pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool {
564560 attrs. iter ( ) . any ( |attr| Level :: from_symbol ( attr. name_or_empty ( ) ) . is_some ( ) )
565561}
566562
567- fn lint_levels ( tcx : TyCtxt < ' _ > , cnum : CrateNum ) -> & LintLevelMap {
568- assert_eq ! ( cnum, LOCAL_CRATE ) ;
569- let store = & tcx. lint_store ;
570- let mut builder = LintLevelMapBuilder {
571- levels : LintLevelSets :: builder ( tcx. sess , false , & store) ,
572- tcx : tcx,
573- store : store,
574- } ;
575- let krate = tcx. hir ( ) . krate ( ) ;
576-
577- let push = builder. levels . push ( & krate. attrs , & store) ;
578- builder. levels . register_id ( hir:: CRATE_HIR_ID ) ;
579- for macro_def in krate. exported_macros {
580- builder. levels . register_id ( macro_def. hir_id ) ;
581- }
582- intravisit:: walk_crate ( & mut builder, krate) ;
583- builder. levels . pop ( push) ;
584-
585- tcx. arena . alloc ( builder. levels . build_map ( ) )
586- }
587-
588- struct LintLevelMapBuilder < ' a , ' tcx > {
589- levels : levels:: LintLevelsBuilder < ' tcx > ,
590- tcx : TyCtxt < ' tcx > ,
591- store : & ' a LintStore ,
592- }
593-
594- impl LintLevelMapBuilder < ' _ , ' _ > {
595- fn with_lint_attrs < F > ( & mut self , id : hir:: HirId , attrs : & [ ast:: Attribute ] , f : F )
596- where
597- F : FnOnce ( & mut Self ) ,
598- {
599- let push = self . levels . push ( attrs, self . store ) ;
600- if push. changed {
601- self . levels . register_id ( id) ;
602- }
603- f ( self ) ;
604- self . levels . pop ( push) ;
605- }
606- }
607-
608- impl intravisit:: Visitor < ' tcx > for LintLevelMapBuilder < ' _ , ' tcx > {
609- fn nested_visit_map < ' this > ( & ' this mut self ) -> intravisit:: NestedVisitorMap < ' this , ' tcx > {
610- intravisit:: NestedVisitorMap :: All ( & self . tcx . hir ( ) )
611- }
612-
613- fn visit_param ( & mut self , param : & ' tcx hir:: Param < ' tcx > ) {
614- self . with_lint_attrs ( param. hir_id , & param. attrs , |builder| {
615- intravisit:: walk_param ( builder, param) ;
616- } ) ;
617- }
618-
619- fn visit_item ( & mut self , it : & ' tcx hir:: Item < ' tcx > ) {
620- self . with_lint_attrs ( it. hir_id , & it. attrs , |builder| {
621- intravisit:: walk_item ( builder, it) ;
622- } ) ;
623- }
624-
625- fn visit_foreign_item ( & mut self , it : & ' tcx hir:: ForeignItem < ' tcx > ) {
626- self . with_lint_attrs ( it. hir_id , & it. attrs , |builder| {
627- intravisit:: walk_foreign_item ( builder, it) ;
628- } )
629- }
630-
631- fn visit_expr ( & mut self , e : & ' tcx hir:: Expr < ' tcx > ) {
632- self . with_lint_attrs ( e. hir_id , & e. attrs , |builder| {
633- intravisit:: walk_expr ( builder, e) ;
634- } )
635- }
636-
637- fn visit_struct_field ( & mut self , s : & ' tcx hir:: StructField < ' tcx > ) {
638- self . with_lint_attrs ( s. hir_id , & s. attrs , |builder| {
639- intravisit:: walk_struct_field ( builder, s) ;
640- } )
641- }
642-
643- fn visit_variant (
644- & mut self ,
645- v : & ' tcx hir:: Variant < ' tcx > ,
646- g : & ' tcx hir:: Generics < ' tcx > ,
647- item_id : hir:: HirId ,
648- ) {
649- self . with_lint_attrs ( v. id , & v. attrs , |builder| {
650- intravisit:: walk_variant ( builder, v, g, item_id) ;
651- } )
652- }
653-
654- fn visit_local ( & mut self , l : & ' tcx hir:: Local < ' tcx > ) {
655- self . with_lint_attrs ( l. hir_id , & l. attrs , |builder| {
656- intravisit:: walk_local ( builder, l) ;
657- } )
658- }
659-
660- fn visit_arm ( & mut self , a : & ' tcx hir:: Arm < ' tcx > ) {
661- self . with_lint_attrs ( a. hir_id , & a. attrs , |builder| {
662- intravisit:: walk_arm ( builder, a) ;
663- } )
664- }
665-
666- fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem < ' tcx > ) {
667- self . with_lint_attrs ( trait_item. hir_id , & trait_item. attrs , |builder| {
668- intravisit:: walk_trait_item ( builder, trait_item) ;
669- } ) ;
670- }
671-
672- fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem < ' tcx > ) {
673- self . with_lint_attrs ( impl_item. hir_id , & impl_item. attrs , |builder| {
674- intravisit:: walk_impl_item ( builder, impl_item) ;
675- } ) ;
676- }
677- }
678-
679- pub fn provide ( providers : & mut Providers < ' _ > ) {
680- providers. lint_levels = lint_levels;
681- }
682-
683563/// Returns whether `span` originates in a foreign crate's external macro.
684564///
685565/// This is used to test whether a lint should not even begin to figure out whether it should
0 commit comments