Skip to content

Commit c84ac4c

Browse files
committed
Move some things around
1 parent dfd3525 commit c84ac4c

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

clippy_lints/src/utils/internal_lints/compiler_lint_functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ declare_clippy_lint! {
3030
"usage of the lint functions of the compiler instead of the utils::* variant"
3131
}
3232

33+
impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
34+
3335
#[derive(Clone, Default)]
3436
pub struct CompilerLintFunctions {
3537
map: FxHashMap<&'static str, &'static str>,
@@ -48,8 +50,6 @@ impl CompilerLintFunctions {
4850
}
4951
}
5052

51-
impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
52-
5353
impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
5454
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5555
if is_lint_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) {

clippy_lints/src/utils/internal_lints/invalid_paths.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,38 @@ declare_clippy_lint! {
2525
"invalid path"
2626
}
2727

28+
declare_lint_pass!(InvalidPaths => [INVALID_PATHS]);
29+
30+
impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
31+
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
32+
let local_def_id = &cx.tcx.parent_module(item.hir_id());
33+
let mod_name = &cx.tcx.item_name(local_def_id.to_def_id());
34+
if_chain! {
35+
if mod_name.as_str() == "paths";
36+
if let hir::ItemKind::Const(ty, body_id) = item.kind;
37+
let ty = hir_ty_to_ty(cx.tcx, ty);
38+
if let ty::Array(el_ty, _) = &ty.kind();
39+
if let ty::Ref(_, el_ty, _) = &el_ty.kind();
40+
if el_ty.is_str();
41+
let body = cx.tcx.hir().body(body_id);
42+
let typeck_results = cx.tcx.typeck_body(body_id);
43+
if let Some(Constant::Vec(path)) = constant_simple(cx, typeck_results, body.value);
44+
let path: Vec<&str> = path.iter().map(|x| {
45+
if let Constant::Str(s) = x {
46+
s.as_str()
47+
} else {
48+
// We checked the type of the constant above
49+
unreachable!()
50+
}
51+
}).collect();
52+
if !check_path(cx, &path[..]);
53+
then {
54+
span_lint(cx, INVALID_PATHS, item.span, "invalid path");
55+
}
56+
}
57+
}
58+
}
59+
2860
// This is not a complete resolver for paths. It works on all the paths currently used in the paths
2961
// module. That's all it does and all it needs to do.
3062
pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
@@ -71,35 +103,3 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
71103

72104
false
73105
}
74-
75-
declare_lint_pass!(InvalidPaths => [INVALID_PATHS]);
76-
77-
impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
78-
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
79-
let local_def_id = &cx.tcx.parent_module(item.hir_id());
80-
let mod_name = &cx.tcx.item_name(local_def_id.to_def_id());
81-
if_chain! {
82-
if mod_name.as_str() == "paths";
83-
if let hir::ItemKind::Const(ty, body_id) = item.kind;
84-
let ty = hir_ty_to_ty(cx.tcx, ty);
85-
if let ty::Array(el_ty, _) = &ty.kind();
86-
if let ty::Ref(_, el_ty, _) = &el_ty.kind();
87-
if el_ty.is_str();
88-
let body = cx.tcx.hir().body(body_id);
89-
let typeck_results = cx.tcx.typeck_body(body_id);
90-
if let Some(Constant::Vec(path)) = constant_simple(cx, typeck_results, body.value);
91-
let path: Vec<&str> = path.iter().map(|x| {
92-
if let Constant::Str(s) = x {
93-
s.as_str()
94-
} else {
95-
// We checked the type of the constant above
96-
unreachable!()
97-
}
98-
}).collect();
99-
if !check_path(cx, &path[..]);
100-
then {
101-
span_lint(cx, INVALID_PATHS, item.span, "invalid path");
102-
}
103-
}
104-
}
105-
}

0 commit comments

Comments
 (0)