Skip to content

Commit 1d02bd0

Browse files
committed
update clippy
1 parent 2ed90a6 commit 1d02bd0

29 files changed

+404
-306
lines changed

.github/PULL_REQUEST_TEMPLATE

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ checked during review or continuous integration.
1616
- [ ] Followed [lint naming conventions][lint_naming]
1717
- [ ] Added passing UI tests (including committed `.stderr` file)
1818
- [ ] `cargo test` passes locally
19-
- [ ] Executed `util/dev update_lints`
19+
- [ ] Executed `./util/dev update_lints`
2020
- [ ] Added lint documentation
21-
- [ ] Run `cargo fmt`
21+
- [ ] Run `./util/dev fmt`
22+
23+
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
2224

2325
Note that you can skip the above if you are just opening a WIP PR in
2426
order to get feedback.

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,6 @@ Released 2018-09-13
982982
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
983983
[`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array
984984
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
985-
[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref
986985
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
987986
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
988987
[`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements

README.md

Lines changed: 20 additions & 11 deletions
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 310 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 309 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

@@ -36,6 +36,7 @@ Table of contents:
3636

3737
* [Usage instructions](#usage)
3838
* [Configuration](#configuration)
39+
* [Contributing](#contributing)
3940
* [License](#license)
4041

4142
## Usage
@@ -52,7 +53,7 @@ subcommand.
5253

5354
#### Step 1: Install rustup
5455

55-
You can install [rustup](http://rustup.rs/) on supported platforms. This will help
56+
You can install [rustup](https://rustup.rs/) on supported platforms. This will help
5657
us install Clippy and its dependencies.
5758

5859
If you already have rustup installed, update to ensure you have the latest
@@ -79,6 +80,15 @@ Now you can run Clippy by invoking the following command:
7980
cargo clippy
8081
```
8182

83+
#### Automatically applying Clippy suggestions
84+
85+
Some Clippy lint suggestions can be automatically applied by `cargo fix`.
86+
Note that this is still experimental and only supported on the nightly channel:
87+
88+
```terminal
89+
cargo fix -Z unstable-options --clippy
90+
```
91+
8292
### Running Clippy from the command line without installing it
8393

8494
To have cargo compile your crate with Clippy without Clippy installation
@@ -88,8 +98,7 @@ in your code, you can use:
8898
cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml
8999
```
90100

91-
*[Note](https://github.com/rust-lang/rust-clippy/wiki#a-word-of-warning):*
92-
Be sure that Clippy was compiled with the same version of rustc that cargo invokes here!
101+
*Note:* Be sure that Clippy was compiled with the same version of rustc that cargo invokes here!
93102

94103
### Travis CI
95104

@@ -113,20 +122,20 @@ script:
113122
```
114123

115124
If you are on nightly, It might happen that Clippy is not available for a certain nightly release.
116-
In this case you can try to conditionally install Clippy from the git repo.
125+
In this case you can try to conditionally install Clippy from the Git repo.
117126

118127
```yaml
119128
language: rust
120129
rust:
121130
- nightly
122131
before_script:
123132
- rustup component add clippy --toolchain=nightly || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy
124-
# etc
133+
# etc.
125134
```
126135

127136
Note that adding `-D warnings` will cause your build to fail if **any** warnings are found in your code.
128137
That includes warnings found by rustc (e.g. `dead_code`, etc.). If you want to avoid this and only cause
129-
an error for clippy warnings, use `#![deny(clippy::all)]` in your code or `-D clippy::all` on the command
138+
an error for Clippy warnings, use `#![deny(clippy::all)]` in your code or `-D clippy::all` on the command
130139
line. (You can swap `clippy::all` with the specific lint category you are targeting.)
131140

132141
## Configuration
@@ -154,9 +163,9 @@ You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
154163
`#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive
155164
lints prone to false positives.
156165

157-
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc)
166+
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
158167

159-
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc
168+
* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc.
160169

161170
Note: `deny` produces errors instead of warnings.
162171

@@ -171,7 +180,7 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
171180
Copyright 2014-2019 The Rust Project Developers
172181

173182
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
174-
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
175-
<LICENSE-MIT or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT)>, at your
183+
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
184+
<LICENSE-MIT or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)>, at your
176185
option. All files in the project carrying such notice may not be
177186
copied, modified, or distributed except according to those terms.

clippy_lints/src/deprecated_lints.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,12 @@ declare_deprecated_lint! {
113113
pub UNSAFE_VECTOR_INITIALIZATION,
114114
"the replacement suggested by this lint had substantially different behavior"
115115
}
116+
117+
/// **What it does:** Nothing. This lint has been deprecated.
118+
///
119+
/// **Deprecation reason:** This lint has been superseded by the warn-by-default
120+
/// `invalid_value` rustc lint.
121+
declare_clippy_lint! {
122+
pub INVALID_REF,
123+
"superseded by rustc lint `invalid_value`"
124+
}

clippy_lints/src/enum_variants.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn check_variant(
160160
let name = var2str(var);
161161
if partial_match(item_name, &name) == item_name_chars
162162
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
163+
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
163164
{
164165
span_lint(cx, lint, var.span, "Variant name starts with the enum's name");
165166
}
@@ -178,6 +179,9 @@ fn check_variant(
178179
let pre_camel = camel_case::until(pre);
179180
pre = &pre[..pre_camel];
180181
while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() {
182+
if next.is_numeric() {
183+
return;
184+
}
181185
if next.is_lowercase() {
182186
let last = pre.len() - last.len_utf8();
183187
let last_camel = camel_case::until(&pre[..last]);

clippy_lints/src/implicit_return.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ static LINT_BREAK: &str = "change `break` to `return` as shown";
4646
static LINT_RETURN: &str = "add `return` as shown";
4747

4848
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);
49+
let outer_span = outer_span.source_callsite();
50+
let inner_span = inner_span.source_callsite();
5151

5252
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
5353
if let Some(snippet) = snippet_opt(cx, inner_span) {
@@ -61,14 +61,6 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str)
6161
});
6262
}
6363

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
69-
}
70-
}
71-
7264
fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
7365
match &expr.node {
7466
// loops could be using `break` instead of `return`

clippy_lints/src/invalid_ref.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

clippy_lints/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ pub mod inherent_to_string;
200200
pub mod inline_fn_without_body;
201201
pub mod int_plus_one;
202202
pub mod integer_division;
203-
pub mod invalid_ref;
204203
pub mod items_after_statements;
205204
pub mod large_enum_variant;
206205
pub mod len_zero;
@@ -558,7 +557,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
558557
reg.register_late_lint_pass(box bytecount::ByteCount);
559558
reg.register_late_lint_pass(box infinite_iter::InfiniteIter);
560559
reg.register_late_lint_pass(box inline_fn_without_body::InlineFnWithoutBody);
561-
reg.register_late_lint_pass(box invalid_ref::InvalidRef);
562560
reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default());
563561
reg.register_late_lint_pass(box types::ImplicitHasher);
564562
reg.register_early_lint_pass(box redundant_static_lifetimes::RedundantStaticLifetimes);
@@ -736,7 +734,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
736734
inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY,
737735
inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
738736
int_plus_one::INT_PLUS_ONE,
739-
invalid_ref::INVALID_REF,
740737
large_enum_variant::LARGE_ENUM_VARIANT,
741738
len_zero::LEN_WITHOUT_IS_EMPTY,
742739
len_zero::LEN_ZERO,
@@ -1094,7 +1091,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
10941091
infinite_iter::INFINITE_ITER,
10951092
inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY,
10961093
inline_fn_without_body::INLINE_FN_WITHOUT_BODY,
1097-
invalid_ref::INVALID_REF,
10981094
literal_representation::MISTYPED_LITERAL_SUFFIXES,
10991095
loops::FOR_LOOP_OVER_OPTION,
11001096
loops::FOR_LOOP_OVER_RESULT,

clippy_lints/src/methods/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
937937
["is_some", "position"] => lint_search_is_some(cx, expr, "position", arg_lists[1], arg_lists[0]),
938938
["is_some", "rposition"] => lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0]),
939939
["extend", ..] => lint_extend(cx, expr, arg_lists[0]),
940-
["as_ptr", "unwrap"] => lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0]),
940+
["as_ptr", "unwrap"] | ["as_ptr", "expect"] => {
941+
lint_cstring_as_ptr(cx, expr, &arg_lists[1][0], &arg_lists[0][0])
942+
},
941943
["nth", "iter"] => lint_iter_nth(cx, expr, arg_lists[1], false),
942944
["nth", "iter_mut"] => lint_iter_nth(cx, expr, arg_lists[1], true),
943945
["next", "skip"] => lint_iter_skip_next(cx, expr),
@@ -2329,13 +2331,20 @@ fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &
23292331
fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx hir::Expr, arg: &'tcx hir::Expr) {
23302332
if_chain! {
23312333
if let hir::ExprKind::Lit(lit) = &arg.node;
2332-
if let ast::LitKind::Str(r, _) = lit.node;
2334+
if let ast::LitKind::Str(r, style) = lit.node;
23332335
if r.as_str().len() == 1;
23342336
then {
23352337
let mut applicability = Applicability::MachineApplicable;
23362338
let snip = snippet_with_applicability(cx, arg.span, "..", &mut applicability);
2337-
let c = &snip[1..snip.len() - 1];
2338-
let hint = format!("'{}'", if c == "'" { "\\'" } else { c });
2339+
let ch = if let ast::StrStyle::Raw(nhash) = style {
2340+
let nhash = nhash as usize;
2341+
// for raw string: r##"a"##
2342+
&snip[(nhash + 2)..(snip.len() - 1 - nhash)]
2343+
} else {
2344+
// for regular string: "a"
2345+
&snip[1..(snip.len() - 1)]
2346+
};
2347+
let hint = format!("'{}'", if ch == "'" { "\\'" } else { ch });
23392348
span_lint_and_sugg(
23402349
cx,
23412350
SINGLE_CHAR_PATTERN,

clippy_lints/src/try_err.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{match_qpath, paths, snippet, span_lint_and_sugg};
1+
use crate::utils::{in_macro_or_desugar, match_qpath, paths, snippet, snippet_with_macro_callsite, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -67,10 +67,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr {
6767

6868
then {
6969
let err_type = cx.tables.expr_ty(err_arg);
70+
let origin_snippet = if in_macro_or_desugar(err_arg.span) {
71+
snippet_with_macro_callsite(cx, err_arg.span, "_")
72+
} else {
73+
snippet(cx, err_arg.span, "_")
74+
};
7075
let suggestion = if err_type == return_type {
71-
format!("return Err({})", snippet(cx, err_arg.span, "_"))
76+
format!("return Err({})", origin_snippet)
7277
} else {
73-
format!("return Err({}.into())", snippet(cx, err_arg.span, "_"))
78+
format!("return Err({}.into())", origin_snippet)
7479
};
7580

7681
span_lint_and_sugg(

0 commit comments

Comments
 (0)