Skip to content

Commit

Permalink
submodules: update clippy from 164310d to dc69a5c
Browse files Browse the repository at this point in the history
Changes:
````
ci: temporarily disable rustfmt checks/tetss since it's broken for nightly
rustup rust-lang/rust#62964
Bump version of clippy_dummy
update test stderr, not sure which rustc pull request caused this.
rustup rust-lang/rust#62859
Fix tests for edition 2018 compatibility
Revert "Revert global fmt config and use `rustfmt::skip`"
Fix breakage due to rust-lang/rust#60913
Fix breakage due to rust-lang/rust#62705
Revert global fmt config and use `rustfmt::skip`
Fix fmt
rustup rust-lang/rust#62679
Update pulldown-cmark to 0.5.3
rustup rust-lang/rust#62764
Add test
Format code
Decrease maximum length for stderr files
Improved imports
Fix "unkown clippy lint" error in UI test.
Corrections for PR review.
Implement lint for inherent to_string() method.
UI Test Cleanup: Extract match_ref_pats tests
Update UI tests
Allow no_effect lint
Remove comment
cargo fmt
UI Test Cleanup: Split up checked_unwrap tests
Removed lintining on never type.
UI Test Cleanup: Split out out_of_bounds_indexing
false positives fixes of `implicit_return`
Ignore generated fresh lifetimes in elision check.
````
  • Loading branch information
