1
1
//! checks for attributes
2
2
3
3
use clippy_utils:: diagnostics:: { span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then} ;
4
- use clippy_utils:: match_panic_def_id ;
4
+ use clippy_utils:: msrvs ;
5
5
use clippy_utils:: source:: { first_line_of_span, is_present_in_source, snippet_opt, without_block_comments} ;
6
+ use clippy_utils:: { extract_msrv_attr, match_panic_def_id, meets_msrv} ;
6
7
use if_chain:: if_chain;
7
8
use rustc_ast:: { AttrKind , AttrStyle , Attribute , Lit , LitKind , MetaItemKind , NestedMetaItem } ;
8
9
use rustc_errors:: Applicability ;
@@ -12,7 +13,8 @@ use rustc_hir::{
12
13
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
13
14
use rustc_middle:: lint:: in_external_macro;
14
15
use rustc_middle:: ty;
15
- use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
16
+ use rustc_semver:: RustcVersion ;
17
+ use rustc_session:: { declare_lint_pass, declare_tool_lint, impl_lint_pass} ;
16
18
use rustc_span:: source_map:: Span ;
17
19
use rustc_span:: sym;
18
20
use rustc_span:: symbol:: { Symbol , SymbolStr } ;
@@ -497,7 +499,11 @@ fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
497
499
}
498
500
}
499
501
500
- declare_lint_pass ! ( EarlyAttributes => [
502
+ pub struct EarlyAttributes {
503
+ pub msrv : Option < RustcVersion > ,
504
+ }
505
+
506
+ impl_lint_pass ! ( EarlyAttributes => [
501
507
DEPRECATED_CFG_ATTR ,
502
508
MISMATCHED_TARGET_OS ,
503
509
EMPTY_LINE_AFTER_OUTER_ATTR ,
@@ -509,9 +515,11 @@ impl EarlyLintPass for EarlyAttributes {
509
515
}
510
516
511
517
fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & Attribute ) {
512
- check_deprecated_cfg_attr ( cx, attr) ;
518
+ check_deprecated_cfg_attr ( cx, attr, self . msrv ) ;
513
519
check_mismatched_target_os ( cx, attr) ;
514
520
}
521
+
522
+ extract_msrv_attr ! ( EarlyContext ) ;
515
523
}
516
524
517
525
fn check_empty_line_after_outer_attr ( cx : & EarlyContext < ' _ > , item : & rustc_ast:: Item ) {
@@ -548,8 +556,9 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
548
556
}
549
557
}
550
558
551
- fn check_deprecated_cfg_attr ( cx : & EarlyContext < ' _ > , attr : & Attribute ) {
559
+ fn check_deprecated_cfg_attr ( cx : & EarlyContext < ' _ > , attr : & Attribute , msrv : Option < RustcVersion > ) {
552
560
if_chain ! {
561
+ if meets_msrv( msrv. as_ref( ) , & msrvs:: TOOL_ATTRIBUTES ) ;
553
562
// check cfg_attr
554
563
if attr. has_name( sym:: cfg_attr) ;
555
564
if let Some ( items) = attr. meta_item_list( ) ;
0 commit comments