Skip to content

Commit 859b59e

Browse files
committed
submodules: update clippy from 1ff81c1 to 70b93aa
Changes: ```` remove redundant import rustup rust-lang/rust#68404 rustup rust-lang/rust#69644 rustup rust-lang/rust#70344 Move verbose_file_reads to restriction move redundant_pub_crate to nursery readme: explain how to run only a single lint on a codebase Remove dependency on `matches` crate Move useless_transmute to nursery nursery group -> style Update for PR feedback Auto merge of rust-lang#5314 - ehuss:remove-git2, r=flip1995 Lint for `pub(crate)` items that are not crate visible due to the visibility of the module that contains them ```` Fixes #70456
1 parent a3c73a9 commit 859b59e

40 files changed

+513
-99
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,7 @@ Released 2018-09-13
14391439
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
14401440
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
14411441
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
1442+
[`redundant_pub_crate`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
14421443
[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes
14431444
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
14441445
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
[There are 361 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are 362 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

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

@@ -90,6 +90,14 @@ Note that this is still experimental and only supported on the nightly channel:
9090
cargo fix -Z unstable-options --clippy
9191
```
9292

93+
#### Running only a single lint
94+
95+
If you care only about the warnings of a single lint and want to ignore everything else, you
96+
can first deny all the clippy lints and then explicitly enable the lint(s) you care about:
97+
````
98+
cargo clippy -- -Aclippy::all -Wclippy::useless_format
99+
````
100+
93101
### Running Clippy from the command line without installing it
94102

95103
To have cargo compile your crate with Clippy without Clippy installation

clippy_lints/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ cargo_metadata = "0.9.0"
2121
if_chain = "1.0.0"
2222
itertools = "0.9"
2323
lazy_static = "1.0.2"
24-
matches = "0.1.7"
2524
pulldown-cmark = { version = "0.7", default-features = false }
2625
quine-mc_cluskey = "0.2.2"
2726
regex-syntax = "0.6"

clippy_lints/src/block_in_if_condition.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::utils::{differing_macro_contexts, higher, snippet_block_with_applicability, span_lint, span_lint_and_sugg};
2-
use matches::matches;
32
use rustc::hir::map::Map;
43
use rustc::lint::in_external_macro;
54
use rustc_errors::Applicability;

clippy_lints/src/derive.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ fn check_hash_peq<'a, 'tcx>(
9494
if_chain! {
9595
if match_path(&trait_ref.path, &paths::HASH);
9696
if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait();
97-
if !&trait_ref.trait_def_id().is_local();
97+
if let Some(def_id) = &trait_ref.trait_def_id();
98+
if !def_id.is_local();
9899
then {
99100
// Look for the PartialEq implementations for `ty`
100101
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {

clippy_lints/src/eta_reduction.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use if_chain::if_chain;
2-
use matches::matches;
32
use rustc::lint::in_external_macro;
43
use rustc::ty::{self, Ty};
54
use rustc_errors::Applicability;

clippy_lints/src/if_let_some_result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::{match_type, method_chain_args, paths, snippet_with_applicability, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
4-
use rustc_hir::{print, Expr, ExprKind, MatchSource, PatKind, QPath};
4+
use rustc_hir::{Expr, ExprKind, MatchSource, PatKind, QPath};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77

@@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet {
4646
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation
4747
if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
4848
let is_result_type = match_type(cx, cx.tables.expr_ty(&result_types[0]), &paths::RESULT);
49-
if print::to_string(print::NO_ANN, |s| s.print_path(x, false)) == "Some" && is_result_type;
49+
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some" && is_result_type;
5050

5151
then {
5252
let mut applicability = Applicability::MachineApplicable;

clippy_lints/src/items_after_statements.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! lint when items are used after statements
22
33
use crate::utils::span_lint;
4-
use matches::matches;
54
use rustc_ast::ast::{Block, ItemKind, StmtKind};
65
use rustc_lint::{EarlyContext, EarlyLintPass};
76
use rustc_session::{declare_lint_pass, declare_tool_lint};

clippy_lints/src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern crate rustc_errors;
3434
#[allow(unused_extern_crates)]
3535
extern crate rustc_hir;
3636
#[allow(unused_extern_crates)]
37+
extern crate rustc_hir_pretty;
38+
#[allow(unused_extern_crates)]
3739
extern crate rustc_index;
3840
#[allow(unused_extern_crates)]
3941
extern crate rustc_infer;
@@ -285,6 +287,7 @@ pub mod ranges;
285287
pub mod redundant_clone;
286288
pub mod redundant_field_names;
287289
pub mod redundant_pattern_matching;
290+
pub mod redundant_pub_crate;
288291
pub mod redundant_static_lifetimes;
289292
pub mod reference;
290293
pub mod regex;
@@ -323,7 +326,7 @@ pub mod zero_div_zero;
323326
pub use crate::utils::conf::Conf;
324327

325328
mod reexport {
326-
crate use rustc_ast::ast::Name;
329+
pub use rustc_ast::ast::Name;
327330
}
328331

329332
/// Register all pre expansion lints
@@ -745,6 +748,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
745748
&redundant_clone::REDUNDANT_CLONE,
746749
&redundant_field_names::REDUNDANT_FIELD_NAMES,
747750
&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING,
751+
&redundant_pub_crate::REDUNDANT_PUB_CRATE,
748752
&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES,
749753
&reference::DEREF_ADDROF,
750754
&reference::REF_IN_DEREF,
@@ -1021,6 +1025,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10211025
store.register_late_pass(|| box wildcard_imports::WildcardImports);
10221026
store.register_early_pass(|| box macro_use::MacroUseImports);
10231027
store.register_late_pass(|| box verbose_file_reads::VerboseFileReads);
1028+
store.register_late_pass(|| box redundant_pub_crate::RedundantPubCrate::default());
10241029

10251030
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
10261031
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
@@ -1059,6 +1064,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10591064
LintId::of(&shadow::SHADOW_REUSE),
10601065
LintId::of(&shadow::SHADOW_SAME),
10611066
LintId::of(&strings::STRING_ADD),
1067+
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
10621068
LintId::of(&write::PRINT_STDOUT),
10631069
LintId::of(&write::USE_DEBUG),
10641070
]);
@@ -1351,7 +1357,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13511357
LintId::of(&transmute::TRANSMUTE_PTR_TO_PTR),
13521358
LintId::of(&transmute::TRANSMUTE_PTR_TO_REF),
13531359
LintId::of(&transmute::UNSOUND_COLLECTION_TRANSMUTE),
1354-
LintId::of(&transmute::USELESS_TRANSMUTE),
13551360
LintId::of(&transmute::WRONG_TRANSMUTE),
13561361
LintId::of(&transmuting_null::TRANSMUTING_NULL),
13571362
LintId::of(&trivially_copy_pass_by_ref::TRIVIALLY_COPY_PASS_BY_REF),
@@ -1378,7 +1383,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13781383
LintId::of(&unwrap::PANICKING_UNWRAP),
13791384
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
13801385
LintId::of(&vec::USELESS_VEC),
1381-
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
13821386
LintId::of(&write::PRINTLN_EMPTY_STRING),
13831387
LintId::of(&write::PRINT_LITERAL),
13841388
LintId::of(&write::PRINT_WITH_NEWLINE),
@@ -1553,7 +1557,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15531557
LintId::of(&transmute::TRANSMUTE_INT_TO_FLOAT),
15541558
LintId::of(&transmute::TRANSMUTE_PTR_TO_PTR),
15551559
LintId::of(&transmute::TRANSMUTE_PTR_TO_REF),
1556-
LintId::of(&transmute::USELESS_TRANSMUTE),
15571560
LintId::of(&types::BORROWED_BOX),
15581561
LintId::of(&types::CHAR_LIT_AS_U8),
15591562
LintId::of(&types::OPTION_OPTION),
@@ -1562,7 +1565,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15621565
LintId::of(&types::UNNECESSARY_CAST),
15631566
LintId::of(&types::VEC_BOX),
15641567
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
1565-
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
15661568
LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO),
15671569
]);
15681570

@@ -1670,6 +1672,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16701672
LintId::of(&mutex_atomic::MUTEX_INTEGER),
16711673
LintId::of(&needless_borrow::NEEDLESS_BORROW),
16721674
LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),
1675+
LintId::of(&redundant_pub_crate::REDUNDANT_PUB_CRATE),
1676+
LintId::of(&transmute::USELESS_TRANSMUTE),
16731677
LintId::of(&use_self::USE_SELF),
16741678
]);
16751679
}

clippy_lints/src/lifetimes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use matches::matches;
21
use rustc::hir::map::Map;
32
use rustc::lint::in_external_macro;
43
use rustc_data_structures::fx::{FxHashMap, FxHashSet};

clippy_lints/src/loops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
720720
ExprKind::Struct(_, _, None)
721721
| ExprKind::Yield(_, _)
722722
| ExprKind::Closure(_, _, _, _, _)
723-
| ExprKind::InlineAsm(_)
723+
| ExprKind::LlvmInlineAsm(_)
724724
| ExprKind::Path(_)
725725
| ExprKind::Lit(_)
726726
| ExprKind::Err => NeverLoopResult::Otherwise,

clippy_lints/src/matches.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use rustc_ast::ast::LitKind;
1515
use rustc_errors::Applicability;
1616
use rustc_hir::def::CtorKind;
1717
use rustc_hir::{
18-
print, Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Local, MatchSource, Mutability, Node, Pat,
19-
PatKind, QPath, RangeEnd,
18+
Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Local, MatchSource, Mutability, Node, Pat, PatKind,
19+
QPath, RangeEnd,
2020
};
2121
use rustc_lint::{LateContext, LateLintPass, LintContext};
2222
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -536,10 +536,12 @@ fn check_single_match_opt_like(
536536
if !inner.iter().all(is_wild) {
537537
return;
538538
}
539-
print::to_string(print::NO_ANN, |s| s.print_qpath(path, false))
539+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false))
540540
},
541541
PatKind::Binding(BindingAnnotation::Unannotated, .., ident, None) => ident.to_string(),
542-
PatKind::Path(ref path) => print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
542+
PatKind::Path(ref path) => {
543+
rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false))
544+
},
543545
_ => return,
544546
};
545547

@@ -638,7 +640,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>])
638640
if match_type(cx, ex_ty, &paths::RESULT) {
639641
for arm in arms {
640642
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
641-
let path_str = print::to_string(print::NO_ANN, |s| s.print_qpath(path, false));
643+
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));
642644
if path_str == "Err" {
643645
let mut matching_wild = inner.iter().any(is_wild);
644646
let mut ident_bind_name = String::from("_");

clippy_lints/src/methods/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::fmt;
88
use std::iter;
99

1010
use if_chain::if_chain;
11-
use matches::matches;
1211
use rustc::hir::map::Map;
1312
use rustc::lint::in_external_macro;
1413
use rustc::ty::{self, Predicate, Ty};

clippy_lints/src/misc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use if_chain::if_chain;
2-
use matches::matches;
32
use rustc::ty;
43
use rustc_ast::ast::LitKind;
54
use rustc_errors::Applicability;

clippy_lints/src/missing_const_for_fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::Span;
1010
use rustc_typeck::hir_ty_to_ty;
11-
use std::matches;
1211

1312
declare_clippy_lint! {
1413
/// **What it does:**

clippy_lints/src/mut_reference.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint;
22
use rustc::ty::subst::Subst;
33
use rustc::ty::{self, Ty};
4-
use rustc_hir::{print, BorrowKind, Expr, ExprKind, Mutability};
4+
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77

@@ -34,7 +34,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
3434
cx,
3535
arguments,
3636
cx.tables.expr_ty(fn_expr),
37-
&print::to_string(print::NO_ANN, |s| s.print_qpath(path, false)),
37+
&rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)),
3838
);
3939
}
4040
},

clippy_lints/src/mutable_debug_assertion.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::utils::{is_direct_expn_of, span_lint};
22
use if_chain::if_chain;
3-
use matches::matches;
43
use rustc::hir::map::Map;
54
use rustc::ty;
65
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};

clippy_lints/src/needless_pass_by_value.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::utils::{
44
snippet, snippet_opt, span_lint_and_then,
55
};
66
use if_chain::if_chain;
7-
use matches::matches;
87
use rustc::ty::{self, TypeFoldable};
98
use rustc_ast::ast::Attribute;
109
use rustc_data_structures::fx::{FxHashMap, FxHashSet};

clippy_lints/src/redundant_clone.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::utils::{
33
span_lint_hir_and_then, walk_ptrs_ty_depth,
44
};
55
use if_chain::if_chain;
6-
use matches::matches;
76
use rustc::mir::{
87
self, traversal,
98
visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor as _},
@@ -15,8 +14,8 @@ use rustc_hir::intravisit::FnKind;
1514
use rustc_hir::{def_id, Body, FnDecl, HirId};
1615
use rustc_index::bit_set::{BitSet, HybridBitSet};
1716
use rustc_lint::{LateContext, LateLintPass};
18-
use rustc_mir::dataflow::generic::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor};
1917
use rustc_mir::dataflow::BottomValue;
18+
use rustc_mir::dataflow::{Analysis, AnalysisDomain, GenKill, GenKillAnalysis, ResultsCursor};
2019
use rustc_session::{declare_lint_pass, declare_tool_lint};
2120
use rustc_span::source_map::{BytePos, Span};
2221
use std::convert::TryFrom;
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use crate::utils::span_lint_and_then;
2+
use rustc_errors::Applicability;
3+
use rustc_hir::{Item, ItemKind, VisibilityKind};
4+
use rustc_lint::{LateContext, LateLintPass};
5+
use rustc_session::{declare_tool_lint, impl_lint_pass};
6+
7+
declare_clippy_lint! {
8+
/// **What it does:** Checks for items declared `pub(crate)` that are not crate visible because they
9+
/// are inside a private module.
10+
///
11+
/// **Why is this bad?** Writing `pub(crate)` is misleading when it's redundant due to the parent
12+
/// module's visibility.
13+
///
14+
/// **Known problems:** None.
15+
///
16+
/// **Example:**
17+
///
18+
/// ```rust
19+
/// mod internal {
20+
/// pub(crate) fn internal_fn() { }
21+
/// }
22+
/// ```
23+
/// This function is not visible outside the module and it can be declared with `pub` or
24+
/// private visibility
25+
/// ```rust
26+
/// mod internal {
27+
/// pub fn internal_fn() { }
28+
/// }
29+
/// ```
30+
pub REDUNDANT_PUB_CRATE,
31+
nursery,
32+
"Using `pub(crate)` visibility on items that are not crate visible due to the visibility of the module that contains them."
33+
}
34+
35+
#[derive(Default)]
36+
pub struct RedundantPubCrate {
37+
is_exported: Vec<bool>,
38+
}
39+
40+
impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
41+
42+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPubCrate {
43+
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) {
44+
if let VisibilityKind::Crate { .. } = item.vis.node {
45+
if !cx.access_levels.is_exported(item.hir_id) {
46+
if let Some(false) = self.is_exported.last() {
47+
let span = item.span.with_hi(item.ident.span.hi());
48+
span_lint_and_then(
49+
cx,
50+
REDUNDANT_PUB_CRATE,
51+
span,
52+
&format!("pub(crate) {} inside private module", item.kind.descr()),
53+
|db| {
54+
db.span_suggestion(
55+
item.vis.span,
56+
"consider using",
57+
"pub".to_string(),
58+
Applicability::MachineApplicable,
59+
);
60+
},
61+
)
62+
}
63+
}
64+
}
65+
66+
if let ItemKind::Mod { .. } = item.kind {
67+
self.is_exported.push(cx.access_levels.is_exported(item.hir_id));
68+
}
69+
}
70+
71+
fn check_item_post(&mut self, _cx: &LateContext<'a, 'tcx>, item: &'tcx Item<'tcx>) {
72+
if let ItemKind::Mod { .. } = item.kind {
73+
self.is_exported.pop().expect("unbalanced check_item/check_item_post");
74+
}
75+
}
76+
}

clippy_lints/src/swap.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::utils::{
44
span_lint_and_then, walk_ptrs_ty, SpanlessEq,
55
};
66
use if_chain::if_chain;
7-
use matches::matches;
87
use rustc::ty;
98
use rustc_errors::Applicability;
109
use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, StmtKind};

0 commit comments

Comments
 (0)