|
1 | | -use crate::utils::internal_lints::metadata_collector::is_deprecated_lint; |
| 1 | +use crate::utils::metadata_collector::is_deprecated_lint; |
| 2 | +use crate::utils::{extract_clippy_version_value, is_lint_ref_type}; |
2 | 3 | use clippy_utils::diagnostics::{span_lint, span_lint_and_help}; |
| 4 | +use clippy_utils::is_lint_allowed; |
3 | 5 | use clippy_utils::macros::root_macro_call_first_node; |
4 | | -use clippy_utils::{is_lint_allowed, match_def_path, paths}; |
5 | | -use if_chain::if_chain; |
6 | | -use rustc_ast as ast; |
7 | 6 | use rustc_ast::ast::LitKind; |
8 | 7 | use rustc_data_structures::fx::{FxHashMap, FxHashSet}; |
9 | 8 | use rustc_hir as hir; |
10 | | -use rustc_hir::def::{DefKind, Res}; |
11 | 9 | use rustc_hir::hir_id::CRATE_HIR_ID; |
12 | 10 | use rustc_hir::intravisit::Visitor; |
13 | | -use rustc_hir::{ExprKind, HirId, Item, MutTy, Mutability, Path, TyKind}; |
| 11 | +use rustc_hir::{ExprKind, HirId, Item, Mutability, Path}; |
14 | 12 | use rustc_lint::{LateContext, LateLintPass}; |
15 | 13 | use rustc_middle::hir::nested_filter; |
16 | 14 | use rustc_semver::RustcVersion; |
17 | 15 | use rustc_session::{declare_tool_lint, impl_lint_pass}; |
18 | 16 | use rustc_span::source_map::Spanned; |
19 | 17 | use rustc_span::symbol::Symbol; |
20 | | -use rustc_span::{sym, Span}; |
| 18 | +use rustc_span::Span; |
21 | 19 |
|
22 | 20 | declare_clippy_lint! { |
23 | 21 | /// ### What it does |
@@ -255,25 +253,6 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { |
255 | 253 | } |
256 | 254 | } |
257 | 255 |
|
258 | | -pub(super) fn is_lint_ref_type(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool { |
259 | | - if let TyKind::Ref( |
260 | | - _, |
261 | | - MutTy { |
262 | | - ty: inner, |
263 | | - mutbl: Mutability::Not, |
264 | | - }, |
265 | | - ) = ty.kind |
266 | | - { |
267 | | - if let TyKind::Path(ref path) = inner.kind { |
268 | | - if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, inner.hir_id) { |
269 | | - return match_def_path(cx, def_id, &paths::LINT); |
270 | | - } |
271 | | - } |
272 | | - } |
273 | | - |
274 | | - false |
275 | | -} |
276 | | - |
277 | 256 | fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'_>) { |
278 | 257 | if let Some(value) = extract_clippy_version_value(cx, item) { |
279 | 258 | // The `sym!` macro doesn't work as it only expects a single token. |
@@ -304,23 +283,6 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<' |
304 | 283 | } |
305 | 284 | } |
306 | 285 |
|
307 | | -/// This function extracts the version value of a `clippy::version` attribute if the given value has |
308 | | -/// one |
309 | | -pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<'_>) -> Option<Symbol> { |
310 | | - let attrs = cx.tcx.hir().attrs(item.hir_id()); |
311 | | - attrs.iter().find_map(|attr| { |
312 | | - if_chain! { |
313 | | - // Identify attribute |
314 | | - if let ast::AttrKind::Normal(ref attr_kind) = &attr.kind; |
315 | | - if let [tool_name, attr_name] = &attr_kind.item.path.segments[..]; |
316 | | - if tool_name.ident.name == sym::clippy; |
317 | | - if attr_name.ident.name == sym::version; |
318 | | - if let Some(version) = attr.value_str(); |
319 | | - then { Some(version) } else { None } |
320 | | - } |
321 | | - }) |
322 | | -} |
323 | | - |
324 | 286 | struct LintCollector<'a, 'tcx> { |
325 | 287 | output: &'a mut FxHashSet<Symbol>, |
326 | 288 | cx: &'a LateContext<'tcx>, |
|
0 commit comments