Skip to content

Commit 999ab66

Browse files
authored
Merge branch 'master' into return-and-then
2 parents de1c90f + e02c885 commit 999ab66

File tree

229 files changed

+3449
-1140
lines changed

Some content is hidden

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

229 files changed

+3449
-1140
lines changed

.github/driver.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ unset CARGO_MANIFEST_DIR
4747

4848
# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
4949
# FIXME: How to match the clippy invocation in compile-test.rs?
50-
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1
51-
sed -e "/= help: for/d" double_neg.stderr > normalized.stderr
52-
diff -u normalized.stderr tests/ui/double_neg.stderr
50+
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/string_to_string.rs 2>string_to_string.stderr && exit 1
51+
sed -e "/= help: for/d" string_to_string.stderr > normalized.stderr
52+
diff -u normalized.stderr tests/ui/string_to_string.stderr
5353

5454
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
5555
SYSROOT=$(rustc --print sysroot)

.github/workflows/clippy_changelog.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ jobs:
2626
run: |
2727
body=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/rust-lang/rust-clippy/pulls/$PR_NUMBER" | \
2828
python -c "import sys, json; print(json.load(sys.stdin)['body'])")
29-
output=$(grep "^changelog:\s*\S" <<< "$body" | sed "s/changelog:\s*//g") || {
30-
echo "ERROR: pull request message must contain 'changelog: ...'. Please add it."
29+
output=$(awk '/^changelog:\s*\S/ && !/changelog: \[.*\]: your change/' <<< "$body" | sed "s/changelog:\s*//g")
30+
if [ -z "$output" ]; then
31+
echo "ERROR: pull request message must contain 'changelog: ...' with your changelog. Please add it."
3132
exit 1
32-
}
33-
echo "changelog: $output"
33+
else
34+
echo "changelog: $output"
35+
fi
3436
env:
3537
PYTHONIOENCODING: 'utf-8'
3638
PR_NUMBER: '${{ github.event.number }}'

.github/workflows/lintcheck.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Lintcheck
22

3-
on: pull_request
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- 'book/**'
7+
- 'util/**'
8+
- 'tests/**'
9+
- '*.md'
410

