Skip to content

Commit 12cbb6c

Browse files
committed
Merge commit '435a8ad86c7a33bd7ffb91c59039943408d3b6aa' into clippyup
2 parents 25f084d + 435a8ad commit 12cbb6c

File tree

149 files changed

+2623
-1114
lines changed

Some content is hidden

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

149 files changed

+2623
-1114
lines changed

src/tools/clippy/.github/workflows/clippy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
github_token: "${{ secrets.github_token }}"
4040

4141
- name: Checkout
42-
uses: actions/checkout@v3.0.2
42+
uses: actions/checkout@v3
4343

4444
- name: Install toolchain
4545
run: rustup show active-toolchain

src/tools/clippy/.github/workflows/clippy_bors.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
github_token: "${{ secrets.github_token }}"
2828

2929
- name: Checkout
30-
uses: actions/checkout@v3.0.2
30+
uses: actions/checkout@v3
3131
with:
3232
ref: ${{ github.ref }}
3333

@@ -83,7 +83,7 @@ jobs:
8383
github_token: "${{ secrets.github_token }}"
8484

8585
- name: Checkout
86-
uses: actions/checkout@v3.0.2
86+
uses: actions/checkout@v3
8787

8888
- name: Install toolchain
8989
run: rustup show active-toolchain
@@ -149,7 +149,7 @@ jobs:
149149
github_token: "${{ secrets.github_token }}"
150150

151151
- name: Checkout
152-
uses: actions/checkout@v3.0.2
152+
uses: actions/checkout@v3
153153

154154
- name: Install toolchain
155155
run: rustup show active-toolchain
@@ -173,7 +173,7 @@ jobs:
173173
github_token: "${{ secrets.github_token }}"
174174

175175
- name: Checkout
176-
uses: actions/checkout@v3.0.2
176+
uses: actions/checkout@v3
177177

178178
- name: Install toolchain
179179
run: rustup show active-toolchain
@@ -233,7 +233,7 @@ jobs:
233233
github_token: "${{ secrets.github_token }}"
234234

235235
- name: Checkout
236-
uses: actions/checkout@v3.0.2
236+
uses: actions/checkout@v3
237237

238238
- name: Install toolchain
239239
run: rustup show active-toolchain

src/tools/clippy/.github/workflows/clippy_dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
steps:
2626
# Setup
2727
- name: Checkout
28-
uses: actions/checkout@v3.0.2
28+
uses: actions/checkout@v3
2929

3030
# Run
3131
- name: Build

src/tools/clippy/.github/workflows/deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
steps:
2222
# Setup
2323
- name: Checkout
24-
uses: actions/checkout@v3.0.2
24+
uses: actions/checkout@v3
2525

2626
- name: Checkout
27-
uses: actions/checkout@v3.0.2
27+
uses: actions/checkout@v3
2828
with:
2929
ref: ${{ env.TARGET_BRANCH }}
3030
path: 'out'

src/tools/clippy/.github/workflows/remark.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
steps:
1717
# Setup
1818
- name: Checkout
19-
uses: actions/checkout@v3.0.2
19+
uses: actions/checkout@v3
2020

2121
- name: Setup Node.js
22-
uses: actions/setup-node@v1.4.4
22+
uses: actions/setup-node@v3
2323
with:
2424
node-version: '14.x'
2525

