Skip to content

Misc fixes #11186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/error_impl_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare_clippy_lint! {
///
/// impl std::error::Error for Error { ... }
/// ```
#[clippy::version = "1.72.0"]
#[clippy::version = "1.73.0"]
pub ERROR_IMPL_ERROR,
restriction,
"exported types named `Error` that implement `Error`"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/excessive_nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ declare_clippy_lint! {
/// // lib.rs
/// pub mod a;
/// ```
#[clippy::version = "1.70.0"]
#[clippy::version = "1.72.0"]
pub EXCESSIVE_NESTING,
complexity,
"checks for blocks nested beyond a certain threshold"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/four_forward_slashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare_clippy_lint! {
/// // ...
/// }
/// ```
#[clippy::version = "1.72.0"]
#[clippy::version = "1.73.0"]
pub FOUR_FORWARD_SLASHES,
suspicious,
"comments with 4 forward slashes (`////`) likely intended to be doc comments (`///`)"
Expand Down
7 changes: 4 additions & 3 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3365,6 +3365,7 @@ declare_clippy_lint! {
}

declare_clippy_lint! {
/// ### What it does
/// Looks for calls to [`Stdin::read_line`] to read a line from the standard input
/// into a string, then later attempting to parse this string into a type without first trimming it, which will
/// always fail because the string has a trailing newline in it.
Expand Down Expand Up @@ -3415,7 +3416,7 @@ declare_clippy_lint! {
/// # let c = 'c';
/// matches!(c, '\\' | '.' | '+' | '*' | '(' | ')' | '|' | '[' | ']' | '{' | '}' | '^' | '$' | '#' | '&' | '-' | '~');
/// ```
#[clippy::version = "1.72.0"]
#[clippy::version = "1.73.0"]
pub STRING_LIT_CHARS_ANY,
restriction,
"checks for `<string_lit>.chars().any(|i| i == c)`"
Expand Down Expand Up @@ -3450,7 +3451,7 @@ declare_clippy_lint! {
/// })
/// }
/// ```
#[clippy::version = "1.72.0"]
#[clippy::version = "1.73.0"]
pub FORMAT_COLLECT,
perf,
"`format!`ing every element in a collection, then collecting the strings into a new `String`"
Expand All @@ -3471,7 +3472,7 @@ declare_clippy_lint! {
/// let y = v.iter().collect::<Vec<_>>();
/// assert_eq!(x, y);
/// ```
#[clippy::version = "1.72.0"]
#[clippy::version = "1.73.0"]
pub ITER_SKIP_ZERO,
correctness,
"disallows `.skip(0)`"
Expand Down
9 changes: 4 additions & 5 deletions clippy_lints/src/needless_pass_by_ref_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rustc_target::spec::abi::Abi;

declare_clippy_lint! {
/// ### What it does
/// Check if a `&mut` function argument is actually used mutably.
/// Checks if a `&mut` function argument is actually used mutably.
///
/// Be careful if the function is publicly reexported as it would break compatibility with
/// users of this function.
Expand Down Expand Up @@ -89,7 +89,6 @@ fn should_skip<'tcx>(
}
}

// All spans generated from a proc-macro invocation are the same...
is_from_proc_macro(cx, &input)
}

Expand Down Expand Up @@ -203,19 +202,19 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
NEEDLESS_PASS_BY_REF_MUT,
cx.tcx.hir().local_def_id_to_hir_id(*fn_def_id),
sp,
"this argument is a mutable reference, but not used mutably",
"this argument is a mutable reference, but never used mutably",
|diag| {
diag.span_suggestion(
sp,
"consider changing to".to_string(),
"consider using an immutable reference instead",
format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),),
Applicability::Unspecified,
);
if show_semver_warning {
diag.warn("changing this function will impact semver compatibility");
}
if *is_cfged {
diag.note("this is cfg-gated and may require further changes");
diag.note("this is `cfg`-gated and may require further changes");
}
},
);
Expand Down
12 changes: 7 additions & 5 deletions clippy_lints/src/single_call_fn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::{is_from_proc_macro, is_in_test_function};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -88,16 +88,18 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
};
cx.tcx.hir().visit_all_item_likes_in_crate(&mut v);

