Skip to content

Commit bc184e9

Browse files
committed
Merge branch 'master' into rustup
2 parents daa94d2 + b528cc9 commit bc184e9

File tree

133 files changed

+3013
-640
lines changed

Some content is hidden

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

133 files changed

+3013
-640
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,7 @@ Released 2018-09-13
44304430
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
44314431
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
44324432
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
4433+
[`impl_trait_in_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params
44334434
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
44344435
[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
44354436
[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
@@ -4494,6 +4495,7 @@ Released 2018-09-13
44944495
[`let_underscore_future`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_future
44954496
[`let_underscore_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock
44964497
[`let_underscore_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use
4498+
[`let_underscore_untyped`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_untyped
44974499
[`let_unit_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
44984500
[`linkedlist`]: https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist
44994501
[`logic_bug`]: https://rust-lang.github.io/rust-clippy/master/index.html#logic_bug
@@ -4620,6 +4622,7 @@ Released 2018-09-13
46204622
[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect
46214623
[`no_effect_replace`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_replace
46224624
[`no_effect_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
4625+
[`no_mangle_with_rust_abi`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
46234626
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
46244627
[`non_octal_unix_permissions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions
46254628
[`non_send_fields_in_send_ty`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty
@@ -4675,6 +4678,7 @@ Released 2018-09-13
46754678
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
46764679
[`pub_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_use
46774680
[`question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
4681+
[`question_mark_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark_used
46784682
[`range_minus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_minus_one
46794683
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one
46804684
[`range_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_step_by_zero
@@ -4734,6 +4738,7 @@ Released 2018-09-13
47344738
[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq
47354739
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
47364740
[`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee
4741+
[`significant_drop_tightening`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening
47374742
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
47384743
[`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str
47394744
[`single_char_lifetime_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_lifetime_names
@@ -4764,6 +4769,7 @@ Released 2018-09-13
47644769
[`suboptimal_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#suboptimal_flops
47654770
[`suspicious_arithmetic_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
47664771
[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting
4772+
[`suspicious_command_arg_space`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_command_arg_space
47674773
[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting
47684774
[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map
47694775
[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl
@@ -4790,6 +4796,7 @@ Released 2018-09-13
47904796
[`transmute_int_to_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_bool
47914797
[`transmute_int_to_char`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_char
47924798
[`transmute_int_to_float`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_float
4799+
[`transmute_int_to_non_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_non_zero
47934800
[`transmute_null_to_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_null_to_fn
47944801
[`transmute_num_to_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_num_to_bytes
47954802
[`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr

README.md

+28-11
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,35 @@ You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the
1919
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
2020
| `clippy::perf` | code that can be written to run faster | **warn** |
2121
| `clippy::pedantic` | lints which are rather strict or have occasional false positives | allow |
22+
| `clippy::restriction` | lints which prevent the use of language and library features[^restrict] | allow |
2223
| `clippy::nursery` | new lints that are still under development | allow |
2324
| `clippy::cargo` | lints for the cargo manifest | allow |
2425

2526
More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
2627

27-
The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also contains "restriction lints", which are
28-
for things which are usually not considered "bad", but may be useful to turn on in specific cases. These should be used
29-
very selectively, if at all.
28+
The `restriction` category should, *emphatically*, not be enabled as a whole. The contained
29+
lints may lint against perfectly reasonable code, may not have an alternative suggestion,
30+
and may contradict any other lints (including other categories). Lints should be considered
31+
on a case-by-case basis before enabling.
32+
33+
[^restrict]: Some use cases for `restriction` lints include:
34+
- Strict coding styles (e.g. [`clippy::else_if_without_else`]).
35+
- Additional restrictions on CI (e.g. [`clippy::todo`]).
36+
- Preventing panicking in certain functions (e.g. [`clippy::unwrap_used`]).
37+
- Running a lint only on a subset of code (e.g. `#[forbid(clippy::float_arithmetic)]` on a module).
38+
39+
[`clippy::else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
40+
[`clippy::todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
41+
[`clippy::unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
42+
43+
---
3044

3145
Table of contents:
3246

33-
* [Usage instructions](#usage)
34-
* [Configuration](#configuration)
35-
* [Contributing](#contributing)
36-
* [License](#license)
47+
* [Usage instructions](#usage)
48+
* [Configuration](#configuration)
49+
* [Contributing](#contributing)
50+
* [License](#license)
3751

3852
## Usage
3953

@@ -64,6 +78,7 @@ Once you have rustup and the latest stable release (at least Rust 1.29) installe
6478
```terminal
6579
rustup component add clippy
6680
```
81+
6782
If it says that it can't find the `clippy` component, please run `rustup self update`.
6883

6984
#### Step 3: Run Clippy
@@ -143,16 +158,16 @@ line. (You can swap `clippy::all` with the specific lint category you are target
143158

144159
You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
145160

146-
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`).
161+
* the whole set of `Warn` lints using the `clippy` lint group (`#![deny(clippy::all)]`).
147162
Note that `rustc` has additional [lint groups](https://doc.rust-lang.org/rustc/lints/groups.html).
148163

149-
* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
164+
* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
150165
`#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive
151166
lints prone to false positives.
152167

153-
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
168+
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
154169

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

157172
Note: `allow` means to suppress the lint for your code. With `warn` the lint
158173
will only emit a warning, while with `deny` the lint will emit an error, when
@@ -176,12 +191,14 @@ cargo clippy -- -W clippy::lint_name
176191

177192
This also works with lint groups. For example, you
178193
can run Clippy with warnings for all lints enabled:
194+
179195
```terminal
180196
cargo clippy -- -W clippy::pedantic
181197
```
182198

183199
If you care only about a single lint, you can allow all others and then explicitly warn on
184200
the lint(s) you are interested in:
201+
185202
```terminal
186203
cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
187204
```

book/src/development/infrastructure/backport.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ repository. You can do this with:
2828
```bash
2929
# Assuming the current directory corresponds to the Rust repository
3030
$ git checkout beta
31+
# Make sure to change `your-github-name` to your github name in the following command
3132
$ git subtree pull -p src/tools/clippy https://github.com/<your-github-name>/rust-clippy backport
3233
$ ./x.py test src/tools/clippy
3334
```

book/src/development/infrastructure/sync.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ to be run inside the `rust` directory):
7979
`rustup check`.
8080
3. Sync the changes to the rust-copy of Clippy to your Clippy fork:
8181
```bash
82-
# Make sure to change `your-github-name` to your github name in the following command. Also be
83-
# sure to either use a net-new branch, e.g. `sync-from-rust`, or delete the branch beforehand
82+
# Be sure to either use a net-new branch, e.g. `sync-from-rust`, or delete the branch beforehand
8483
# because changes cannot be fast forwarded and you have to run this command again.
8584
git subtree push -P src/tools/clippy clippy-local sync-from-rust
8685
```

book/src/lint_configuration.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Please use that command to update the file and do not edit it by hand.
5353
| [ignore-interior-mutability](#ignore-interior-mutability) | `["bytes::Bytes"]` |
5454
| [allow-mixed-uninlined-format-args](#allow-mixed-uninlined-format-args) | `true` |
5555
| [suppress-restriction-lint-in-const](#suppress-restriction-lint-in-const) | `false` |
56+
| [missing-docs-in-crate-items](#missing-docs-in-crate-items) | `false` |
5657

5758
### arithmetic-side-effects-allowed
5859
Suppress checking of the passed type names in all types of operations.
@@ -471,31 +472,31 @@ The maximum size of a file included via `include_bytes!()` or `include_str!()`,
471472

472473

473474
### allow-expect-in-tests
474-
Whether `expect` should be allowed within `#[cfg(test)]`
475+
Whether `expect` should be allowed in test functions or `#[cfg(test)]`
475476

476477
**Default Value:** `false` (`bool`)
477478

478479
* [expect_used](https://rust-lang.github.io/rust-clippy/master/index.html#expect_used)
479480

480481

481482
### allow-unwrap-in-tests
482-
Whether `unwrap` should be allowed in test cfg
483+
Whether `unwrap` should be allowed in test functions or `#[cfg(test)]`
483484

484485
**Default Value:** `false` (`bool`)
485486

486487
* [unwrap_used](https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used)
487488

488489

489490
### allow-dbg-in-tests
490-
Whether `dbg!` should be allowed in test functions
491+
Whether `dbg!` should be allowed in test functions or `#[cfg(test)]`
491492

492493
**Default Value:** `false` (`bool`)
493494

494495
* [dbg_macro](https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro)
495496

496497

497498
### allow-print-in-tests
498-
Whether print macros (ex. `println!`) should be allowed in test functions
499+
Whether print macros (ex. `println!`) should be allowed in test functions or `#[cfg(test)]`
499500

500501
**Default Value:** `false` (`bool`)
501502

@@ -540,4 +541,13 @@ if no suggestion can be made.
540541
* [indexing_slicing](https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing)
541542

542543

544+
### missing-docs-in-crate-items
545+
Whether to **only** check for missing documentation in items visible within the current
546+
crate. For example, `pub(crate)` items.
547+
548+
**Default Value:** `false` (`bool`)
549+
550+
* [missing_docs_in_private_items](https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items)
551+
552+
543553

clippy_dev/src/new_lint.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::clippy_project_root;
22
use indoc::{formatdoc, writedoc};
3+
use std::fmt;
34
use std::fmt::Write as _;
45
use std::fs::{self, OpenOptions};
56
use std::io::prelude::*;
@@ -256,7 +257,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
256257
)
257258
});
258259

259-
let _ = write!(result, "{}", get_lint_declaration(&name_upper, category));
260+
let _: fmt::Result = write!(result, "{}", get_lint_declaration(&name_upper, category));
260261

261262
result.push_str(&if enable_msrv {
262263
formatdoc!(
@@ -353,7 +354,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
353354
let mut lint_file_contents = String::new();
354355

355356
if enable_msrv {
356-
let _ = writedoc!(
357+
let _: fmt::Result = writedoc!(
357358
lint_file_contents,
358359
r#"
359360
use clippy_utils::msrvs::{{self, Msrv}};
@@ -373,7 +374,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
373374
name_upper = name_upper,
374375
);
375376
} else {
376-
let _ = writedoc!(
377+
let _: fmt::Result = writedoc!(
377378
lint_file_contents,
378379
r#"
379380
use rustc_lint::{{{context_import}, LintContext}};
@@ -521,7 +522,7 @@ fn setup_mod_file(path: &Path, lint: &LintData<'_>) -> io::Result<&'static str>
521522
.chain(std::iter::once(&*lint_name_upper))
522523
.filter(|s| !s.is_empty())
523524
{
524-
let _ = write!(new_arr_content, "\n {ident},");
525+
let _: fmt::Result = write!(new_arr_content, "\n {ident},");
525526
}
526527
new_arr_content.push('\n');
527528

clippy_dev/src/update_lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use itertools::Itertools;
55
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
66
use std::collections::{HashMap, HashSet};
77
use std::ffi::OsStr;
8-
use std::fmt::Write;
8+
use std::fmt::{self, Write};
99
use std::fs::{self, OpenOptions};
1010
use std::io::{self, Read, Seek, SeekFrom, Write as _};
1111
use std::ops::Range;
@@ -691,7 +691,7 @@ fn gen_deprecated(lints: &[DeprecatedLint]) -> String {
691691
let mut output = GENERATED_FILE_COMMENT.to_string();
692692
output.push_str("{\n");
693693
for lint in lints {
694-
let _ = write!(
694+
let _: fmt::Result = write!(
695695
output,
696696
concat!(
697697
" store.register_removed(\n",
@@ -726,7 +726,7 @@ fn gen_declared_lints<'a>(
726726
if !is_public {
727727
output.push_str(" #[cfg(feature = \"internal\")]\n");
728728
}
729-
let _ = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
729+
let _: fmt::Result = writeln!(output, " crate::{module_name}::{lint_name}_INFO,");
730730
}
731731
output.push_str("];\n");
732732

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ quine-mc_cluskey = "0.2"
1919
regex-syntax = "0.6"
2020
serde = { version = "1.0", features = ["derive"] }
2121
serde_json = { version = "1.0", optional = true }
22-
tempfile = { version = "3.2", optional = true }
22+
tempfile = { version = "3.3.0", optional = true }
2323
toml = "0.5"
2424
unicode-normalization = "0.1"
2525
unicode-script = { version = "0.5", default-features = false }

clippy_lints/src/blocks_in_if_conditions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
8585
);
8686
}
8787
} else {
88-
let span =
89-
block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
88+
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
9089
if span.from_expansion() || expr.span.from_expansion() {
9190
return;
9291
}

clippy_lints/src/box_default.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
117117
) => {
118118
if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id) &&
119119
let Some(sig) = expr_sig(cx, path) &&
120-
let Some(input) = sig.input(index)
120+
let Some(input) = sig.input(index) &&
121+
!cx.typeck_results().expr_ty_adjusted(expr).boxed_ty().is_trait()
121122
{
122123
input.no_bound_vars().is_some()
123124
} else {

clippy_lints/src/casts/cast_possible_truncation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(super) fn check(
168168
let suggestion = format!("{cast_to_snip}::try_from({name_of_cast_from})");
169169

170170
span_lint_and_then(cx, CAST_POSSIBLE_TRUNCATION, expr.span, &msg, |diag| {
171-
diag.help("if this is intentional allow the lint with `#[allow(clippy::cast_precision_loss)]` ...");
171+
diag.help("if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...");
172172
diag.span_suggestion_with_style(
173173
expr.span,
174174
"... or use `try_from` and handle the error accordingly",

0 commit comments

Comments
 (0)