src/tools/clippy/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4620,6 +4620,7 @@ Released 2018-09-13
46204620
[`else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
46214621
[`empty_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_drop
46224622
[`empty_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_enum
4623+
[`empty_line_after_doc_comments`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
46234624
[`empty_line_after_outer_attr`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_outer_attr
46244625
[`empty_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_loop
46254626
[`empty_structs_with_brackets`]: https://rust-lang.github.io/rust-clippy/master/index.html#empty_structs_with_brackets
@@ -4785,6 +4786,7 @@ Released 2018-09-13
47854786
[`manual_main_separator_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str
47864787
[`manual_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_map
47874788
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
4789+
[`manual_next_back`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_next_back
47884790
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
47894791
[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or
47904792
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
@@ -4897,6 +4899,7 @@ Released 2018-09-13
48974899
[`no_effect_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
48984900
[`no_mangle_with_rust_abi`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
48994901
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
4902+
[`non_minimal_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_minimal_cfg
49004903
[`non_octal_unix_permissions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions
49014904
[`non_send_fields_in_send_ty`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty
49024905
[`nonminimal_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool
@@ -4978,6 +4981,7 @@ Released 2018-09-13
49784981
[`ref_binding_to_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference
49794982
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
49804983
[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
4984+
[`ref_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_patterns
49814985
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
49824986
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
49834987
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts

src/tools/clippy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
278278

279279
<!-- REUSE-IgnoreStart -->
280280

281-
Copyright 2014-2022 The Rust Project Developers
281+
Copyright 2014-2023 The Rust Project Developers
282282

283283
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
284284
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license

src/tools/clippy/book/src/development/type_checking.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ in this chapter:
133133
- [Type checking](https://rustc-dev-guide.rust-lang.org/type-checking.html)
134134
- [Ty module](https://rustc-dev-guide.rust-lang.org/ty.html)
135135

136-
[Adt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variant.Adt
136+
[Adt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html#variant.Adt
137137
[AdtDef]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html
138138
[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty
139139
[node_type]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type
@@ -142,9 +142,9 @@ in this chapter:
142142
[kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.kind
143143
[LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html
144144
[LateLintPass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
145-
[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.pat_ty
145+
[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/typeck_results/struct.TypeckResults.html#method.pat_ty
146146
[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
147-
[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html
147+
[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/sty/enum.TyKind.html
148148
[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html
149149
[middle_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/ty/struct.Ty.html
150150
[hir_ty]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_hir/struct.Ty.html

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if_chain = "1.0"
1717
itertools = "0.10.1"
1818
pulldown-cmark = { version = "0.9", default-features = false }
1919
quine-mc_cluskey = "0.2"
20-
regex-syntax = "0.6"
20+
regex-syntax = "0.7"
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = { version = "1.0", optional = true }
2323
tempfile = { version = "3.2", optional = true }

src/tools/clippy/clippy_lints/src/assertions_on_constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
3838
_ => return,
3939
};
4040
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else { return };
41-
let Some((Constant::Bool(val), _)) = constant(cx, cx.typeck_results(), condition) else { return };
41+
let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else { return };
4242
if val {
4343
span_lint_and_help(
4444
cx,

src/tools/clippy/clippy_lints/src/attrs.rs

+136-8
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,52 @@ declare_clippy_lint! {
176176
"empty line after outer attribute"
177177
}
178178

179+
declare_clippy_lint! {
180+
/// ### What it does
181+
/// Checks for empty lines after documenation comments.
182+
///
183+
/// ### Why is this bad?
184+
/// The documentation comment was most likely meant to be an inner attribute or regular comment.
185+
/// If it was intended to be a documentation comment, then the empty line should be removed to
186+
/// be more idiomatic.
187+
///
188+
/// ### Known problems
189+
/// Only detects empty lines immediately following the documentation. If the doc comment is followed
190+
/// by an attribute and then an empty line, this lint will not trigger. Use `empty_line_after_outer_attr`
191+
/// in combination with this lint to detect both cases.
192+
///
193+
/// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`).
194+
///
195+
/// ### Example
196+
/// ```rust
197+
/// /// Some doc comment with a blank line after it.
198+
///
199+
/// fn not_quite_good_code() { }
200+
/// ```
201+
///
202+
/// Use instead:
203+
/// ```rust
204+
/// /// Good (no blank line)
205+
/// fn this_is_fine() { }
206+
/// ```
207+
///
208+
/// ```rust
209+
/// // Good (convert to a regular comment)
210+
///
211+
/// fn this_is_fine_too() { }
212+
/// ```
213+
///
214+
/// ```rust
215+
/// //! Good (convert to a comment on an inner attribute)
216+
///
217+
/// fn this_is_fine_as_well() { }
218+
/// ```
219+
#[clippy::version = "1.70.0"]
220+
pub EMPTY_LINE_AFTER_DOC_COMMENTS,
221+
nursery,
222+
"empty line after documentation comments"
223+
}
224+
179225
declare_clippy_lint! {
180226
/// ### What it does
181227
/// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
@@ -292,6 +338,30 @@ declare_clippy_lint! {
292338
"ensures that all `allow` and `expect` attributes have a reason"
293339
}
294340

341+
declare_clippy_lint! {
342+
/// ### What it does
343+
/// Checks for `any` and `all` combinators in `cfg` with only one condition.
344+
///
345+
/// ### Why is this bad?
346+
/// If there is only one condition, no need to wrap it into `any` or `all` combinators.
347+
///
348+
/// ### Example
349+
/// ```rust
350+
/// #[cfg(any(unix))]
351+
/// pub struct Bar;
352+
/// ```
353+
///
354+
/// Use instead:
355+
/// ```rust
356+
/// #[cfg(unix)]
357+
/// pub struct Bar;
358+
/// ```
359+
#[clippy::version = "1.71.0"]
360+
pub NON_MINIMAL_CFG,
361+
style,
362+
"ensure that all `cfg(any())` and `cfg(all())` have more than one condition"
363+
}
364+
295365
declare_lint_pass!(Attributes => [
296366
ALLOW_ATTRIBUTES_WITHOUT_REASON,
297367
INLINE_ALWAYS,
@@ -604,6 +674,8 @@ impl_lint_pass!(EarlyAttributes => [
604674
DEPRECATED_CFG_ATTR,
605675
MISMATCHED_TARGET_OS,
606676
EMPTY_LINE_AFTER_OUTER_ATTR,
677+
EMPTY_LINE_AFTER_DOC_COMMENTS,
678+
NON_MINIMAL_CFG,
607679
]);
608680

609681
impl EarlyLintPass for EarlyAttributes {
@@ -614,15 +686,22 @@ impl EarlyLintPass for EarlyAttributes {
614686
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
615687
check_deprecated_cfg_attr(cx, attr, &self.msrv);
616688
check_mismatched_target_os(cx, attr);
689+
check_minimal_cfg_condition(cx, attr);
617690
}
618691

619692
extract_msrv_attr!(EarlyContext);
620693
}
621694

695+
/// Check for empty lines after outer attributes.
696+
///
697+
/// Attributes and documenation comments are both considered outer attributes
698+
/// by the AST. However, the average user likely considers them to be different.
699+
/// Checking for empty lines after each of these attributes is split into two different
700+
/// lints but can share the same logic.
622701
fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
623702
let mut iter = item.attrs.iter().peekable();
624703
while let Some(attr) = iter.next() {
625-
if matches!(attr.kind, AttrKind::Normal(..))
704+
if (matches!(attr.kind, AttrKind::Normal(..)) || matches!(attr.kind, AttrKind::DocComment(..)))
626705
&& attr.style == AttrStyle::Outer
627706
&& is_present_in_source(cx, attr.span)
628707
{
@@ -639,13 +718,20 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
639718
let lines = without_block_comments(lines);
640719

641720
if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
642-
span_lint(
643-
cx,
644-
EMPTY_LINE_AFTER_OUTER_ATTR,
645-
begin_of_attr_to_item,
646-
"found an empty line after an outer attribute. \
647-
Perhaps you forgot to add a `!` to make it an inner attribute?",
648-
);
721+
let (lint_msg, lint_type) = match attr.kind {
722+
AttrKind::DocComment(..) => (
723+
"found an empty line after a doc comment. \
724+
Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`?",
725+
EMPTY_LINE_AFTER_DOC_COMMENTS,
726+
),
727+
AttrKind::Normal(..) => (
728+
"found an empty line after an outer attribute. \
729+
Perhaps you forgot to add a `!` to make it an inner attribute?",
730+
EMPTY_LINE_AFTER_OUTER_ATTR,
731+
),
732+
};
733+
734+
span_lint(cx, lint_type, begin_of_attr_to_item, lint_msg);
649735
}
650736
}
651737
}
@@ -690,6 +776,48 @@ fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msr
690776
}
691777
}
692778

779+
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
780+
for item in items.iter() {
781+
if let NestedMetaItem::MetaItem(meta) = item {
782+
if !meta.has_name(sym::any) && !meta.has_name(sym::all) {
783+
continue;
784+
}
785+
if let MetaItemKind::List(list) = &meta.kind {
786+
check_nested_cfg(cx, list);
787+
if list.len() == 1 {
788+
span_lint_and_then(
789+
cx,
790+
NON_MINIMAL_CFG,
791+
meta.span,
792+
"unneeded sub `cfg` when there is only one condition",
793+
|diag| {
794+
if let Some(snippet) = snippet_opt(cx, list[0].span()) {
795+
diag.span_suggestion(meta.span, "try", snippet, Applicability::MaybeIncorrect);
796+
}
797+
},
798+
);
799+
} else if list.is_empty() && meta.has_name(sym::all) {
800+
span_lint_and_then(
801+
cx,
802+
NON_MINIMAL_CFG,
803+
meta.span,
804+
"unneeded sub `cfg` when there is no condition",
805+
|_| {},
806+
);
807+
}
808+
}
809+
}
810+
}
811+
}
812+
813+
fn check_minimal_cfg_condition(cx: &EarlyContext<'_>, attr: &Attribute) {
814+
if attr.has_name(sym::cfg) &&
815+
let Some(items) = attr.meta_item_list()
816+
{
817+
check_nested_cfg(cx, &items);
818+
}
819+
}
820+
693821
fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
694822
fn find_os(name: &str) -> Option<&'static str> {
695823
UNIX_SYSTEMS

src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::reference::DEREF_ADDROF;
22
use clippy_utils::diagnostics::span_lint_and_then;
3+
use clippy_utils::is_from_proc_macro;
34
use clippy_utils::source::snippet_opt;
45
use clippy_utils::ty::implements_trait;
56
use clippy_utils::{get_parent_expr, is_lint_allowed};
@@ -47,8 +48,8 @@ declare_clippy_lint! {
4748

4849
declare_lint_pass!(BorrowDerefRef => [BORROW_DEREF_REF]);
4950

50-
impl LateLintPass<'_> for BorrowDerefRef {
51-
fn check_expr(&mut self, cx: &LateContext<'_>, e: &rustc_hir::Expr<'_>) {
51+
impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
52+
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
5253
if_chain! {
5354
if !e.span.from_expansion();
5455
if let ExprKind::AddrOf(_, Mutability::Not, addrof_target) = e.kind;
@@ -58,6 +59,7 @@ impl LateLintPass<'_> for BorrowDerefRef {
5859
if !matches!(deref_target.kind, ExprKind::Unary(UnOp::Deref, ..) );
5960
let ref_ty = cx.typeck_results().expr_ty(deref_target);
6061
if let ty::Ref(_, inner_ty, Mutability::Not) = ref_ty.kind();
62+
if !is_from_proc_macro(cx, e);
6163
then{
6264

6365
if let Some(parent_expr) = get_parent_expr(cx, e){

0 commit comments

Comments
 (0)