Skip to content

Commit ce5a662

Browse files
committed
submodules: update clippy from 164310d to dc69a5c
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. ````
1 parent ea2cfe0 commit ce5a662

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1159
-681
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222
install:
2323
- |
2424
if [ -z ${INTEGRATION} ]; then
25-
rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
25+
# rustup component add rustfmt || cargo install --git https://github.com/rust-lang/rustfmt/ --force
2626
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
2727
. $HOME/.nvm/nvm.sh
2828
nvm install stable

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ Released 2018-09-13
973973
[`ineffective_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#ineffective_bit_mask
974974
[`infallible_destructuring_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#infallible_destructuring_match
975975
[`infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#infinite_iter
976+
[`inherent_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string
977+
[`inherent_to_string_shadow_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#inherent_to_string_shadow_display
976978
[`inline_always`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_always
977979
[`inline_fn_without_body`]: https://rust-lang.github.io/rust-clippy/master/index.html#inline_fn_without_body
978980
[`int_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#int_plus_one

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 306 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 308 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

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ install:
2222
- del rust-toolchain
2323
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
2424
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
25-
- rustup component add rustfmt --toolchain nightly
25+
#- rustup component add rustfmt --toolchain nightly
2626
- rustup default master
2727
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
2828
- rustc -V

clippy_dev/src/stderr_length_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::prelude::*;
77
// The maximum length allowed for stderr files.
88
//
99
// We limit this because small files are easier to deal with than bigger files.
10-
const LIMIT: usize = 320;
10+
const LIMIT: usize = 275;
1111

1212
pub fn check() {
1313
let stderr_files = stderr_files();

clippy_dummy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_dummy" # rename to clippy before publishing
3-
version = "0.0.302"
3+
version = "0.0.303"
44
authors = ["Manish Goregaokar <[email protected]>"]
55
edition = "2018"
66
readme = "crates-readme.md"

clippy_dummy/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate term;
33
fn main() {
44
if let Err(_) = foo() {
55
eprintln!("error: Clippy is no longer available via crates.io\n");
6-
eprintln!("help: please run `rustup component add clippy-preview` instead");
6+
eprintln!("help: please run `rustup component add clippy` instead");
77
}
88
std::process::exit(1);
99
}
@@ -31,7 +31,7 @@ fn foo() -> Result<(), ()> {
3131
write!(t, "please run `").map_err(|_| ())?;
3232

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

3636
t.reset().map_err(|_| ())?;
3737
t.fg(term::color::WHITE).map_err(|_| ())?;

clippy_dummy/crates-readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Installing clippy via crates.io is deprecated. Please use the following:
22

33
```terminal
4-
rustup component add clippy-preview
4+
rustup component add clippy
55
```
66

77
on a Rust version 1.29 or later. You may need to run `rustup self update` if it complains about a missing clippy binary.

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ semver = "0.9.0"
2727
serde = { version = "1.0", features = ["derive"] }
2828
toml = "0.5"
2929
unicode-normalization = "0.1"
30-
pulldown-cmark = "0.5.2"
30+
pulldown-cmark = "0.5.3"
3131
url = "1.7.0"
3232
if_chain = "1.0.0"
3333
smallvec = { version = "0.6.5", features = ["union"] }

clippy_lints/src/double_comparison.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl<'a, 'tcx> DoubleComparisons {
6363
);
6464
}};
6565
}
66+
#[rustfmt::skip]
6667
match (op, lkind, rkind) {
6768
(BinOpKind::Or, BinOpKind::Eq, BinOpKind::Lt) | (BinOpKind::Or, BinOpKind::Lt, BinOpKind::Eq) => {
6869
lint_double_comparison!(<=)

clippy_lints/src/implicit_return.rs

+91-63
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
use crate::utils::{in_macro_or_desugar, is_expn_of, snippet_opt, span_lint_and_then};
2-
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource};
3-
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use rustc::{declare_lint_pass, declare_tool_lint};
1+
use crate::utils::{
2+
in_macro_or_desugar, match_def_path,
3+
paths::{BEGIN_PANIC, BEGIN_PANIC_FMT},
4+
resolve_node, snippet_opt, span_lint_and_then,
5+
};
6+
use if_chain::if_chain;
7+
use rustc::{
8+
declare_lint_pass, declare_tool_lint,
9+
hir::{intravisit::FnKind, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, StmtKind},
10+
lint::{LateContext, LateLintPass, LintArray, LintPass},
11+
};
512
use rustc_errors::Applicability;
613
use syntax::source_map::Span;
714

@@ -35,71 +42,92 @@ declare_clippy_lint! {
3542

3643
declare_lint_pass!(ImplicitReturn => [IMPLICIT_RETURN]);
3744

38-
impl ImplicitReturn {
39-
fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) {
40-
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
41-
if let Some(snippet) = snippet_opt(cx, inner_span) {
42-
db.span_suggestion(
43-
outer_span,
44-
msg,
45-
format!("return {}", snippet),
46-
Applicability::MachineApplicable,
47-
);
48-
}
49-
});
45+
static LINT_BREAK: &str = "change `break` to `return` as shown";
46+
static LINT_RETURN: &str = "add `return` as shown";
47+
48+
fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str) {
49+
let outer_span = span_to_outer_expn(outer_span);
50+
let inner_span = span_to_outer_expn(inner_span);
51+
52+
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
53+
if let Some(snippet) = snippet_opt(cx, inner_span) {
54+
db.span_suggestion(
55+
outer_span,
56+
msg,
57+
format!("return {}", snippet),
58+
Applicability::MachineApplicable,
59+
);
60+
}
61+
});
62+
}
63+
64+
fn span_to_outer_expn(span: Span) -> Span {
65+
if let Some(expr) = span.ctxt().outer_expn_info() {
66+
span_to_outer_expn(expr.call_site)
67+
} else {
68+
span
5069
}
70+
}
5171

