Skip to content

Add a reason to/remove some //@no-rustfix annotations #14839

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

Merged
merged 1 commit into from
May 18, 2025
Merged
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
38 changes: 36 additions & 2 deletions tests/ui/assign_ops.fixed
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(clippy::useless_vec)]
#![warn(clippy::assign_op_pattern)]

use core::num::Wrapping;
use std::ops::{Mul, MulAssign};

#[allow(dead_code, unused_assignments, clippy::useless_vec)]
#[warn(clippy::assign_op_pattern)]
fn main() {
let mut a = 5;
a += 1;
Expand Down Expand Up @@ -39,3 +41,35 @@ fn main() {
v[0] = v[0] + v[1];
let _ = || v[0] = v[0] + v[1];
}

fn cow_add_assign() {
use std::borrow::Cow;
let mut buf = Cow::Owned(String::from("bar"));
let cows = Cow::Borrowed("foo");

// this can be linted
buf += cows.clone();
//~^ assign_op_pattern

// this should not as cow<str> Add is not commutative
buf = cows + buf;
}

// check that we don't lint on op assign impls, because that's just the way to impl them

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Wrap(i64);

impl Mul<i64> for Wrap {
type Output = Self;

fn mul(self, rhs: i64) -> Self {
Wrap(self.0 * rhs)
}
}

impl MulAssign<i64> for Wrap {
fn mul_assign(&mut self, rhs: i64) {
*self = *self * rhs
}
}
38 changes: 36 additions & 2 deletions tests/ui/assign_ops.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(clippy::useless_vec)]
#![warn(clippy::assign_op_pattern)]

use core::num::Wrapping;
use std::ops::{Mul, MulAssign};

