Skip to content

Commit b7fc905

Browse files
committed
submodules: update clippy from 329923e to 8485d40
Changes: ```` Rustup to rust-lang/rust#69674 Use visit_place Check for mutation Only fires on temporaries Extend `redundant_clone` to the case that cloned value is not consumed add CR feedback Improve documentation Use `edition:2018` flag more widely Update tests/ui/needless_doc_main.rs Move links to the end of each chapter on adding_lints Move links to the end of each chapter on CONTRIBUTING Clean-up adding_lints.md Clean-up CONTRIBUTING.md needless_doc_main: only check rust code Use `node_type_opt` over `node_type` Fix doc Fix ICE with trivial_bounds feature clippy_lints: readme: don't mention crates.io since it is no longer used to publish clippy. update rust-lang.github.io to rustc-dev-guide.rust-lang.org Improve placeholder in map_unit_fn Fix match single binding when in a let stmt Improve error messages for {option,result}_map_unit_fn Mention the setup instructions in CONTRIBUTING redundant_pattern: take binding (ref, ref mut) into account in suggestion. check_pat: delay creation of the "normal" vec until we reach the branch where is is actually needed deps: bump itertools 0.8 -> 0.9 add lint on File::read_to_string and File::read_to_end transition rustc-guide to rustc-dev-guide Rename macro_use_import -> macro_use_imports warn on macro_use attr Fix deploy script for tag deploys ```` Fixes #69957
1 parent 302d2e5 commit b7fc905

Some content is hidden

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

62 files changed

+928
-346
lines changed

.github/deploy.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ if git diff --exit-code --quiet; then
3333
exit 0
3434
fi
3535

36-
git add .
37-
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
36+
if [[ -n $TAG_NAME ]]; then
37+
# Add the new dir
38+
git add $TAG_NAME
39+
# Update the symlink
40+
git add stable
41+
# Update versions file
42+
git add versions.json
43+
git commit -m "Add documentation for ${TAG_NAME} release: ${SHA}"
44+
else
45+
git add .
46+
git commit -m "Automatic deploy to GitHub Pages: ${SHA}"
47+
fi
3848