matthiaskrgr committed Jul 27, 2019
1 parent ea2cfe0 commit ce5a662
Show file tree
Hide file tree
Showing 74 changed files with 1,159 additions and 681 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
install:
- |
if [ -z ${INTEGRATION} ]; then
rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
# rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
. $HOME/.nvm/nvm.sh
nvm install stable
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,8 @@ Released 2018-09-13
[`ineffective_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask
[`infallible_destructuring_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#infallible_destructuring_match
[`infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter
[`inherent_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string
[`inherent_to_string_shadow_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string_shadow_display
[`inline_always`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_always
[`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body
[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one
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 306 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
[There are 308 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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install:
- del rust-toolchain
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
- rustup component add rustfmt --toolchain nightly
#- rustup component add rustfmt --toolchain nightly
- rustup default master
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
- rustc -V
Expand Down
2 changes: 1 addition & 1 deletion clippy_dev/src/stderr_length_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::prelude::*;
// The maximum length allowed for stderr files.
//
// We limit this because small files are easier to deal with than bigger files.
const LIMIT: usize = 320;
const LIMIT: usize = 275;

pub fn check() {
let stderr_files = stderr_files();
Expand Down
2 changes: 1 addition & 1 deletion clippy_dummy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_dummy" # rename to clippy before publishing
version = "0.0.302"
version = "0.0.303"
authors = ["Manish Goregaokar <manishsmail@gmail.com>"]
edition = "2018"
readme = "crates-readme.md"
Expand Down
4 changes: 2 additions & 2 deletions clippy_dummy/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate term;
fn main() {
if let Err(_) = foo() {
eprintln!("error: Clippy is no longer available via crates.io\n");
eprintln!("help: please run `rustup component add clippy-preview` instead");
eprintln!("help: please run `rustup component add clippy` instead");
}
std::process::exit(1);
}
Expand Down Expand Up @@ -31,7 +31,7 @@ fn foo() -> Result<(), ()> {
write!(t, "please run `").map_err(|_| ())?;

t.attr(term::Attr::Bold).map_err(|_| ())?;
write!(t, "rustup component add clippy-preview").map_err(|_| ())?;
write!(t, "rustup component add clippy").map_err(|_| ())?;

t.reset().map_err(|_| ())?;
t.fg(term::color::WHITE).map_err(|_| ())?;
Expand Down
2 changes: 1 addition & 1 deletion clippy_dummy/crates-readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installing clippy via crates.io is deprecated. Please use the following:

```terminal
rustup component add clippy-preview
rustup component add clippy
```

on a Rust version 1.29 or later. You may need to run `rustup self update` if it complains about a missing clippy binary.
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ semver = "0.9.0"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5"
unicode-normalization = "0.1"
pulldown-cmark = "0.5.2"
pulldown-cmark = "0.5.3"
url = "1.7.0"
if_chain = "1.0.0"
smallvec = { version = "0.6.5", features = ["union"] }
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/double_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl<'a, 'tcx> DoubleComparisons {
);
}};
}
#[rustfmt::skip]
match (op, lkind, rkind) {
(BinOpKind::Or, BinOpKind::Eq, BinOpKind::Lt) | (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Eq) => {
lint_double_comparison!(<=)
Expand Down
154 changes: 91 additions & 63 deletions clippy_lints/src/implicit_return.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use crate::utils::{in_macro_or_desugar, is_expn_of, snippet_opt, span_lint_and_then};
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use crate::utils::{
in_macro_or_desugar, match_def_path,
paths::{BEGIN_PANIC, BEGIN_PANIC_FMT},
resolve_node, snippet_opt, span_lint_and_then,
};
use if_chain::if_chain;
use rustc::{
declare_lint_pass, declare_tool_lint,
hir::{intravisit::FnKind, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, StmtKind},
lint::{LateContext, LateLintPass, LintArray, LintPass},
};
use rustc_errors::Applicability;
use syntax::source_map::Span;

Expand Down Expand Up @@ -35,71 +42,92 @@ declare_clippy_lint! {

declare_lint_pass!(ImplicitReturn => [IMPLICIT_RETURN]);

impl ImplicitReturn {
fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) {
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
if let Some(snippet) = snippet_opt(cx, inner_span) {
db.span_suggestion(
outer_span,
msg,
format!("return {}", snippet),
Applicability::MachineApplicable,
);
}
});
static LINT_BREAK: &str = "change `break` to `return` as shown";
static LINT_RETURN: &str = "add `return` as shown";

fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) {
let outer_span = span_to_outer_expn(outer_span);
let inner_span = span_to_outer_expn(inner_span);

span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
if let Some(snippet) = snippet_opt(cx, inner_span) {
db.span_suggestion(
outer_span,
msg,
format!("return {}", snippet),
Applicability::MachineApplicable,
);
}
});
}

fn span_to_outer_expn(span: Span) -> Span {
if let Some(expr) = span.ctxt().outer_expn_info() {
span_to_outer_expn(expr.call_site)
} else {
span
}
}

fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
match &expr.node {
// loops could be using `break` instead of `return`
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
if let Some(expr) = &block.expr {
Self::expr_match(cx, expr);
}
// only needed in the case of `break` with `;` at the end
else if let Some(stmt) = block.stmts.last() {
if let rustc::hir::StmtKind::Semi(expr, ..) = &stmt.node {
// make sure it's a break, otherwise we want to skip
if let ExprKind::Break(.., break_expr) = &expr.node {
if let Some(break_expr) = break_expr {
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
}
}
fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
match &expr.node {
// loops could be using `break` instead of `return`
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
if let Some(expr) = &block.expr {
expr_match(cx, expr);
}
// only needed in the case of `break` with `;` at the end
else if let Some(stmt) = block.stmts.last() {
if_chain! {
if let StmtKind::Semi(expr, ..) = &stmt.node;
// make sure it's a break, otherwise we want to skip
if let ExprKind::Break(.., break_expr) = &expr.node;
if let Some(break_expr) = break_expr;
then {
lint(cx, expr.span, break_expr.span, LINT_BREAK);
}
}
},
// use `return` instead of `break`
ExprKind::Break(.., break_expr) => {
if let Some(break_expr) = break_expr {
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
}
},
ExprKind::Match(.., arms, source) => {
let check_all_arms = match source {
MatchSource::IfLetDesugar {
contains_else_clause: has_else,
} => *has_else,
_ => true,
};
}
},
// use `return` instead of `break`
ExprKind::Break(.., break_expr) => {
if let Some(break_expr) = break_expr {
lint(cx, expr.span, break_expr.span, LINT_BREAK);
}
},
ExprKind::Match(.., arms, source) => {
let check_all_arms = match source {
MatchSource::IfLetDesugar {
contains_else_clause: has_else,
} => *has_else,
_ => true,
};

if check_all_arms {
for arm in arms {
Self::expr_match(cx, &arm.body);
}
} else {
Self::expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body);
if check_all_arms {
for arm in arms {
expr_match(cx, &arm.body);
}
},
// skip if it already has a return statement
ExprKind::Ret(..) => (),
// everything else is missing `return`
_ => {
// make sure it's not just an unreachable expression
if is_expn_of(expr.span, "unreachable").is_none() {
Self::lint(cx, expr.span, expr.span, "add `return` as shown")
} else {
expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body);
}
},
// skip if it already has a return statement
ExprKind::Ret(..) => (),
// make sure it's not a call that panics
ExprKind::Call(expr, ..) => {
if_chain! {
if let ExprKind::Path(qpath) = &expr.node;
if let Some(path_def_id) = resolve_node(cx, qpath, expr.hir_id).opt_def_id();
if match_def_path(cx, path_def_id, &BEGIN_PANIC) ||
match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT);
then { }
else {
lint(cx, expr.span, expr.span, LINT_RETURN)
}
},
}
}
},
// everything else is missing `return`
_ => lint(cx, expr.span, expr.span, LINT_RETURN),
}
}

Expand All @@ -119,7 +147,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn {
// checking return type through MIR, HIR is not able to determine inferred closure return types
// make sure it's not a macro
if !mir.return_ty().is_unit() && !in_macro_or_desugar(span) {
Self::expr_match(cx, &body.value);
expr_match(cx, &body.value);
}
}
}
Loading

0 comments on commit ce5a662

Please sign in to comment.