Skip to content

Commit 4c7d644

Browse files
committed
submodules: update clippy from 754b4c0 to b2601be
Changes: ```` Fix NAIVE_BYTECOUNT applicability Fix dogfood error Change Applicability of MISTYPED_LITERAL_SUFFIX Add applicability level to (nearly) every span_lint_and_sugg function Update stderr file Fix bugs and improve documentation Add Applicability::Unspecified to span_lint_and_sugg functions Introduce snippet_with_applicability and hir_with_applicability functions readme: tell how to install clippy on travis from git if it is not shipped with a nightly. constants: add u128 i128 builtin types and fix outdated url Update lints Lint only the first statment/expression after alloc Fix some warnings related to Self Rename some symbols Split lint into slow and unsafe vector initalization Add unsafe set_len initialization Add slow zero-filled vector initialization lint Travis: Remove `sudo: false` Downgrade needless_pass_by_value to allow by default ````
1 parent 5afee64 commit 4c7d644

Some content is hidden

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

43 files changed

+1123
-302
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ os:
77
- osx
88
- windows
99

10-
sudo: false
11-
1210
branches:
1311
# Don't build these branches
1412
except:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ All notable changes to this project will be documented in this file.
842842
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
843843
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
844844
[`single_match_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match_else
845+
[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
845846
[`str_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#str_to_string
846847
[`string_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add
847848
[`string_add_assign`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_add_assign
@@ -880,6 +881,7 @@ All notable changes to this project will be documented in this file.
880881
[`unneeded_field_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#unneeded_field_pattern
881882
[`unreadable_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal
882883
[`unsafe_removed_from_name`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_removed_from_name
884+
[`unsafe_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unsafe_vector_initialization
883885
[`unseparated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#unseparated_literal_suffix
884886
[`unstable_as_mut_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_mut_slice
885887
[`unstable_as_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#unstable_as_slice

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We are currently in the process of discussing Clippy 1.0 via the RFC process in
99

1010
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
1111

12-
[There are 288 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
12+
[There are 290 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1313

1414
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1515

@@ -108,6 +108,18 @@ script:
108108
# etc.
109109
```
110110

111+
It might happen that clippy is not available for a certain nightly release.
112+
In this case you can try to conditionally install clippy from the git repo.
113+
114+
```yaml
115+
language: rust
116+
rust:
117+
- nightly
118+
before_script:
119+
- rustup component add clippy-preview --toolchain=nightly || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy
120+
# etc
121+
```
122+
111123
## Configuration
112124

113125
Some lints can be configured in a TOML file named `clippy.toml` or `.clippy.toml`. It contains a basic `variable = value` mapping eg.

clippy_lints/src/attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ impl EarlyLintPass for CfgAttrPass {
532532
"`cfg_attr` is deprecated for rustfmt and got replaced by tool_attributes",
533533
"use",
534534
format!("{}rustfmt::skip]", attr_style),
535+
Applicability::MachineApplicable,
535536
);
536537
}
537538
}

clippy_lints/src/bytecount.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010

1111
use crate::rustc::hir::*;
1212
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13-
use crate::rustc::{declare_tool_lint, lint_array};
14-
use if_chain::if_chain;
1513
use crate::rustc::ty;
14+
use crate::rustc::{declare_tool_lint, lint_array};
15+
use crate::rustc_errors::Applicability;
1616
use crate::syntax::ast::{Name, UintTy};
17-
use crate::utils::{contains_name, get_pat_name, match_type, paths, single_segment_path, snippet, span_lint_and_sugg,
18-
walk_ptrs_ty};
17+
use crate::utils::{
18+
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
19+
span_lint_and_sugg, walk_ptrs_ty,
20+
};
21+
use if_chain::if_chain;
1922

2023
/// **What it does:** Checks for naive byte counts
2124
///
@@ -89,14 +92,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
8992
} else {
9093
&filter_args[0]
9194
};
92-
span_lint_and_sugg(cx,
93-
NAIVE_BYTECOUNT,
94-
expr.span,
95-
"You appear to be counting bytes the naive way",
96-
"Consider using the bytecount crate",
97-
format!("bytecount::count({}, {})",
98-
snippet(cx, haystack.span, ".."),
99-
snippet(cx, needle.span, "..")));
95+
let mut applicability = Applicability::MachineApplicable;
96+
span_lint_and_sugg(
97+
cx,
98+
NAIVE_BYTECOUNT,
99+
expr.span,
100+
"You appear to be counting bytes the naive way",
101+
"Consider using the bytecount crate",
102+
format!("bytecount::count({}, {})",
103+
snippet_with_applicability(cx, haystack.span, "..", &mut applicability),
104+
snippet_with_applicability(cx, needle.span, "..", &mut applicability)),
105+
applicability,
106+
);
100107
}
101108
};
102109
}

clippy_lints/src/collapsible_if.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::rustc::{declare_tool_lint, lint_array};
2727
use if_chain::if_chain;
2828
use crate::syntax::ast;
2929

