|
1 | 1 | use clippy_config::Conf; |
2 | 2 | use clippy_utils::diagnostics::span_lint; |
3 | | -use clippy_utils::is_in_test; |
4 | 3 | use clippy_utils::msrvs::Msrv; |
| 4 | +use clippy_utils::{def_path_def_ids, is_in_test}; |
5 | 5 | use rustc_attr_parsing::{RustcVersion, StabilityLevel, StableSince}; |
6 | 6 | use rustc_data_structures::fx::FxHashMap; |
7 | 7 | use rustc_hir::{Expr, ExprKind, HirId}; |
@@ -43,16 +43,23 @@ pub struct IncompatibleMsrv { |
43 | 43 | msrv: Msrv, |
44 | 44 | is_above_msrv: FxHashMap<DefId, RustcVersion>, |
45 | 45 | check_in_tests: bool, |
| 46 | + ignored_def_ids: Vec<DefId>, |
46 | 47 | } |
47 | 48 |
|
48 | 49 | impl_lint_pass!(IncompatibleMsrv => [INCOMPATIBLE_MSRV]); |
49 | 50 |
|
50 | 51 | impl IncompatibleMsrv { |
51 | | - pub fn new(conf: &'static Conf) -> Self { |
| 52 | + pub fn new(tcx: TyCtxt<'_>, conf: &'static Conf) -> Self { |
| 53 | + let ignored_def_ids = conf |
| 54 | + .ignore_msrv_check_for |
| 55 | + .iter() |
| 56 | + .flat_map(|x| def_path_def_ids(tcx, &x.split("::").collect::<Vec<_>>())) |
| 57 | + .collect(); |
52 | 58 | Self { |
53 | 59 | msrv: conf.msrv, |
54 | 60 | is_above_msrv: FxHashMap::default(), |
55 | 61 | check_in_tests: conf.check_incompatible_msrv_in_tests, |
| 62 | + ignored_def_ids, |
56 | 63 | } |
57 | 64 | } |
58 | 65 |
|
@@ -84,8 +91,9 @@ impl IncompatibleMsrv { |
84 | 91 | } |
85 | 92 |
|
86 | 93 | fn emit_lint_if_under_msrv(&mut self, cx: &LateContext<'_>, def_id: DefId, node: HirId, span: Span) { |
87 | | - if def_id.is_local() { |
88 | | - // We don't check local items since their MSRV is supposed to always be valid. |
| 94 | + // We don't check local items since their MSRV is supposed to always be valid, nor ignored items |
| 95 | + // which may be feature-gated. |
| 96 | + if def_id.is_local() || self.ignored_def_ids.contains(&def_id) { |
89 | 97 | return; |
90 | 98 | } |
91 | 99 | if let ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) = span.ctxt().outer_expn_data().kind { |
|
0 commit comments