for usage in self.def_id_to_usage.values() {
for (def_id, usage) in &self.def_id_to_usage {
let single_call_fn_span = usage.0;
if let [caller_span] = *usage.1 {
span_lint_and_help(
span_lint_hir_and_then(
cx,
SINGLE_CALL_FN,
cx.tcx.hir().local_def_id_to_hir_id(*def_id),
single_call_fn_span,
"this function is only used once",
Some(caller_span),
"used here",
|diag| {
diag.span_help(caller_span, "used here");
},
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/tuple_array_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.72.0"]
pub TUPLE_ARRAY_CONVERSIONS,
nursery,
pedantic,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to move this to pedantic?

"checks for tuple<=>array conversions that are not done with `.into()`"
}
impl_lint_pass!(TupleArrayConversions => [TUPLE_ARRAY_CONVERSIONS]);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/infinite_loop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_pass_by_ref_mut)]

fn fn_val(i: i32) -> i32 {
unimplemented!()
}
Expand Down
32 changes: 12 additions & 20 deletions tests/ui/infinite_loop.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:20:11
--> $DIR/infinite_loop.rs:22:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -8,71 +8,71 @@ LL | while y < 10 {
= note: `#[deny(clippy::while_immutable_condition)]` on by default

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:25:11
--> $DIR/infinite_loop.rs:27:11
|
LL | while y < 10 && x < 3 {
| ^^^^^^^^^^^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:32:11
--> $DIR/infinite_loop.rs:34:11
|
LL | while !cond {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:76:11
--> $DIR/infinite_loop.rs:78:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:81:11
--> $DIR/infinite_loop.rs:83:11
|
LL | while i < 3 && j > 0 {
| ^^^^^^^^^^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:85:11
--> $DIR/infinite_loop.rs:87:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:100:11
--> $DIR/infinite_loop.rs:102:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:105:11
--> $DIR/infinite_loop.rs:107:11
|
LL | while i < 3 {
| ^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:171:15
--> $DIR/infinite_loop.rs:173:15
|
LL | while self.count < n {
| ^^^^^^^^^^^^^^
|
= note: this may lead to an infinite or to a never running loop

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:179:11
--> $DIR/infinite_loop.rs:181:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -82,7 +82,7 @@ LL | while y < 10 {
= help: rewrite it as `if cond { loop { } }`

error: variables in the condition are not mutated in the loop body
--> $DIR/infinite_loop.rs:186:11
--> $DIR/infinite_loop.rs:188:11
|
LL | while y < 10 {
| ^^^^^^
Expand All @@ -91,13 +91,5 @@ LL | while y < 10 {
= note: this loop contains `return`s or `break`s
= help: rewrite it as `if cond { loop { } }`

error: this argument is a mutable reference, but not used mutably
--> $DIR/infinite_loop.rs:7:17
|
LL | fn fn_mutref(i: &mut i32) {
| ^^^^^^^^ help: consider changing to: `&i32`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`

error: aborting due to 12 previous errors
error: aborting due to 11 previous errors

2 changes: 2 additions & 0 deletions tests/ui/let_underscore_future.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_pass_by_ref_mut)]

use std::future::Future;

async fn some_async_fn() {}
Expand Down
16 changes: 4 additions & 12 deletions tests/ui/let_underscore_future.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:14:5
--> $DIR/let_underscore_future.rs:16:5
|
LL | let _ = some_async_fn();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,28 +8,20 @@ LL | let _ = some_async_fn();
= note: `-D clippy::let-underscore-future` implied by `-D warnings`

error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:15:5
--> $DIR/let_underscore_future.rs:17:5
|
LL | let _ = custom();
| ^^^^^^^^^^^^^^^^^
|
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`

error: non-binding `let` on a future
--> $DIR/let_underscore_future.rs:19:5
--> $DIR/let_underscore_future.rs:21:5
|
LL | let _ = future;
| ^^^^^^^^^^^^^^^
|
= help: consider awaiting the future or dropping explicitly with `std::mem::drop`

error: this argument is a mutable reference, but not used mutably
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we can have a CI test to prevent this stuff from happening 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably search for -D followed by anything that isn't a specific lint. Not sure how you'd set that "specific lint" for each test though

--> $DIR/let_underscore_future.rs:11:35
|
LL | fn do_something_to_future(future: &mut impl Future<Output = ()>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider changing to: `&impl Future<Output = ()>`
|
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

2 changes: 2 additions & 0 deletions tests/ui/mut_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_pass_by_ref_mut)]

use std::cell::Cell;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::hash::{Hash, Hasher};
Expand Down
Loading