#[allow(dead_code, unused_assignments, clippy::useless_vec)]
#[warn(clippy::assign_op_pattern)]
fn main() {
let mut a = 5;
a = a + 1;
Expand Down Expand Up @@ -39,3 +41,35 @@ fn main() {
v[0] = v[0] + v[1];
let _ = || v[0] = v[0] + v[1];
}

fn cow_add_assign() {
use std::borrow::Cow;
let mut buf = Cow::Owned(String::from("bar"));
let cows = Cow::Borrowed("foo");

// this can be linted
buf = buf + cows.clone();
//~^ assign_op_pattern

// this should not as cow<str> Add is not commutative
buf = cows + buf;
}

// check that we don't lint on op assign impls, because that's just the way to impl them

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Wrap(i64);

impl Mul<i64> for Wrap {
type Output = Self;

fn mul(self, rhs: i64) -> Self {
Wrap(self.0 * rhs)
}
}

impl MulAssign<i64> for Wrap {
fn mul_assign(&mut self, rhs: i64) {
*self = *self * rhs
}
}
30 changes: 18 additions & 12 deletions tests/ui/assign_ops.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:7:5
--> tests/ui/assign_ops.rs:9:5
|
LL | a = a + 1;
| ^^^^^^^^^ help: replace it with: `a += 1`
Expand All @@ -8,64 +8,70 @@ LL | a = a + 1;
= help: to override `-D warnings` add `#[allow(clippy::assign_op_pattern)]`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:9:5
--> tests/ui/assign_ops.rs:11:5
|
LL | a = 1 + a;
| ^^^^^^^^^ help: replace it with: `a += 1`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:11:5
--> tests/ui/assign_ops.rs:13:5
|
LL | a = a - 1;
| ^^^^^^^^^ help: replace it with: `a -= 1`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:13:5
--> tests/ui/assign_ops.rs:15:5
|
LL | a = a * 99;
| ^^^^^^^^^^ help: replace it with: `a *= 99`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:15:5
--> tests/ui/assign_ops.rs:17:5
|
LL | a = 42 * a;
| ^^^^^^^^^^ help: replace it with: `a *= 42`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:17:5
--> tests/ui/assign_ops.rs:19:5
|
LL | a = a / 2;
| ^^^^^^^^^ help: replace it with: `a /= 2`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:19:5
--> tests/ui/assign_ops.rs:21:5
|
LL | a = a % 5;
| ^^^^^^^^^ help: replace it with: `a %= 5`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:21:5
--> tests/ui/assign_ops.rs:23:5
|
LL | a = a & 1;
| ^^^^^^^^^ help: replace it with: `a &= 1`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:28:5
--> tests/ui/assign_ops.rs:30:5
|
LL | s = s + "bla";
| ^^^^^^^^^^^^^ help: replace it with: `s += "bla"`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:33:5
--> tests/ui/assign_ops.rs:35:5
|
LL | a = a + Wrapping(1u32);
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `a += Wrapping(1u32)`

error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:36:5
--> tests/ui/assign_ops.rs:38:5
|
LL | v[0] = v[0] + v[1];
| ^^^^^^^^^^^^^^^^^^ help: replace it with: `v[0] += v[1]`

error: aborting due to 11 previous errors
error: manual implementation of an assign operation
--> tests/ui/assign_ops.rs:51:5
|
LL | buf = buf + cows.clone();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `buf += cows.clone()`

error: aborting due to 12 previous errors

77 changes: 0 additions & 77 deletions tests/ui/assign_ops2.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/cast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@no-rustfix
//@no-rustfix: only some diagnostics have suggestions

#![feature(repr128)]
#![allow(incomplete_features)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cast_size.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@revisions: 32bit 64bit
//@[32bit]ignore-bitwidth: 64
//@[64bit]ignore-bitwidth: 32
//@no-rustfix
//@no-rustfix: only some diagnostics have suggestions

#![warn(
clippy::cast_precision_loss,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/checked_unwrap/complex_conditionals_nested.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
clippy::branches_sharing_code,
clippy::unnecessary_literal_unwrap
)]
//@no-rustfix
//@no-rustfix: has placeholders
fn test_nested() {
fn nested() {
let x = Some(());
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/checked_unwrap/simple_conditionals.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@no-rustfix: overlapping suggestions
//@no-rustfix: has placeholders
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
#![allow(
clippy::if_same_then_else,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/comparison_chain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@no-rustfix
//@no-rustfix: has placeholders
#![allow(dead_code)]
#![warn(clippy::comparison_chain)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dbg_macro/dbg_macro_unfixable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@no-rustfix
//@no-rustfix: overlapping suggestions
//@error-in-other-file:
#![warn(clippy::dbg_macro)]

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/double_ended_iterator_last_unfixable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@no-rustfix
//@no-rustfix: requires manual changes
#![warn(clippy::double_ended_iterator_last)]

// Should not be linted because applying the lint would move the original iterator. This can only be
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/entry_unfixable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(unused, clippy::needless_pass_by_value, clippy::collapsible_if)]
#![allow(clippy::needless_pass_by_value, clippy::collapsible_if)]
#![warn(clippy::map_entry)]
//@no-rustfix

use std::collections::HashMap;
use std::hash::Hash;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/entry_unfixable.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: usage of `contains_key` followed by `insert` on a `HashMap`
--> tests/ui/entry_unfixable.rs:28:13
--> tests/ui/entry_unfixable.rs:27:13
|
LL | / if !self.values.contains_key(&name) {
LL | |
Expand All @@ -14,7 +14,7 @@ LL | | }
= help: to override `-D warnings` add `#[allow(clippy::map_entry)]`

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> tests/ui/entry_unfixable.rs:43:5
--> tests/ui/entry_unfixable.rs:42:5
|
LL | / if hm.contains_key(&key) {
LL | |
Expand All @@ -26,7 +26,7 @@ LL | | }
| |_____^

error: usage of `contains_key` followed by `insert` on a `HashMap`
--> tests/ui/entry_unfixable.rs:81:13
--> tests/ui/entry_unfixable.rs:80:13
|
LL | / if self.globals.contains_key(&name) {
LL | |
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/explicit_counter_loop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![warn(clippy::explicit_counter_loop)]
#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
//@no-rustfix
//@no-rustfix: suggestion does not remove the `+= 1`
fn main() {
let mut vec = vec![1, 2, 3, 4];
let mut _index = 0;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/filter_map_bool_then_unfixable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(clippy::question_mark, unused)]
#![allow(clippy::question_mark)]
#![warn(clippy::filter_map_bool_then)]
//@no-rustfix

fn issue11617() {
let mut x: Vec<usize> = vec![0; 10];
Expand Down
Loading