@@ -73,6 +73,8 @@ struct AstValidator<'a> {
73
73
/// these booleans.
74
74
warning_period_57979_didnt_record_next_impl_trait : bool ,
75
75
warning_period_57979_impl_trait_in_proj : bool ,
76
+
77
+ lint_buffer : & ' a mut lint:: LintBuffer ,
76
78
}
77
79
78
80
impl < ' a > AstValidator < ' a > {
@@ -229,7 +231,7 @@ impl<'a> AstValidator<'a> {
229
231
err. emit ( ) ;
230
232
}
231
233
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 ) {
233
235
for arg in & decl. inputs {
234
236
match arg. pat . kind {
235
237
PatKind :: Ident ( BindingMode :: ByValue ( Mutability :: Immutable ) , _, None ) |
@@ -460,7 +462,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
460
462
match ty. kind {
461
463
TyKind :: BareFn ( ref bfty) => {
462
464
self . check_fn_decl ( & bfty. decl ) ;
463
- self . check_decl_no_pat ( & bfty. decl , |span, _| {
465
+ Self :: check_decl_no_pat ( & bfty. decl , |span, _| {
464
466
struct_span_err ! ( self . session, span, E0561 ,
465
467
"patterns aren't allowed in function pointer types" ) . emit ( ) ;
466
468
} ) ;
@@ -483,7 +485,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
483
485
TyKind :: ImplTrait ( _, ref bounds) => {
484
486
if self . is_impl_trait_banned {
485
487
if self . warning_period_57979_impl_trait_in_proj {
486
- self . session . buffer_lint (
488
+ self . lint_buffer . buffer_lint (
487
489
NESTED_IMPL_TRAIT , ty. id , ty. span ,
488
490
"`impl Trait` is not allowed in path parameters" ) ;
489
491
} else {
@@ -494,7 +496,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
494
496
495
497
if let Some ( outer_impl_trait) = self . outer_impl_trait {
496
498
if outer_impl_trait. should_warn_instead_of_error ( ) {
497
- self . session . buffer_lint_with_diagnostic (
499
+ self . lint_buffer . buffer_lint_with_diagnostic (
498
500
NESTED_IMPL_TRAIT , ty. id , ty. span ,
499
501
"nested `impl Trait` is not allowed" ,
500
502
BuiltinLintDiagnostics :: NestedImplTrait {
@@ -634,9 +636,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
634
636
self . check_trait_fn_not_async ( trait_item. span , sig. header . asyncness . node ) ;
635
637
self . check_trait_fn_not_const ( sig. header . constness ) ;
636
638
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| {
638
640
if mut_ident {
639
- self . session . buffer_lint (
641
+ self . lint_buffer . buffer_lint (
640
642
lint:: builtin:: PATTERNS_IN_FNS_WITHOUT_BODY ,
641
643
trait_item. id , span,
642
644
"patterns aren't allowed in methods without bodies" ) ;
@@ -655,7 +657,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
655
657
if attr:: contains_name ( & item. attrs , sym:: warn_directory_ownership) {
656
658
let lint = lint:: builtin:: LEGACY_DIRECTORY_OWNERSHIP ;
657
659
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) ;
659
661
}
660
662
}
661
663
ItemKind :: Union ( ref vdata, _) => {
@@ -686,7 +688,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
686
688
match fi. kind {
687
689
ForeignItemKind :: Fn ( ref decl, _) => {
688
690
self . check_fn_decl ( decl) ;
689
- self . check_decl_no_pat ( decl, |span, _| {
691
+ Self :: check_decl_no_pat ( decl, |span, _| {
690
692
struct_span_err ! ( self . session, span, E0130 ,
691
693
"patterns aren't allowed in foreign function declarations" )
692
694
. span_label ( span, "pattern not allowed in foreign function" ) . emit ( ) ;
@@ -840,7 +842,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
840
842
}
841
843
}
842
844
843
- pub fn check_crate ( session : & Session , krate : & Crate ) -> bool {
845
+ pub fn check_crate ( session : & Session , krate : & Crate , lints : & mut lint :: LintBuffer ) -> bool {
844
846
let mut validator = AstValidator {
845
847
session,
846
848
has_proc_macro_decls : false ,
@@ -849,6 +851,7 @@ pub fn check_crate(session: &Session, krate: &Crate) -> bool {
849
851
is_assoc_ty_bound_banned : false ,
850
852
warning_period_57979_didnt_record_next_impl_trait : false ,
851
853
warning_period_57979_impl_trait_in_proj : false ,
854
+ lint_buffer : lints,
852
855
} ;
853
856
visit:: walk_crate ( & mut validator, krate) ;
854
857
0 commit comments