Skip to content

Commit 2b06765

Browse files
committed
Update clippy
1 parent 8a2b6d9 commit 2b06765

18 files changed

+515
-370
lines changed

.travis.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ matrix:
6363
- env: INTEGRATION=chronotope/chrono
6464
- env: INTEGRATION=serde-rs/serde
6565
- env: INTEGRATION=Geal/nom
66-
# uncomment once https://github.com/rust-lang/rust/issues/55376 is fixed
67-
# - env: INTEGRATION=hyperium/hyper
66+
- env: INTEGRATION=hyperium/hyper
6867
allow_failures:
6968
- os: windows
7069
env: BASE_TEST=true
@@ -75,14 +74,13 @@ matrix:
7574
- os: windows
7675

7776
script:
78-
# uncomment once https://github.com/rust-lang/rust/issues/55376 is fixed
79-
# - |
80-
# rm rust-toolchain
81-
# cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
82-
# RUSTC_HASH=$(git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}')
83-
# travis_retry rustup-toolchain-install-master -f -n master $RUSTC_HASH
84-
# rustup default master
85-
# export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
77+
- |
78+
rm rust-toolchain
79+
cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
80+
RUSTC_HASH=$(git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}')
81+
travis_retry rustup-toolchain-install-master -f -n master $RUSTC_HASH
82+
rustup default master
83+
export LD_LIBRARY_PATH=$(rustc --print sysroot)/lib
8684
- |
8785
if [ -z ${INTEGRATION} ]; then
8886
./ci/base-tests.sh && sleep 5

appveyor.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ install:
2020
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
2121
- git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}' >rustc-hash.txt
2222
- set /p RUSTC_HASH=<rustc-hash.txt
23-
# uncomment once https://github.com/rust-lang/rust/issues/55376 is fixed
24-
# - del rust-toolchain
25-
# - cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
26-
# - rustup-toolchain-install-master %RUSTC_HASH% -f -n master
27-
# - rustup default master
28-
# - set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
23+
- del rust-toolchain
24+
- cargo install rustup-toolchain-install-master || echo "rustup-toolchain-install-master already installed"
25+
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
26+
- rustup default master
27+
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
2928
- rustc -V
3029
- cargo -V
3130

