Skip to content

Commit 60ce2bc

Browse files
committed
Simplify dentry point detection
1 parent 136130a commit 60ce2bc

File tree

4 files changed

+9
-24
lines changed

4 files changed

+9
-24
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/exit.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
3333
if match_def_path(cx, def_id, &paths::EXIT);
3434
then {
3535
let mut parent = cx.tcx.hir().get_parent_item(e.hir_id);
36-
// We have to traverse the parents upwards until we find a function
37-
// otherwise a exit in a let or if in main would still trigger this
38-
loop{
39-
match cx.tcx.hir().find(parent) {
40-
Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) => {
41-
// If we found a function we check it's name if it is
42-
// `main` we emit a lint.
43-
let def_id = cx.tcx.hir().local_def_id(parent);
44-
if !is_entrypoint_fn(cx, def_id) {
45-
span_lint(cx, EXIT, e.span, "usage of `process::exit`");
46-
}
47-
// We found any kind of function and can end our loop
48-
break;
49-
}
50-
// If we found anything but a funciton we continue with the
51-
// loop and go one parent up
52-
Some(_) => {
53-
parent = cx.tcx.hir().get_parent_item(parent);
54-
},
55-
// If we found nothing we break.
56-
None => break,
36+
if let Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent) {
37+
// If the next item up is a function we check if it is an entry point
38+
// and only then emit a linter warning
39+
let def_id = cx.tcx.hir().local_def_id(parent);
40+
if !is_entrypoint_fn(cx, def_id) {
41+
span_lint(cx, EXIT, e.span, "usage of `process::exit`");
5742
}
5843
}
5944
}
60-
6145
}
6246
}
6347
}

clippy_lints/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
500500
&eval_order_dependence::DIVERGING_SUB_EXPRESSION,
501501
&eval_order_dependence::EVAL_ORDER_DEPENDENCE,
502502
&excessive_precision::EXCESSIVE_PRECISION,
503+
&exit::EXIT,
503504
&explicit_write::EXPLICIT_WRITE,
504505
&fallible_impl_from::FALLIBLE_IMPL_FROM,
505506
&format::USELESS_FORMAT,

src/lintlist/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 332] = [
9+
pub const ALL_LINTS: [Lint; 333] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",

0 commit comments

Comments
 (0)