30-
use crate::utils::{in_macro, snippet_block, span_lint_and_sugg, span_lint_and_then};
30+
use crate::utils::{in_macro, snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
3131
use crate::utils::sugg::Sugg;
3232
use crate::rustc_errors::Applicability;
3333

@@ -128,12 +128,16 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
128128
then {
129129
match else_.node {
130130
ast::ExprKind::If(..) | ast::ExprKind::IfLet(..) => {
131-
span_lint_and_sugg(cx,
132-
COLLAPSIBLE_IF,
133-
block.span,
134-
"this `else { if .. }` block can be collapsed",
135-
"try",
136-
snippet_block(cx, else_.span, "..").into_owned());
131+
let mut applicability = Applicability::MachineApplicable;
132+
span_lint_and_sugg(
133+
cx,
134+
COLLAPSIBLE_IF,
135+
block.span,
136+
"this `else { if .. }` block can be collapsed",
137+
"try",
138+
snippet_block_with_applicability(cx, else_.span, "..", &mut applicability).into_owned(),
139+
applicability,
140+
);
137141
}
138142
_ => (),
139143
}

clippy_lints/src/default_trait_access.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010

1111
use crate::rustc::hir::*;
1212
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
13+
use crate::rustc::ty::TyKind;
1314
use crate::rustc::{declare_tool_lint, lint_array};
15+
use crate::rustc_errors::Applicability;
1416
use if_chain::if_chain;
15-
use crate::rustc::ty::TyKind;
1617

1718
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
1819

@@ -80,7 +81,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
8081
expr.span,
8182
&format!("Calling {} is more clear than this expression", replacement),
8283
"try",
83-
replacement);
84+
replacement,
85+
Applicability::Unspecified, // First resolve the TODO above
86+
);
8487
}
8588
},
8689
QPath::TypeRelative(..) => {},

clippy_lints/src/double_comparison.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
use crate::rustc::hir::*;
1414
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1515
use crate::rustc::{declare_tool_lint, lint_array};
16+
use crate::rustc_errors::Applicability;
1617
use crate::syntax::source_map::Span;
1718

18-
use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};
19+
use crate::utils::{snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
1920

2021
/// **What it does:** Checks for double comparions that could be simpified to a single expression.
2122
///
@@ -70,12 +71,19 @@ impl<'a, 'tcx> Pass {
7071
}
7172
macro_rules! lint_double_comparison {
7273
($op:tt) => {{
73-
let lhs_str = snippet(cx, llhs.span, "");
74-
let rhs_str = snippet(cx, lrhs.span, "");
74+
let mut applicability = Applicability::MachineApplicable;
75+
let lhs_str = snippet_with_applicability(cx, llhs.span, "", &mut applicability);
76+
let rhs_str = snippet_with_applicability(cx, lrhs.span, "", &mut applicability);
7577
let sugg = format!("{} {} {}", lhs_str, stringify!($op), rhs_str);
76-
span_lint_and_sugg(cx, DOUBLE_COMPARISONS, span,
77-
"This binary expression can be simplified",
78-
"try", sugg);
78+
span_lint_and_sugg(
79+
cx,
80+
DOUBLE_COMPARISONS,
81+
span,
82+
"This binary expression can be simplified",
83+
"try",
84+
sugg,
85+
applicability,
86+
);
7987
}}
8088
}
8189
match (op, lkind, rkind) {

clippy_lints/src/duration_subsec.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use crate::rustc::hir::*;
1212
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1313
use crate::rustc::{declare_tool_lint, lint_array};
14-
use if_chain::if_chain;
14+
use crate::rustc_errors::Applicability;
1515
use crate::syntax::source_map::Spanned;
16+
use if_chain::if_chain;
1617

1718
use crate::consts::{constant, Constant};
1819
use crate::utils::paths;
19-
use crate::utils::{match_type, snippet, span_lint_and_sugg, walk_ptrs_ty};
20+
use crate::utils::{match_type, snippet_with_applicability, span_lint_and_sugg, walk_ptrs_ty};
2021

2122
/// **What it does:** Checks for calculation of subsecond microseconds or milliseconds
2223
/// from other `Duration` methods.
@@ -60,13 +61,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
6061
("subsec_nanos", 1_000) => "subsec_micros",
6162
_ => return,
6263
};
64+
let mut applicability = Applicability::MachineApplicable;
6365
span_lint_and_sugg(
6466
cx,
6567
DURATION_SUBSEC,
6668
expr.span,
6769
&format!("Calling `{}()` is more concise than this calculation", suggested_fn),
6870
"try",
69-
format!("{}.{}()", snippet(cx, args[0].span, "_"), suggested_fn),
71+
format!("{}.{}()", snippet_with_applicability(cx, args[0].span, "_", &mut applicability), suggested_fn),
72+
applicability,
7073
);
7174
}
7275
}

clippy_lints/src/else_if_without_else.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass, in_ex
1414
use crate::rustc::{declare_tool_lint, lint_array};
1515
use crate::syntax::ast::*;
1616

17-
use crate::utils::span_lint_and_sugg;
17+
use crate::utils::span_help_and_lint;
1818

1919
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
2020
/// but without a final `else` branch.
@@ -66,13 +66,12 @@ impl EarlyLintPass for ElseIfWithoutElse {
6666

6767
while let ExprKind::If(_, _, Some(ref els)) = item.node {
6868
if let ExprKind::If(_, _, None) = els.node {
69-
span_lint_and_sugg(
69+
span_help_and_lint(
7070
cx,
7171
ELSE_IF_WITHOUT_ELSE,
7272
els.span,
7373
"if expression with an `else if`, but without a final `else`",
7474
"add an `else` block here",
75-
String::new()
7675
);
7776
}
7877

0 commit comments

Comments
 (0)