diff --git a/README.md b/README.md index 87ef441eadd5..922dbcd11380 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs index 23952efbc8d8..7220833b9f23 100644 --- a/clippy_lints/src/exit.rs +++ b/clippy_lints/src/exit.rs @@ -33,31 +33,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit { if match_def_path(cx, def_id, &paths::EXIT); then { let mut parent = cx.tcx.hir().get_parent_item(e.hir_id); - // We have to traverse the parents upwards until we find a function - // otherwise a exit in a let or if in main would still trigger this - loop{ - match cx.tcx.hir().find(parent) { - Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) => { - // If we found a function we check it's name if it is - // `main` we emit a lint. - let def_id = cx.tcx.hir().local_def_id(parent); - if !is_entrypoint_fn(cx, def_id) { - span_lint(cx, EXIT, e.span, "usage of `process::exit`"); - } - // We found any kind of function and can end our loop - break; - } - // If we found anything but a funciton we continue with the - // loop and go one parent up - Some(_) => { - parent = cx.tcx.hir().get_parent_item(parent); - }, - // If we found nothing we break. - None => break, + if let Some(Node::Item(Item{ident, kind: ItemKind::Fn(..), ..})) = cx.tcx.hir().find(parent) { + // If the next item up is a function we check if it is an entry point + // and only then emit a linter warning + let def_id = cx.tcx.hir().local_def_id(parent); + if !is_entrypoint_fn(cx, def_id) { + span_lint(cx, EXIT, e.span, "usage of `process::exit`"); } } } - } } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2e5d46b273ca..d8d3bd7d5139 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -500,6 +500,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &eval_order_dependence::DIVERGING_SUB_EXPRESSION, &eval_order_dependence::EVAL_ORDER_DEPENDENCE, &excessive_precision::EXCESSIVE_PRECISION, + &exit::EXIT, &explicit_write::EXPLICIT_WRITE, &fallible_impl_from::FALLIBLE_IMPL_FROM, &format::USELESS_FORMAT, diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 96f676e515f1..beaadb9c29ad 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 332] = [ +pub const ALL_LINTS: [Lint; 333] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness",