Skip to content

Commit

Permalink
Merge branch 'master' into or_fun_call
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystucki committed Aug 21, 2019
2 parents cfc0174 + 6d9ee9e commit d9b8508
Show file tree
Hide file tree
Showing 84 changed files with 810 additions and 324 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ matrix:
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
- env: INTEGRATION=rust-lang-nursery/chalk
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
- env: INTEGRATION=rust-lang/rls
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
# - env: INTEGRATION=rust-lang/rls
# if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
- env: INTEGRATION=Geal/nom
if: repo =~ /^rust-lang\/rust-clippy$/ AND branch IN (auto, try)
- env: INTEGRATION=rust-lang/rustfmt
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Changelog Update](doc/changelog_update.md) if you want to update this
document.

## Unreleased / In Rust Beta or Nightly

Expand Down Expand Up @@ -1088,6 +1090,7 @@ Released 2018-09-13
[`not_unsafe_ptr_arg_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
[`option_map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or
Expand Down Expand Up @@ -1152,6 +1155,7 @@ Released 2018-09-13
[`suspicious_arithmetic_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting
[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting
[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map
[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Hello fellow Rustacean! Great to see your interest in compiler internals and lin
Clippy welcomes contributions from everyone. There are many ways to contribute to Clippy and the following document explains how
you can contribute and how to get started.
If you have any questions about contributing or need help with anything, feel free to ask questions on issues or
visit the `#clippy` IRC channel on `irc.mozilla.org` or meet us in `#wg-clippy` on [Discord](https://discord.gg/rust-lang).
visit the `#clippy` IRC channel on `irc.mozilla.org` or meet us in `#clippy` on [Discord](https://discord.gg/rust-lang).

All contributors are expected to follow the [Rust Code of Conduct](http://www.rust-lang.org/conduct.html).

Expand Down Expand Up @@ -90,7 +90,7 @@ Clippy is a [rustc compiler plugin][compiler_plugin]. The main entry point is at
pub mod else_if_without_else;
// ...

pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry) {
// ...
reg.register_early_lint_pass(box else_if_without_else::ElseIfWithoutElse);
// ...
Expand All @@ -103,7 +103,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
}
```

The [`rustc_plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
The [`plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.

Expand Down Expand Up @@ -193,9 +193,9 @@ or the [MIT](http://opensource.org/licenses/MIT) license.
[lint_crate_entry]: https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src/lib.rs
[else_if_without_else]: https://github.com/rust-lang/rust-clippy/blob/c5b39a5917ffc0f1349b6e414fa3b874fdcf8429/clippy_lints/src/else_if_without_else.rs
[compiler_plugin]: https://doc.rust-lang.org/unstable-book/language-features/plugin.html#lint-plugins
[plugin_registry]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin/registry/struct.Registry.html
[reg_early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin/registry/struct.Registry.html#method.register_early_lint_pass
[reg_late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin/registry/struct.Registry.html#method.register_late_lint_pass
[plugin_registry]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html
[reg_early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html#method.register_early_lint_pass
[reg_late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_plugin_impl/registry/struct.Registry.html#method.register_late_lint_pass
[early_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.EarlyLintPass.html
[late_lint_pass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/lint/trait.LateLintPass.html
[toolstate_commit_history]: https://github.com/rust-lang-nursery/rust-toolstate/commits/master
Expand Down
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 309 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
[There are 311 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
6 changes: 3 additions & 3 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
lints
.iter()
.filter_map(|l| {
l.clone().deprecation.and_then(|depr_text| {
Some(vec![
l.clone().deprecation.map(|depr_text| {
vec![
" store.register_removed(".to_string(),
format!(" \"clippy::{}\",", l.name),
format!(" \"{}\",", depr_text),
" );".to_string(),
])
]
})
})
.flatten()
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ serde = { version = "1.0", features = ["derive"] }
toml = "0.5.3"
unicode-normalization = "0.1"
pulldown-cmark = "0.5.3"
url = "2.1.0"
url = { version = "2.1.0", features = ["serde"] } # cargo requires serde feat in its url dep
# see https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864
if_chain = "1.0.0"
smallvec = { version = "0.6.5", features = ["union"] }

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};

use crate::consts::{constant, Constant};
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, is_expn_of, span_help_and_lint};
use crate::utils::{is_direct_expn_of, is_expn_of, span_help_and_lint};

declare_clippy_lint! {
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
Expand Down Expand Up @@ -55,12 +55,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
}
};
if let Some(debug_assert_span) = is_expn_of(e.span, "debug_assert") {
if in_macro_or_desugar(debug_assert_span) {
if debug_assert_span.from_expansion() {
return;
}
lint_assert_cb(true);
} else if let Some(assert_span) = is_direct_expn_of(e.span, "assert") {
if in_macro_or_desugar(assert_span) {
if assert_span.from_expansion() {
return;
}
lint_assert_cb(false);
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use crate::reexport::*;
use crate::utils::{
in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
span_lint_and_sugg, span_lint_and_then, without_block_comments,
is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
span_lint_and_then, without_block_comments,
};
use if_chain::if_chain;
use rustc::hir::*;
Expand Down Expand Up @@ -412,7 +412,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
}

fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
if in_macro_or_desugar(span) {
if span.from_expansion() {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/block_in_if_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
if let ExprKind::Closure(_, _, eid, _, _) = expr.node {
let body = self.cx.tcx.hir().body(eid);
let ex = &body.value;
if matches!(ex.node, ExprKind::Block(_, _)) && !in_macro_or_desugar(body.value.span) {
if matches!(ex.node, ExprKind::Block(_, _)) && !body.value.span.from_expansion() {
self.found_block = Some(ex);
return;
}
Expand All @@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
if let Some(ex) = &block.expr {
// don't dig into the expression here, just suggest that they remove
// the block
if in_macro_or_desugar(expr.span) || differing_macro_contexts(expr.span, ex.span) {
if expr.span.from_expansion() || differing_macro_contexts(expr.span, ex.span) {
return;
}
span_help_and_lint(
Expand All @@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
}
} else {
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
if in_macro_or_desugar(span) || differing_macro_contexts(expr.span, span) {
if span.from_expansion() || differing_macro_contexts(expr.span, span) {
return;
}
// move block higher
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::utils::{
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
span_lint_and_then, SpanlessEq,
get_trait_def_id, implements_trait, in_macro, match_type, paths, snippet_opt, span_lint_and_then, SpanlessEq,
};
use if_chain::if_chain;
use rustc::hir::intravisit::*;
Expand Down Expand Up @@ -106,7 +105,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
}

// prevent folding of `cfg!` macros and the like
if !in_macro_or_desugar(e.span) {
if !e.span.from_expansion() {
match &e.node {
ExprKind::Unary(UnNot, inner) => return Ok(Bool::Not(box self.run(inner)?)),
ExprKind::Binary(binop, lhs, rhs) => match &binop.node {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc::{declare_tool_lint, impl_lint_pass};
use syntax::ast::Attribute;
use syntax::source_map::Span;

use crate::utils::{in_macro_or_desugar, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
use crate::utils::{is_allowed, match_type, paths, span_help_and_lint, LimitStack};

declare_clippy_lint! {
/// **What it does:** Checks for methods with high cognitive complexity.
Expand Down Expand Up @@ -42,7 +42,7 @@ impl_lint_pass!(CognitiveComplexity => [COGNITIVE_COMPLEXITY]);

impl CognitiveComplexity {
fn check<'a, 'tcx>(&mut self, cx: &'a LateContext<'a, 'tcx>, body: &'tcx Body, span: Span) {
if in_macro_or_desugar(span) {
if span.from_expansion() {
return;
}

Expand Down
8 changes: 3 additions & 5 deletions clippy_lints/src/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::ast;

use crate::utils::sugg::Sugg;
use crate::utils::{
in_macro_or_desugar, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then,
};
use crate::utils::{snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
use rustc_errors::Applicability;

declare_clippy_lint! {
Expand Down Expand Up @@ -77,7 +75,7 @@ declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]);

impl EarlyLintPass for CollapsibleIf {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
if !in_macro_or_desugar(expr.span) {
if !expr.span.from_expansion() {
check_if(cx, expr)
}
}
Expand Down Expand Up @@ -108,7 +106,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
if let ast::ExprKind::Block(ref block, _) = else_.node;
if !block_starts_with_comment(cx, block);
if let Some(else_) = expr_block(block);
if !in_macro_or_desugar(else_.span);
if !else_.span.from_expansion();
if let ast::ExprKind::If(..) = else_.node;
then {
let mut applicability = Applicability::MachineApplicable;
Expand Down
6 changes: 2 additions & 4 deletions clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::utils::{
get_parent_expr, higher, in_macro_or_desugar, same_tys, snippet, span_lint_and_then, span_note_and_lint,
};
use crate::utils::{get_parent_expr, higher, same_tys, snippet, span_lint_and_then, span_note_and_lint};
use crate::utils::{SpanlessEq, SpanlessHash};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
Expand Down Expand Up @@ -109,7 +107,7 @@ declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, IF_SAME_THEN_ELSE, MATCH_SAME

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if !in_macro_or_desugar(expr.span) {
if !expr.span.from_expansion() {
// skip ifs directly in else, it will be checked in the parent if
if let Some(expr) = get_parent_expr(cx, expr) {
if let Some((_, _, Some(ref else_expr))) = higher::if_block(&expr) {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/double_parens.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::{in_macro_or_desugar, span_lint};
use crate::utils::span_lint;
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::ast::*;
Expand Down Expand Up @@ -27,7 +27,7 @@ declare_lint_pass!(DoubleParens => [DOUBLE_PARENS]);

impl EarlyLintPass for DoubleParens {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if in_macro_or_desugar(expr.span) {
if expr.span.from_expansion() {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! lint on enum variants that are prefixed or suffixed by the same characters
use crate::utils::{camel_case, in_macro_or_desugar, is_present_in_source};
use crate::utils::{camel_case, is_present_in_source};
use crate::utils::{span_help_and_lint, span_lint};
use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass};
use rustc::{declare_tool_lint, impl_lint_pass};
Expand Down Expand Up @@ -248,7 +248,7 @@ impl EarlyLintPass for EnumVariantNames {
let item_name = item.ident.as_str();
let item_name_chars = item_name.chars().count();
let item_camel = to_camel_case(&item_name);
if !in_macro_or_desugar(item.span) && is_present_in_source(cx, item.span) {
if !item.span.from_expansion() && is_present_in_source(cx, item.span) {
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {
Expand Down
6 changes: 2 additions & 4 deletions clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::utils::{
implements_trait, in_macro_or_desugar, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
};
use crate::utils::{implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
Expand Down Expand Up @@ -52,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
#[allow(clippy::similar_names, clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Binary(op, ref left, ref right) = e.node {
if in_macro_or_desugar(e.span) {
if e.span.from_expansion() {
return;
}
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/erasing_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax::source_map::Span;

use crate::consts::{constant_simple, Constant};
use crate::utils::{in_macro_or_desugar, span_lint};
use crate::utils::span_lint;

declare_clippy_lint! {
/// **What it does:** Checks for erasing operations, e.g., `x * 0`.
Expand All @@ -31,7 +31,7 @@ declare_lint_pass!(ErasingOp => [ERASING_OP]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if in_macro_or_desugar(e.span) {
if e.span.from_expansion() {
return;
}
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.node {
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::utils::paths;
use crate::utils::{
in_macro_or_desugar, is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet,
span_lint_and_then, walk_ptrs_ty,
is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc::hir::*;
Expand Down Expand Up @@ -40,7 +39,7 @@ declare_lint_pass!(UselessFormat => [USELESS_FORMAT]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let Some(span) = is_expn_of(expr.span, "format") {
if in_macro_or_desugar(span) {
if span.from_expansion() {
return;
}
match expr.node {
Expand Down
Loading

0 comments on commit d9b8508

Please sign in to comment.