11//! checks for attributes
22
33use 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 ;
55use 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} ;
67use if_chain:: if_chain;
78use rustc_ast:: { AttrKind , AttrStyle , Attribute , Lit , LitKind , MetaItemKind , NestedMetaItem } ;
89use rustc_errors:: Applicability ;
@@ -12,7 +13,8 @@ use rustc_hir::{
1213use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
1314use rustc_middle:: lint:: in_external_macro;
1415use 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} ;
1618use rustc_span:: source_map:: Span ;
1719use rustc_span:: sym;
1820use rustc_span:: symbol:: { Symbol , SymbolStr } ;
@@ -497,7 +499,11 @@ fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
497499 }
498500}
499501
500- declare_lint_pass ! ( EarlyAttributes => [
502+ pub struct EarlyAttributes {
503+ pub msrv : Option < RustcVersion > ,
504+ }
505+
506+ impl_lint_pass ! ( EarlyAttributes => [
501507 DEPRECATED_CFG_ATTR ,
502508 MISMATCHED_TARGET_OS ,
503509 EMPTY_LINE_AFTER_OUTER_ATTR ,
@@ -509,9 +515,11 @@ impl EarlyLintPass for EarlyAttributes {
509515 }
510516
511517 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 ) ;
513519 check_mismatched_target_os ( cx, attr) ;
514520 }
521+
522+ extract_msrv_attr ! ( EarlyContext ) ;
515523}
516524
517525fn 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
548556 }
549557}
550558
551- fn check_deprecated_cfg_attr ( cx : & EarlyContext < ' _ > , attr : & Attribute ) {
559+ fn check_deprecated_cfg_attr ( cx : & EarlyContext < ' _ > , attr : & Attribute , msrv : Option < RustcVersion > ) {
552560 if_chain ! {
561+ if meets_msrv( msrv. as_ref( ) , & msrvs:: TOOL_ATTRIBUTES ) ;
553562 // check cfg_attr
554563 if attr. has_name( sym:: cfg_attr) ;
555564 if let Some ( items) = attr. meta_item_list( ) ;
0 commit comments