clippy_lints/src/booleans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
424424
improvements.push(suggestion);
425425
}
426426
}
427-
let nonminimal_bool_lint = |suggestions| {
427+
let nonminimal_bool_lint = |suggestions: Vec<_>| {
428428
span_lint_and_then(
429429
self.cx,
430430
NONMINIMAL_BOOL,
@@ -434,7 +434,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
434434
db.span_suggestions_with_applicability(
435435
e.span,
436436
"try",
437-
suggestions,
437+
suggestions.into_iter(),
438438
// nonminimal_bool can produce minimal but
439439
// not human readable expressions (#3141)
440440
Applicability::Unspecified,

clippy_lints/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use toml;
4848

4949
// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
5050
// as said in the README.md of this repository. If this changes, please update README.md.
51+
#[macro_export]
5152
macro_rules! declare_clippy_lint {
5253
{ pub $name:tt, style, $description:tt } => {
5354
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }

clippy_lints/src/literal_representation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ impl LintPass for LiteralDigitGrouping {
329329
lint_array!(
330330
UNREADABLE_LITERAL,
331331
INCONSISTENT_DIGIT_GROUPING,
332-
LARGE_DIGIT_GROUPS
332+
LARGE_DIGIT_GROUPS,
333+
MISTYPED_LITERAL_SUFFIXES,
333334
)
334335
}
335336
}

clippy_lints/src/methods/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,14 @@ declare_clippy_lint! {
568568
/// **Why is this bad?** Using the Index trait (`[]`) is more clear and more
569569
/// concise.
570570
///
571-
/// **Known problems:** None.
571+
/// **Known problems:** Not a replacement for error handling: Using either
572+
/// `.unwrap()` or the Index trait (`[]`) carries the risk of causing a `panic`
573+
/// if the value being accessed is `None`. If the use of `.get().unwrap()` is a
574+
/// temporary placeholder for dealing with the `Option` type, then this does
575+
/// not mitigate the need for error handling. If there is a chance that `.get()`
576+
/// will be `None` in your program, then it is advisable that the `None` case
577+
/// is handled in a future refactor instead of using `.unwrap()` or the Index
578+
/// trait.
572579
///
573580
/// **Example:**
574581
/// ```rust

clippy_lints/src/needless_bool.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::rustc::{declare_tool_lint, lint_array};
1717
use crate::rustc::hir::*;
1818
use crate::syntax::ast::LitKind;
1919
use crate::syntax::source_map::Spanned;
20-
use crate::utils::{snippet, span_lint, span_lint_and_sugg};
20+
use crate::utils::{in_macro, snippet, span_lint, span_lint_and_sugg};
2121
use crate::utils::sugg::Sugg;
2222

2323
/// **What it does:** Checks for expressions of the form `if c { true } else {
@@ -133,6 +133,9 @@ impl LintPass for BoolComparison {
133133

134134
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
135135
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
136+
if in_macro(e.span) {
137+
return;
138+
}
136139
use self::Expression::*;
137140
if let ExprKind::Binary(Spanned { node: BinOpKind::Eq, .. }, ref left_side, ref right_side) = e.node {
138141
match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) {

clippy_lints/src/use_self.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::syntax_pos::symbol::keywords::SelfType;
3636
/// }
3737
/// ```
3838
/// could be
39-
/// ```
39+
/// ```rust
4040
/// struct Foo {}
4141
/// impl Foo {
4242
/// fn new() -> Self {

clippy_lints/src/utils/internal_lints.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010

1111
use crate::utils::{
12-
match_qpath, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
12+
match_def_path, match_type, paths, span_help_and_lint, span_lint, span_lint_and_sugg, walk_ptrs_ty,
1313
};
1414
use if_chain::if_chain;
1515
use crate::rustc::hir;
1616
use crate::rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
1717
use crate::rustc::hir::*;
18+
use crate::rustc::hir::def::Def;
1819
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
1920
use crate::rustc::{declare_tool_lint, lint_array};
2021
use crate::rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -160,15 +161,21 @@ impl LintPass for LintWithoutLintPass {
160161

161162
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
162163
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
163-
if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
164-
if is_lint_ref_type(ty) {
164+
if let hir::ItemKind::Static(ref ty, MutImmutable, _) = item.node {
165+
if is_lint_ref_type(cx, ty) {
165166
self.declared_lints.insert(item.name, item.span);
166-
} else if is_lint_array_type(ty) && item.name == "ARRAY" {
167-
if let VisibilityKind::Inherited = item.vis.node {
167+
}
168+
} else if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
169+
if_chain! {
170+
if let hir::TraitRef{path, ..} = trait_ref;
171+
if let Def::Trait(def_id) = path.def;
172+
if match_def_path(cx.tcx, def_id, &paths::LINT_PASS);
173+
then {
168174
let mut collector = LintCollector {
169175
output: &mut self.registered_lints,
170176
cx,
171177
};
178+
let body_id = cx.tcx.hir.body_owned_by(impl_item_refs[0].id.node_id);
172179
collector.visit_expr(&cx.tcx.hir.body(body_id).value);
173180
}
174181
}
@@ -203,28 +210,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
203210
}
204211
}
205212

206-
fn is_lint_ref_type(ty: &Ty) -> bool {
213+
fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
207214
if let TyKind::Rptr(
208215
_,
209216
MutTy {
210217
ty: ref inner,
211218
mutbl: MutImmutable,
212219
},
213-
) = ty.node
214-
{
220+
) = ty.node {
215221
if let TyKind::Path(ref path) = inner.node {
216-
return match_qpath(path, &paths::LINT);
222+
if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) {
223+
return match_def_path(cx.tcx, def_id, &paths::LINT);
224+
}
217225
}
218226
}
219-
false
220-
}
221227

222-
fn is_lint_array_type(ty: &Ty) -> bool {
223-
if let TyKind::Path(ref path) = ty.node {
224-
match_qpath(path, &paths::LINT_ARRAY)
225-
} else {
226-
false
227-
}
228+
false
228229
}
229230

230231
struct LintCollector<'a, 'tcx: 'a> {

clippy_lints/src/utils/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub const ITERATOR: [&str; 4] = ["core", "iter", "iterator", "Iterator"];
5656
pub const LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
5757
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
5858
pub const LINT: [&str; 3] = ["rustc", "lint", "Lint"];
59-
pub const LINT_ARRAY: [&str; 3] = ["rustc", "lint", "LintArray"];
59+
pub const LINT_PASS: [&str; 3] = ["rustc", "lint", "LintPass"];
6060
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
6161
pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"];
6262
pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"];

0 commit comments

Comments
 (0)