3949
git push "$SSH_REPO" "$TARGET_BRANCH"

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ Released 2018-09-13
12091209
[`linkedlist`]: https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist
12101210
[`logic_bug`]: https://rust-lang.github.io/rust-clippy/master/index.html#logic_bug
12111211
[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal
1212+
[`macro_use_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_use_imports
12121213
[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion
12131214
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
12141215
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
@@ -1416,6 +1417,7 @@ Released 2018-09-13
14161417
[`useless_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
14171418
[`vec_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
14181419
[`verbose_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask
1420+
[`verbose_file_reads`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_file_reads
14191421
[`while_immutable_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_immutable_condition
14201422
[`while_let_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_loop
14211423
[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator

CONTRIBUTING.md

+80-79
Large diffs are not rendered by default.

README.md

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

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ edition = "2018"
1919
[dependencies]
2020
cargo_metadata = "0.9.0"
2121
if_chain = "1.0.0"
22-
itertools = "0.8"
22+
itertools = "0.9"
2323
lazy_static = "1.0.2"
2424
matches = "0.1.7"
2525
pulldown-cmark = { version = "0.7", default-features = false }

clippy_lints/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
This crate contains Clippy lints. For the main crate, check
2-
[*crates.io*](https://crates.io/crates/clippy) or
3-
[GitHub](https://github.com/rust-lang/rust-clippy).
1+
This crate contains Clippy lints. For the main crate, check [GitHub](https://github.com/rust-lang/rust-clippy).

clippy_lints/src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ fn is_relevant_impl(cx: &LateContext<'_, '_>, item: &ImplItem<'_>) -> bool {
379379

380380
fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool {
381381
match item.kind {
382-
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
383-
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
382+
TraitItemKind::Fn(_, TraitMethod::Required(_)) => true,
383+
TraitItemKind::Fn(_, TraitMethod::Provided(eid)) => {
384384
is_relevant_expr(cx, cx.tcx.body_tables(eid), &cx.tcx.hir().body(eid).value)
385385
},
386386
_ => false,

clippy_lints/src/doc.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
179179

180180
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) {
181181
let headers = check_attrs(cx, &self.valid_idents, &item.attrs);
182-
if let hir::TraitItemKind::Method(ref sig, ..) = item.kind {
182+
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
183183
if !in_external_macro(cx.tcx.sess, item.span) {
184184
lint_for_missing_headers(cx, item.hir_id, item.span, sig, headers, None);
185185
}
@@ -367,13 +367,16 @@ fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet<String>, a
367367
check_doc(cx, valid_idents, events, &spans)
368368
}
369369

370+
const RUST_CODE: &[&str] = &["rust", "no_run", "should_panic", "compile_fail", "edition2018"];
371+
370372
fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize>)>>(
371373
cx: &LateContext<'_, '_>,
372374
valid_idents: &FxHashSet<String>,
373375
events: Events,
374376
spans: &[(usize, Span)],
375377
) -> DocHeaders {
376378
// true if a safety header was found
379+
use pulldown_cmark::CodeBlockKind;
377380
use pulldown_cmark::Event::{
378381
Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text,
379382
};
@@ -386,11 +389,20 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
386389
let mut in_code = false;
387390
let mut in_link = None;
388391
let mut in_heading = false;
389-
392+
let mut is_rust = false;
390393
for (event, range) in events {
391394
match event {
392-
Start(CodeBlock(_)) => in_code = true,
393-
End(CodeBlock(_)) => in_code = false,
395+
Start(CodeBlock(ref kind)) => {
396+
in_code = true;
397+
if let CodeBlockKind::Fenced(lang) = kind {
398+
is_rust =
399+
lang.is_empty() || !lang.contains("ignore") && lang.split(',').any(|i| RUST_CODE.contains(&i));
400+
}
401+
},
402+
End(CodeBlock(_)) => {
403+
in_code = false;
404+
is_rust = false;
405+
},
394406
Start(Link(_, url, _)) => in_link = Some(url),
395407
End(Link(..)) => in_link = None,
396408
Start(Heading(_)) => in_heading = true,
@@ -413,7 +425,9 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
413425
};
414426
let (begin, span) = spans[index];
415427
if in_code {
416-
check_code(cx, &text, span);
428+
if is_rust {
429+
check_code(cx, &text, span);
430+
}
417431
} else {
418432
// Adjust for the beginning of the current `Event`
419433
let span = span.with_lo(span.lo() + BytePos::from_usize(range.start - begin));

clippy_lints/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
273273
}
274274

275275
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem<'_>) {
276-
if let hir::TraitItemKind::Method(ref sig, ref eid) = item.kind {
276+
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
277277
// don't lint extern functions decls, it's not their fault
278278
if sig.header.abi == Abi::Rust {
279279
self.check_arg_number(cx, &sig.decl, item.span.with_hi(sig.decl.output.span().hi()));

clippy_lints/src/implicit_return.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
match_def_path,
2+
fn_has_unsatisfiable_preds, match_def_path,
33
paths::{BEGIN_PANIC, BEGIN_PANIC_FMT},
44
snippet_opt, span_lint_and_then,
55
};
@@ -133,6 +133,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitReturn {
133133
_: HirId,
134134
) {
135135
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
136+
137+
// Building MIR for `fn`s with unsatisfiable preds results in ICE.
138+
if fn_has_unsatisfiable_preds(cx, def_id) {
139+
return;
140+
}
141+
136142
let mir = cx.tcx.optimized_mir(def_id);
137143

138144
// checking return type through MIR, HIR is not able to determine inferred closure return types

clippy_lints/src/inline_fn_without_body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
3232

3333
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody {
3434
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) {
35-
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.kind {
35+
if let TraitItemKind::Fn(_, TraitMethod::Required(_)) = item.kind {
3636
check_attrs(cx, item.ident.name, &item.attrs);
3737
}
3838
}

clippy_lints/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub mod let_underscore;
234234
pub mod lifetimes;
235235
pub mod literal_representation;
236236
pub mod loops;
237+
pub mod macro_use;
237238
pub mod main_recursion;
238239
pub mod map_clone;
239240
pub mod map_unit_fn;
@@ -309,6 +310,7 @@ pub mod unused_self;
309310
pub mod unwrap;
310311
pub mod use_self;
311312
pub mod vec;
313+
pub mod verbose_file_reads;
312314
pub mod wildcard_dependencies;
313315
pub mod wildcard_imports;
314316
pub mod write;
@@ -599,6 +601,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
599601
&loops::WHILE_IMMUTABLE_CONDITION,
600602
&loops::WHILE_LET_LOOP,
601603
&loops::WHILE_LET_ON_ITERATOR,
604+
&macro_use::MACRO_USE_IMPORTS,
602605
&main_recursion::MAIN_RECURSION,
603606
&map_clone::MAP_CLONE,
604607
&map_unit_fn::OPTION_MAP_UNIT_FN,
@@ -813,6 +816,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
813816
&unwrap::UNNECESSARY_UNWRAP,
814817
&use_self::USE_SELF,
815818
&vec::USELESS_VEC,
819+
&verbose_file_reads::VERBOSE_FILE_READS,
816820
&wildcard_dependencies::WILDCARD_DEPENDENCIES,
817821
&wildcard_imports::ENUM_GLOB_USE,
818822
&wildcard_imports::WILDCARD_IMPORTS,
@@ -1012,6 +1016,8 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10121016
store.register_early_pass(move || box excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools));
10131017
store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap);
10141018
store.register_late_pass(|| box wildcard_imports::WildcardImports);
1019+
store.register_early_pass(|| box macro_use::MacroUseImports);
1020+
store.register_late_pass(|| box verbose_file_reads::VerboseFileReads);
10151021

10161022
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
10171023
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
@@ -1079,6 +1085,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10791085
LintId::of(&literal_representation::LARGE_DIGIT_GROUPS),
10801086
LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP),
10811087
LintId::of(&loops::EXPLICIT_ITER_LOOP),
1088+
LintId::of(&macro_use::MACRO_USE_IMPORTS),
10821089
LintId::of(&matches::SINGLE_MATCH_ELSE),
10831090
LintId::of(&methods::FILTER_MAP),
10841091
LintId::of(&methods::FILTER_MAP_NEXT),
@@ -1368,6 +1375,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
13681375
LintId::of(&unwrap::PANICKING_UNWRAP),
13691376
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
13701377
LintId::of(&vec::USELESS_VEC),
1378+
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
13711379
LintId::of(&write::PRINTLN_EMPTY_STRING),
13721380
LintId::of(&write::PRINT_LITERAL),
13731381
LintId::of(&write::PRINT_WITH_NEWLINE),
@@ -1551,6 +1559,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15511559
LintId::of(&types::UNNECESSARY_CAST),
15521560
LintId::of(&types::VEC_BOX),
15531561
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
1562+
LintId::of(&verbose_file_reads::VERBOSE_FILE_READS),
15541563
LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO),
15551564
]);
15561565

clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Lifetimes {
100100
}
101101

102102
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) {
103-
if let TraitItemKind::Method(ref sig, ref body) = item.kind {
103+
if let TraitItemKind::Fn(ref sig, ref body) = item.kind {
104104
let body = match *body {
105105
TraitMethod::Required(_) => None,
106106
TraitMethod::Provided(id) => Some(id),

clippy_lints/src/macro_use.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use crate::utils::{snippet, span_lint_and_sugg};
2+
use if_chain::if_chain;
3+
use rustc_ast::ast;
4+
use rustc_errors::Applicability;
5+
use rustc_lint::{EarlyContext, EarlyLintPass};
6+
use rustc_session::{declare_lint_pass, declare_tool_lint};
7+
use rustc_span::edition::Edition;
8+
9+
declare_clippy_lint! {
10+
/// **What it does:** Checks for `#[macro_use] use...`.
11+
///
12+
/// **Why is this bad?** Since the Rust 2018 edition you can import
13+
/// macro's directly, this is considered idiomatic.
14+
///
15+
/// **Known problems:** This lint does not generate an auto-applicable suggestion.
16+
///
17+
/// **Example:**
18+
/// ```rust
19+
/// #[macro_use]
20+
/// use lazy_static;
21+
/// ```
22+
pub MACRO_USE_IMPORTS,
23+
pedantic,
24+
"#[macro_use] is no longer needed"
25+
}
26+
27+
declare_lint_pass!(MacroUseImports => [MACRO_USE_IMPORTS]);
28+
29+
impl EarlyLintPass for MacroUseImports {
30+
fn check_item(&mut self, ecx: &EarlyContext<'_>, item: &ast::Item) {
31+
if_chain! {
32+
if ecx.sess.opts.edition == Edition::Edition2018;
33+
if let ast::ItemKind::Use(use_tree) = &item.kind;
34+
if let Some(mac_attr) = item
35+
.attrs
36+
.iter()
37+
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
38+
then {
39+
let msg = "`macro_use` attributes are no longer needed in the Rust 2018 edition";
40+
let help = format!("use {}::<macro name>", snippet(ecx, use_tree.span, "_"));
41+
span_lint_and_sugg(
42+
ecx,
43+
MACRO_USE_IMPORTS,
44+
mac_attr.span,
45+
msg,
46+
"remove the attribute and import the macro directly, try",
47+
help,
48+
Applicability::HasPlaceholders,
49+
);
50+
}
51+
}
52+
}
53+
}

clippy_lints/src/map_unit_fn.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,19 @@ fn unit_closure<'a, 'tcx>(
186186
/// `x.field` => `x_field`
187187
/// `y` => `_y`
188188
///
189-
/// Anything else will return `_`.
189+
/// Anything else will return `a`.
190190
fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr<'_>) -> String {
191191
match &var_arg.kind {
192192
hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"),
193193
hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")),
194-
_ => "_".to_string(),
194+
_ => "a".to_string(),
195195
}
196196
}
197197

198198
#[must_use]
199199
fn suggestion_msg(function_type: &str, map_type: &str) -> String {
200200
format!(
201-
"called `map(f)` on an `{0}` value where `f` is a unit {1}",
201+
"called `map(f)` on an `{0}` value where `f` is a {1} that returns the unit type",
202202
map_type, function_type
203203
)
204204
}

0 commit comments

Comments
 (0)