511
env:
612
RUST_BACKTRACE: 1

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5533,6 +5533,7 @@ Released 2018-09-13
55335533
[`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
55345534
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
55355535
[`doc_nested_refdefs`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_nested_refdefs
5536+
[`doc_overindented_list_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items
55365537
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
55375538
[`double_ended_iterator_last`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_ended_iterator_last
55385539
[`double_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use
@@ -5906,6 +5907,7 @@ Released 2018-09-13
59065907
[`non_minimal_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg
59075908
[`non_octal_unix_permissions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions
59085909
[`non_send_fields_in_send_ty`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty
5910+
[`non_std_lazy_statics`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_std_lazy_statics
59095911
[`non_zero_suggestions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_zero_suggestions
59105912
[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
59115913
[`nonsensical_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options
@@ -6066,6 +6068,7 @@ Released 2018-09-13
60666068
[`size_of_in_element_count`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_in_element_count
60676069
[`size_of_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#size_of_ref
60686070
[`skip_while_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#skip_while_next
6071+
[`sliced_string_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#sliced_string_as_bytes
60696072
[`slow_vector_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#slow_vector_initialization
60706073
[`stable_sort_primitive`]: https://rust-lang.github.io/rust-clippy/master/index.html#stable_sort_primitive
60716074
[`std_instead_of_alloc`]: https://rust-lang.github.io/rust-clippy/master/index.html#std_instead_of_alloc

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ line. (You can swap `clippy::all` with the specific lint category you are target
159159
You can add options to your code to `allow`/`warn`/`deny` Clippy lints:
160160

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

164164
* all lints using both the `clippy` and `clippy::pedantic` lint groups (`#![deny(clippy::all)]`,
165-
`#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive
166-
lints prone to false positives.
165+
`#![deny(clippy::pedantic)]`). Note that `clippy::pedantic` contains some very aggressive
166+
lints prone to false positives.
167167

168168
* only some lints (`#![deny(clippy::single_match, clippy::box_vec)]`, etc.)
169169

book/src/lint_configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
750750
* [`manual_pattern_char_comparison`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison)
751751
* [`manual_range_contains`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains)
752752
* [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid)
753+
* [`manual_repeat_n`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_repeat_n)
753754
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
754755
* [`manual_split_once`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once)
755756
* [`manual_str_repeat`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat)
@@ -762,11 +763,13 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
762763
* [`mem_replace_with_default`](https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default)
763764
* [`missing_const_for_fn`](https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn)
764765
* [`needless_borrow`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow)
766+
* [`non_std_lazy_statics`](https://rust-lang.github.io/rust-clippy/master/index.html#non_std_lazy_statics)
765767
* [`option_as_ref_deref`](https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref)
766768
* [`option_map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or)
767769
* [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr)
768770
* [`redundant_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names)
769771
* [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes)
772+
* [`same_item_push`](https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push)
770773
* [`seek_from_current`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_from_current)
771774
* [`seek_rewind`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_rewind)
772775
* [`transmute_ptr_to_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref)

book/src/usage.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can configure lint levels on the command line by adding
3333
`-A/W/D clippy::lint_name` like this:
3434

3535
```bash
36-
cargo clippy -- -Aclippy::style -Wclippy::double_neg -Dclippy::perf
36+
cargo clippy -- -Aclippy::style -Wclippy::box_default -Dclippy::perf
3737
```
3838

3939
For [CI] all warnings can be elevated to errors which will in turn fail
@@ -101,11 +101,10 @@ You can configure lint levels in source code the same way you can configure
101101
```rust,ignore
102102
#![allow(clippy::style)]
103103
104-
#[warn(clippy::double_neg)]
104+
#[warn(clippy::box_default)]
105105
fn main() {
106-
let x = 1;
107-
let y = --x;
108-
// ^^ warning: double negation
106+
let _ = Box::<String>::new(Default::default());
107+
// ^ warning: `Box::new(_)` of default value
109108
}
110109
```
111110

clippy_config/src/conf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ define_Conf! {
619619
manual_pattern_char_comparison,
620620
manual_range_contains,
621621
manual_rem_euclid,
622+
manual_repeat_n,
622623
manual_retain,
623624
manual_split_once,
624625
manual_str_repeat,
@@ -631,11 +632,13 @@ define_Conf! {
631632
mem_replace_with_default,
632633
missing_const_for_fn,
633634
needless_borrow,
635+
non_std_lazy_statics,
634636
option_as_ref_deref,
635637
option_map_unwrap_or,
636638
ptr_as_ptr,
637639
redundant_field_names,
638640
redundant_static_lifetimes,
641+
same_item_push,
639642
seek_from_current,
640643
seek_rewind,
641644
transmute_ptr_to_ref,

clippy_dev/src/new_lint.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,9 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
255255
let name_camel = to_camel_case(lint.name);
256256
let name_upper = lint_name.to_uppercase();
257257

258-
result.push_str(&if enable_msrv {
259-
formatdoc!(
258+
if enable_msrv {
259+
let _: fmt::Result = writedoc!(
260+
result,
260261
r"
261262
use clippy_utils::msrvs::{{self, Msrv}};
262263
use clippy_config::Conf;
@@ -265,22 +266,24 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
265266
use rustc_session::impl_lint_pass;
266267
267268
"
268-
)
269+
);
269270
} else {
270-
formatdoc!(
271+
let _: fmt::Result = writedoc!(
272+
result,
271273
r"
272274
{pass_import}
273275
use rustc_lint::{{{context_import}, {pass_type}}};
274276
use rustc_session::declare_lint_pass;
275277
276278
"
277-
)
278-
});
279+
);
280+
}
279281

280282
let _: fmt::Result = writeln!(result, "{}", get_lint_declaration(&name_upper, category));
281283

282-
result.push_str(&if enable_msrv {
283-
formatdoc!(
284+
if enable_msrv {
285+
let _: fmt::Result = writedoc!(
286+
result,
284287
r"
285288
pub struct {name_camel} {{
286289
msrv: Msrv,
@@ -301,16 +304,17 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
301304
// TODO: Add MSRV level to `clippy_config/src/msrvs.rs` if needed.
302305
// TODO: Update msrv config comment in `clippy_config/src/conf.rs`
303306
"
304-
)
307+
);
305308
} else {
306-
formatdoc!(
309+
let _: fmt::Result = writedoc!(
310+
result,
307311
r"
308312
declare_lint_pass!({name_camel} => [{name_upper}]);
309313
310314
impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
311315
"
312-
)
313-
});
316+
);
317+
}
314318

315319
result
316320
}

clippy_lints/src/box_default.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use clippy_utils::ty::expr_sig;
44
use clippy_utils::{is_default_equivalent, path_def_id};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::Res;
7-
use rustc_hir::intravisit::{Visitor, walk_ty};
8-
use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind};
7+
use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_ty};
8+
use rustc_hir::{AmbigArg, Block, Expr, ExprKind, HirId, LetStmt, Node, QPath, Ty, TyKind};
99
use rustc_lint::{LateContext, LateLintPass, LintContext};
1010
use rustc_middle::lint::in_external_macro;
1111
use rustc_session::declare_lint_pass;
12-
use rustc_span::sym;
12+
use rustc_span::{Span, sym};
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
@@ -92,8 +92,13 @@ fn is_local_vec_expn(cx: &LateContext<'_>, expr: &Expr<'_>, ref_expr: &Expr<'_>)
9292
struct InferVisitor(bool);
9393

9494
impl Visitor<'_> for InferVisitor {
95-
fn visit_ty(&mut self, t: &Ty<'_>) {
96-
self.0 |= matches!(t.kind, TyKind::Infer | TyKind::OpaqueDef(..) | TyKind::TraitObject(..));
95+
fn visit_infer(&mut self, inf_id: HirId, _inf_span: Span, _kind: InferKind<'_>) -> Self::Result {
96+
self.0 = true;
97+
self.visit_id(inf_id);
98+
}
99+
100+
fn visit_ty(&mut self, t: &Ty<'_, AmbigArg>) {
101+
self.0 |= matches!(t.kind, TyKind::OpaqueDef(..) | TyKind::TraitObject(..));
97102
if !self.0 {
98103
walk_ty(self, t);
99104
}
@@ -104,7 +109,7 @@ fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
104109
match cx.tcx.parent_hir_node(expr.hir_id) {
105110
Node::LetStmt(LetStmt { ty: Some(ty), .. }) => {
106111
let mut v = InferVisitor::default();
107-
v.visit_ty(ty);
112+
v.visit_ty_unambig(ty);
108113
!v.0
109114
},
110115
Node::Expr(Expr {

0 commit comments

Comments
 (0)