Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify dentry point detection
  • Loading branch information
Licenser committed Nov 7, 2019
commit eae6a62db7582cc0c243a798268a258436c27407
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 331 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:

Expand Down
28 changes: 6 additions & 22 deletions clippy_lints/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`");
}
}
}

}
}
}
1 change: 1 addition & 0 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,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,
Expand Down
2 changes: 1 addition & 1 deletion src/lintlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; 331] = [
pub const ALL_LINTS: [Lint; 333] = [
Lint {
name: "absurd_extreme_comparisons",
group: "correctness",
Expand Down