52-
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
53-
match &expr.node {
54-
// loops could be using `break` instead of `return`
55-
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
56-
if let Some(expr) = &block.expr {
57-
Self::expr_match(cx, expr);
58-
}
59-
// only needed in the case of `break` with `;` at the end
60-
else if let Some(stmt) = block.stmts.last() {
61-
if let rustc::hir::StmtKind::Semi(expr, ..) = &stmt.node {
62-
// make sure it's a break, otherwise we want to skip
63-
if let ExprKind::Break(.., break_expr) = &expr.node {
64-
if let Some(break_expr) = break_expr {
65-
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
66-
}
67-
}
72+
fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
73+
match &expr.node {
74+
// loops could be using `break` instead of `return`
75+
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
76+
if let Some(expr) = &block.expr {
77+
expr_match(cx, expr);
78+
}
79+
// only needed in the case of `break` with `;` at the end
80+
else if let Some(stmt) = block.stmts.last() {
81+
if_chain! {
82+
if let StmtKind::Semi(expr, ..) = &stmt.node;
83+
// make sure it's a break, otherwise we want to skip
84+
if let ExprKind::Break(.., break_expr) = &expr.node;
85+
if let Some(break_expr) = break_expr;
86+
then {
87+
lint(cx, expr.span, break_expr.span, LINT_BREAK);
6888
}
6989
}
70-
},
71-
// use `return` instead of `break`
72-
ExprKind::Break(.., break_expr) => {
73-
if let Some(break_expr) = break_expr {
74-
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
75-
}
76-
},
77-
ExprKind::Match(.., arms, source) => {
78-
let check_all_arms = match source {
79-
MatchSource::IfLetDesugar {
80-
contains_else_clause: has_else,
81-
} => *has_else,
82-
_ => true,
83-
};
90+
}
91+
},
92+
// use `return` instead of `break`
93+
ExprKind::Break(.., break_expr) => {
94+
if let Some(break_expr) = break_expr {
95+
lint(cx, expr.span, break_expr.span, LINT_BREAK);
96+
}
97+
},
98+
ExprKind::Match(.., arms, source) => {
99+
let check_all_arms = match source {
100+
MatchSource::IfLetDesugar {
101+
contains_else_clause: has_else,
102+
} => *has_else,
103+
_ => true,
104+
};
84105

85-
if check_all_arms {
86-
for arm in arms {
87-
Self::expr_match(cx, &arm.body);
88-
}
89-
} else {
90-
Self::expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body);
106+
if check_all_arms {
107+
for arm in arms {
108+
expr_match(cx, &arm.body);
91109
}
92-
},
93-
// skip if it already has a return statement
94-
ExprKind::Ret(..) => (),
95-
// everything else is missing `return`
96-
_ => {
97-
// make sure it's not just an unreachable expression
98-
if is_expn_of(expr.span, "unreachable").is_none() {
99-
Self::lint(cx, expr.span, expr.span, "add `return` as shown")
110+
} else {
111+
expr_match(cx, &arms.first().expect("if let doesn't have a single arm").body);
112+
}
113+
},
114+
// skip if it already has a return statement
115+
ExprKind::Ret(..) => (),
116+
// make sure it's not a call that panics
117+
ExprKind::Call(expr, ..) => {
118+
if_chain! {
119+
if let ExprKind::Path(qpath) = &expr.node;
120+
if let Some(path_def_id) = resolve_node(cx, qpath, expr.hir_id).opt_def_id();
121+
if match_def_path(cx, path_def_id, &BEGIN_PANIC) ||
122+
match_def_path(cx, path_def_id, &BEGIN_PANIC_FMT);
123+
then { }
124+
else {
125+
lint(cx, expr.span, expr.span, LINT_RETURN)
100126
}
101-
},
102-
}
127+
}
128+
},
129+
// everything else is missing `return`
130+
_ => lint(cx, expr.span, expr.span, LINT_RETURN),
103131
}
104132
}
105133

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

0 commit comments

Comments
 (0)