@@ -73,6 +73,8 @@ struct AstValidator<'a> {
7373 /// these booleans.
7474 warning_period_57979_didnt_record_next_impl_trait : bool ,
7575 warning_period_57979_impl_trait_in_proj : bool ,
76+
77+ lint_buffer : & ' a mut lint:: LintBuffer ,
7678}
7779
7880impl < ' a > AstValidator < ' a > {
@@ -229,7 +231,7 @@ impl<'a> AstValidator<'a> {
229231 err. emit ( ) ;
230232 }
231233
232- fn check_decl_no_pat < ReportFn : Fn ( Span , bool ) > ( & self , decl : & FnDecl , report_err : ReportFn ) {
234+ fn check_decl_no_pat < F : FnMut ( Span , bool ) > ( decl : & FnDecl , mut report_err : F ) {
233235 for arg in & decl. inputs {
234236 match arg. pat . kind {
235237 PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , _, None ) |
@@ -460,7 +462,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
460462 match ty. kind {
461463 TyKind :: BareFn ( ref bfty) => {
462464 self . check_fn_decl ( & bfty. decl ) ;
463- self . check_decl_no_pat ( & bfty. decl , |span, _| {
465+ Self :: check_decl_no_pat ( & bfty. decl , |span, _| {
464466 struct_span_err ! ( self . session, span, E0561 ,
465467 "patterns aren't allowed in function pointer types" ) . emit ( ) ;
466468 } ) ;
@@ -483,7 +485,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
483485 TyKind :: ImplTrait ( _, ref bounds) => {
484486 if self . is_impl_trait_banned {
485487 if self . warning_period_57979_impl_trait_in_proj {
486- self . session . buffer_lint (
488+ self . lint_buffer . buffer_lint (
487489 NESTED_IMPL_TRAIT , ty. id , ty. span ,
488490 "`impl Trait` is not allowed in path parameters" ) ;
489491 } else {
@@ -494,7 +496,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
494496
495497 if let Some ( outer_impl_trait) = self . outer_impl_trait {
496498 if outer_impl_trait. should_warn_instead_of_error ( ) {
497- self . session . buffer_lint_with_diagnostic (
499+ self . lint_buffer . buffer_lint_with_diagnostic (
498500 NESTED_IMPL_TRAIT , ty. id , ty. span ,
499501 "nested `impl Trait` is not allowed" ,
500502 BuiltinLintDiagnostics :: NestedImplTrait {
@@ -634,9 +636,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
634636 self . check_trait_fn_not_async ( trait_item. span , sig. header . asyncness . node ) ;
635637 self . check_trait_fn_not_const ( sig. header . constness ) ;
636638 if block. is_none ( ) {
637- self . check_decl_no_pat ( & sig. decl , |span, mut_ident| {
639+ Self :: check_decl_no_pat ( & sig. decl , |span, mut_ident| {
638640 if mut_ident {
639- self . session . buffer_lint (
641+ self . lint_buffer . buffer_lint (
640642 lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ,
641643 trait_item. id , span,
642644 "patterns aren't allowed in methods without bodies" ) ;
@@ -655,7 +657,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
655657 if attr:: contains_name ( & item. attrs , sym:: warn_directory_ownership) {
656658 let lint = lint:: builtin:: LEGACY_DIRECTORY_OWNERSHIP ;
657659 let msg = "cannot declare a new module at this location" ;
658- self . session . buffer_lint ( lint, item. id , item. span , msg) ;
660+ self . lint_buffer . buffer_lint ( lint, item. id , item. span , msg) ;
659661 }
660662 }
661663 ItemKind :: Union ( ref vdata, _) => {
@@ -686,7 +688,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
686688 match fi. kind {
687689 ForeignItemKind :: Fn ( ref decl, _) => {
688690 self . check_fn_decl ( decl) ;
689- self . check_decl_no_pat ( decl, |span, _| {
691+ Self :: check_decl_no_pat ( decl, |span, _| {
690692 struct_span_err ! ( self . session, span, E0130 ,
691693 "patterns aren't allowed in foreign function declarations" )
692694 . span_label ( span, "pattern not allowed in foreign function" ) . emit ( ) ;
@@ -840,7 +842,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
840842 }
841843}
842844
843- pub fn check_crate ( session : & Session , krate : & Crate ) -> bool {
845+ pub fn check_crate ( session : & Session , krate : & Crate , lints : & mut lint :: LintBuffer ) -> bool {
844846 let mut validator = AstValidator {
845847 session,
846848 has_proc_macro_decls : false ,
@@ -849,6 +851,7 @@ pub fn check_crate(session: &Session, krate: &Crate) -> bool {
849851 is_assoc_ty_bound_banned : false ,
850852 warning_period_57979_didnt_record_next_impl_trait : false ,
851853 warning_period_57979_impl_trait_in_proj : false ,
854+ lint_buffer : lints,
852855 } ;
853856 visit:: walk_crate ( & mut validator, krate) ;
854857
0 commit comments