Merge commit '2efebd2f0c' into clippy-subtree-update

This commit is contained in:
Philipp Krones 2024-05-21 10:39:30 -07:00
commit bb1481a72a
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
124 changed files with 4052 additions and 1147 deletions

View file

@ -42,4 +42,32 @@ help: to have lints override the group set `pedantic` to a lower priority
19 | pedantic = { level = "warn", priority = -2 }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: could not compile `fail` (lib) due to 3 previous errors
error: lint group `rust_2018_idioms` has the same priority (0) as a lint
--> Cargo.toml:23:1
|
23 | rust_2018_idioms = "warn"
| ^^^^^^^^^^^^^^^^ ------ has an implicit priority of 0
24 | bare_trait_objects = "allow"
| ------------------ has the same priority as this lint
|
= note: the order of the lints in the table is ignored by Cargo
help: to have lints override the group set `rust_2018_idioms` to a lower priority
|
23 | rust_2018_idioms = { level = "warn", priority = -1 }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: lint group `pedantic` has the same priority (0) as a lint
--> Cargo.toml:27:1
|
27 | pedantic = "warn"
| ^^^^^^^^ ------ has an implicit priority of 0
28 | similar_names = "allow"
| ------------- has the same priority as this lint
|
= note: the order of the lints in the table is ignored by Cargo
help: to have lints override the group set `pedantic` to a lower priority
|
27 | pedantic = { level = "warn", priority = -1 }
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: could not compile `fail` (lib) due to 5 previous errors

View file

@ -18,3 +18,11 @@ deprecated = "allow"
[lints.clippy]
pedantic = { level = "warn", priority = -1 }
similar_names = { level = "allow", priority = -1 }
[workspace.lints.rust]
rust_2018_idioms = "warn"
bare_trait_objects = "allow"
[workspace.lints.clippy]
pedantic = "warn"
similar_names = "allow"

View file

@ -0,0 +1,260 @@
//! Tests macro_metavars_in_unsafe with default configuration
#![feature(decl_macro, lint_reasons)]
#![warn(clippy::macro_metavars_in_unsafe)]
#![allow(clippy::no_effect)]
#[macro_export]
macro_rules! allow_works {
($v:expr) => {
#[expect(clippy::macro_metavars_in_unsafe)]
unsafe {
$v;
};
};
}
#[macro_export]
macro_rules! simple {
($v:expr) => {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
dbg!($v);
}
};
}
#[macro_export]
#[rustfmt::skip] // for some reason rustfmt rewrites $r#unsafe to r#u$nsafe, bug?
macro_rules! raw_symbol {
($r#mod:expr, $r#unsafe:expr) => {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$r#mod;
}
$r#unsafe;
};
}
#[macro_export]
macro_rules! multilevel_unsafe {
($v:expr) => {
unsafe {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$v;
}
}
};
}
#[macro_export]
macro_rules! in_function {
($v:expr) => {
unsafe {
fn f() {
// function introduces a new body, so don't lint.
$v;
}
}
};
}
#[macro_export]
macro_rules! in_function_with_unsafe {
($v:expr) => {
unsafe {
fn f() {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$v;
}
}
}
};
}
#[macro_export]
macro_rules! const_static {
($c:expr, $s:expr) => {
unsafe {
// const and static introduces new body, don't lint
const _X: i32 = $c;
static _Y: i32 = $s;
}
};
}
#[macro_export]
macro_rules! const_generic_in_struct {
($inside_unsafe:expr, $outside_unsafe:expr) => {
unsafe {
struct Ty<
const L: i32 = 1,
const M: i32 = {
1;
unsafe { $inside_unsafe }
//~^ ERROR: this macro expands metavariables in an unsafe block
},
const N: i32 = { $outside_unsafe },
>;
}
};
}
#[macro_export]
macro_rules! fn_with_const_generic {
($inside_unsafe:expr, $outside_unsafe:expr) => {
unsafe {
fn f<const N: usize>() {
$outside_unsafe;
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$inside_unsafe;
}
}
}
};
}
#[macro_export]
macro_rules! variables {
($inside_unsafe:expr, $outside_unsafe:expr) => {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$inside_unsafe;
let inside_unsafe = 1;
inside_unsafe;
}
$outside_unsafe;
let outside_unsafe = 1;
outside_unsafe;
};
}
#[macro_export]
macro_rules! multiple_matchers {
($inside_unsafe:expr, $outside_unsafe:expr) => {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$inside_unsafe;
}
$outside_unsafe;
};
($($v:expr, $x:expr),+) => {
$(
$v;
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$x;
}
);+
};
}
#[macro_export]
macro_rules! multiple_unsafe_blocks {
($w:expr, $x:expr, $y:expr) => {
$w;
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$x;
}
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$x;
$y;
}
};
}
pub macro macro2_0($v:expr) {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$v;
}
}
// don't lint private macros with the default configuration
macro_rules! private_mac {
($v:expr) => {
unsafe {
$v;
}
};
}
// don't lint exported macros that are doc(hidden) because they also aren't part of the public API
#[macro_export]
#[doc(hidden)]
macro_rules! exported_but_hidden {
($v:expr) => {
unsafe {
$v;
}
};
}
// don't lint if the same metavariable is expanded in an unsafe block and then outside of one:
// unsafe {} is still needed at callsite so not problematic
#[macro_export]
macro_rules! does_require_unsafe {
($v:expr) => {
unsafe {
$v;
}
$v;
};
}
#[macro_export]
macro_rules! unsafe_from_root_ctxt {
($v:expr) => {
// Expands to unsafe { 1 }, but the unsafe block is from the root ctxt and not this macro,
// so no warning.
$v;
};
}
// invoked from another macro, should still generate a warning
#[macro_export]
macro_rules! nested_macro_helper {
($v:expr) => {{
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
$v;
}
}};
}
#[macro_export]
macro_rules! nested_macros {
($v:expr, $v2:expr) => {{
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
nested_macro_helper!($v);
$v;
}
}};
}
fn main() {
allow_works!(1);
simple!(1);
raw_symbol!(1, 1);
multilevel_unsafe!(1);
in_function!(1);
in_function_with_unsafe!(1);
const_static!(1, 1);
const_generic_in_struct!(1, 1);
fn_with_const_generic!(1, 1);
variables!(1, 1);
multiple_matchers!(1, 1);
multiple_matchers!(1, 1, 1, 1);
macro2_0!(1);
private_mac!(1);
exported_but_hidden!(1);
does_require_unsafe!(1);
multiple_unsafe_blocks!(1, 1, 1);
unsafe_from_root_ctxt!(unsafe { 1 });
nested_macros!(1, 1);
}

View file

@ -0,0 +1,187 @@
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:19:9
|
LL | / unsafe {
LL | |
LL | | dbg!($v);
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
= note: `-D clippy::macro-metavars-in-unsafe` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::macro_metavars_in_unsafe)]`
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:30:9
|
LL | / unsafe {
LL | |
LL | | $r#mod;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:42:13
|
LL | / unsafe {
LL | |
LL | | $v;
LL | | }
| |_____________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:67:17
|
LL | / unsafe {
LL | |
LL | | $v;
LL | | }
| |_________________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:95:21
|
LL | unsafe { $inside_unsafe }
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:110:17
|
LL | / unsafe {
LL | |
LL | | $inside_unsafe;
LL | | }
| |_________________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:122:9
|
LL | / unsafe {
LL | |
LL | | $inside_unsafe;
LL | | let inside_unsafe = 1;
LL | | inside_unsafe;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:137:9
|
LL | / unsafe {
LL | |
LL | | $inside_unsafe;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:146:13
|
LL | / unsafe {
LL | |
LL | | $x;
LL | | }
| |_____________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:171:5
|
LL | / unsafe {
LL | |
LL | | $v;
LL | | }
| |_____^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:158:9
|
LL | / unsafe {
LL | |
LL | | $x;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:162:9
|
LL | / unsafe {
LL | |
LL | | $x;
LL | | $y;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:222:9
|
LL | / unsafe {
LL | |
LL | | $v;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/default/test.rs:232:9
|
LL | / unsafe {
LL | |
LL | | nested_macro_helper!($v);
LL | | $v;
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
error: aborting due to 14 previous errors

View file

@ -0,0 +1 @@
warn-unsafe-macro-metavars-in-private-macros = true

View file

@ -0,0 +1,15 @@
//! Tests macro_metavars_in_unsafe with private (non-exported) macros
#![warn(clippy::macro_metavars_in_unsafe)]
macro_rules! mac {
($v:expr) => {
unsafe {
//~^ ERROR: this macro expands metavariables in an unsafe block
dbg!($v);
}
};
}
fn main() {
mac!(1);
}

View file

@ -0,0 +1,17 @@
error: this macro expands metavariables in an unsafe block
--> tests/ui-toml/macro_metavars_in_unsafe/private/test.rs:6:9
|
LL | / unsafe {
LL | |
LL | | dbg!($v);
LL | | }
| |_________^
|
= note: this allows the user of the macro to write unsafe code outside of an unsafe block
= help: consider expanding any metavariables outside of this block, e.g. by storing them in a variable
= help: ... or also expand referenced metavariables in a safe context to require an unsafe block at callsite
= note: `-D clippy::macro-metavars-in-unsafe` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::macro_metavars_in_unsafe)]`
error: aborting due to 1 previous error

View file

@ -0,0 +1 @@
allow-panic-in-tests = true

View file

@ -0,0 +1,54 @@
//@compile-flags: --test
#![warn(clippy::panic)]
fn main() {
enum Enam {
A,
}
let a = Enam::A;
match a {
Enam::A => {},
_ => panic!(""),
}
}
#[test]
fn lonely_test() {
enum Enam {
A,
}
let a = Enam::A;
match a {
Enam::A => {},
_ => panic!(""),
}
}
#[cfg(test)]
mod tests {
// should not lint in `#[cfg(test)]` modules
#[test]
fn test_fn() {
enum Enam {
A,
}
let a = Enam::A;
match a {
Enam::A => {},
_ => panic!(""),
}
bar();
}
fn bar() {
enum Enam {
A,
}
let a = Enam::A;
match a {
Enam::A => {},
_ => panic!(""),
}
}
}

View file

@ -0,0 +1,11 @@
error: `panic` should not be present in production code
--> tests/ui-toml/panic/panic.rs:11:14
|
LL | _ => panic!(""),
| ^^^^^^^^^^
|
= note: `-D clippy::panic` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::panic)]`
error: aborting due to 1 previous error

View file

@ -0,0 +1,2 @@
# Ignore `From`, `TryFrom`, `FromStr` by default
# allow-renamed-params-for = []

View file

@ -0,0 +1,2 @@
# Ignore `From`, `TryFrom`, `FromStr` by default
allow-renamed-params-for = [ "..", "std::ops::Add", "renamed_function_params::MyTrait" ]

View file

@ -0,0 +1,46 @@
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:30:18
|
LL | fn eq(&self, rhs: &Self) -> bool {
| ^^^ help: consider using the default name: `other`
|
= note: `-D clippy::renamed-function-params` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::renamed_function_params)]`
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:34:18
|
LL | fn ne(&self, rhs: &Self) -> bool {
| ^^^ help: consider using the default name: `other`
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:48:19
|
LL | fn foo(&self, i_dont_wanna_use_your_name: u8) {} // only lint in `extend`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using the default name: `val`
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:55:31
|
LL | fn hash<H: Hasher>(&self, states: &mut H) {
| ^^^^^^ help: consider using the default name: `state`
error: renamed function parameters of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:59:30
|
LL | fn hash_slice<H: Hasher>(date: &[Self], states: &mut H) {
| ^^^^ ^^^^^^
|
help: consider using the default names
|
LL | fn hash_slice<H: Hasher>(data: &[Self], state: &mut H) {
| ~~~~ ~~~~~
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:80:18
|
LL | fn add(self, b: B) -> C {
| ^ help: consider using the default name: `rhs`
error: aborting due to 6 previous errors

View file

@ -0,0 +1,34 @@
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:30:18
|
LL | fn eq(&self, rhs: &Self) -> bool {
| ^^^ help: consider using the default name: `other`
|
= note: `-D clippy::renamed-function-params` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::renamed_function_params)]`
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:34:18
|
LL | fn ne(&self, rhs: &Self) -> bool {
| ^^^ help: consider using the default name: `other`
error: renamed function parameter of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:55:31
|
LL | fn hash<H: Hasher>(&self, states: &mut H) {
| ^^^^^^ help: consider using the default name: `state`
error: renamed function parameters of trait impl
--> tests/ui-toml/renamed_function_params/renamed_function_params.rs:59:30
|
LL | fn hash_slice<H: Hasher>(date: &[Self], states: &mut H) {
| ^^^^ ^^^^^^
|
help: consider using the default names
|
LL | fn hash_slice<H: Hasher>(data: &[Self], state: &mut H) {
| ~~~~ ~~~~~
error: aborting due to 4 previous errors

View file

@ -0,0 +1,110 @@
//@no-rustfix
//@revisions: default extend
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/renamed_function_params/default
//@[extend] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/renamed_function_params/extend
#![warn(clippy::renamed_function_params)]
#![allow(clippy::partialeq_ne_impl, clippy::to_string_trait_impl)]
#![allow(unused)]
use std::hash::{Hash, Hasher};
struct A;
impl From<A> for String {
fn from(_value: A) -> Self {
String::new()
}
}
impl ToString for A {
fn to_string(&self) -> String {
String::new()
}
}
struct B(u32);
impl std::convert::From<B> for String {
fn from(b: B) -> Self {
b.0.to_string()
}
}
impl PartialEq for B {
fn eq(&self, rhs: &Self) -> bool {
//~^ ERROR: renamed function parameter of trait impl
self.0 == rhs.0
}
fn ne(&self, rhs: &Self) -> bool {
//~^ ERROR: renamed function parameter of trait impl
self.0 != rhs.0
}
}
trait MyTrait {
fn foo(&self, val: u8);
fn bar(a: u8, b: u8);
fn baz(self, _val: u8);
fn quz(&self, _: u8);
}
impl MyTrait for B {
fn foo(&self, i_dont_wanna_use_your_name: u8) {} // only lint in `extend`
fn bar(_a: u8, _: u8) {}
fn baz(self, val: u8) {}
fn quz(&self, val: u8) {}
}
impl Hash for B {
fn hash<H: Hasher>(&self, states: &mut H) {
//~^ ERROR: renamed function parameter of trait impl
self.0.hash(states);
}
fn hash_slice<H: Hasher>(date: &[Self], states: &mut H) {
//~^ ERROR: renamed function parameters of trait impl
for d in date {
d.hash(states);
}
}
}
impl B {
fn totally_irrelevant(&self, right: bool) {}
fn some_fn(&self, other: impl MyTrait) {}
}
#[derive(Copy, Clone)]
enum C {
A,
B(u32),
}
impl std::ops::Add<B> for C {
type Output = C;
fn add(self, b: B) -> C {
// only lint in `extend`
C::B(b.0)
}
}
impl From<A> for C {
fn from(_: A) -> C {
C::A
}
}
trait CustomTraitA {
fn foo(&self, other: u32);
}
trait CustomTraitB {
fn bar(&self, value: u8);
}
macro_rules! impl_trait {
($impl_for:ident, $tr:ty, $fn_name:ident, $t:ty) => {
impl $tr for $impl_for {
fn $fn_name(&self, v: $t) {}
}
};
}
impl_trait!(C, CustomTraitA, foo, u32);
impl_trait!(C, CustomTraitB, bar, u8);
fn main() {}

View file

@ -40,3 +40,9 @@ fn main() {
let _ = HashMap;
let _: usize = 64_usize;
}
mod useless_attribute {
// Regression test for https://github.com/rust-lang/rust-clippy/issues/12753
#[allow(clippy::disallowed_types)]
use std::collections::HashMap;
}

View file

@ -8,8 +8,10 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
allow-expect-in-tests
allow-mixed-uninlined-format-args
allow-one-hash-in-raw-strings
allow-panic-in-tests
allow-print-in-tests
allow-private-module-inception
allow-renamed-params-for
allow-unwrap-in-tests
allow-useless-vec-in-tests
allowed-dotfiles
@ -74,6 +76,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
vec-box-size-threshold
verbose-bit-mask-threshold
warn-on-all-wildcard-imports
warn-unsafe-macro-metavars-in-private-macros
--> $DIR/tests/ui-toml/toml_unknown_key/clippy.toml:2:1
|
LL | foobar = 42
@ -89,8 +92,10 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
allow-expect-in-tests
allow-mixed-uninlined-format-args
allow-one-hash-in-raw-strings
allow-panic-in-tests
allow-print-in-tests
allow-private-module-inception
allow-renamed-params-for
allow-unwrap-in-tests
allow-useless-vec-in-tests
allowed-dotfiles
@ -155,6 +160,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
vec-box-size-threshold
verbose-bit-mask-threshold
warn-on-all-wildcard-imports
warn-unsafe-macro-metavars-in-private-macros
--> $DIR/tests/ui-toml/toml_unknown_key/clippy.toml:4:1
|
LL | barfoo = 53
@ -170,8 +176,10 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
allow-expect-in-tests
allow-mixed-uninlined-format-args
allow-one-hash-in-raw-strings
allow-panic-in-tests
allow-print-in-tests
allow-private-module-inception
allow-renamed-params-for
allow-unwrap-in-tests
allow-useless-vec-in-tests
allowed-dotfiles
@ -236,6 +244,7 @@ error: error reading Clippy's configuration file: unknown field `allow_mixed_uni
vec-box-size-threshold
verbose-bit-mask-threshold
warn-on-all-wildcard-imports
warn-unsafe-macro-metavars-in-private-macros
--> $DIR/tests/ui-toml/toml_unknown_key/clippy.toml:7:1
|
LL | allow_mixed_uninlined_format_args = true

View file

@ -62,6 +62,16 @@ fn clone_method_rhs_complex(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFr
mut_thing.clone_from(ref_thing + ref_thing);
}
fn clone_method_macro() {
let mut s = String::from("");
s.clone_from(&format!("{} {}", "hello", "world"));
}
fn clone_function_macro() {
let mut s = String::from("");
Clone::clone_from(&mut s, &format!("{} {}", "hello", "world"));
}
fn assign_to_init_mut_var(b: HasCloneFrom) -> HasCloneFrom {
let mut a = HasCloneFrom;
for _ in 1..10 {
@ -86,6 +96,12 @@ fn assign_to_uninit_mut_var(b: HasCloneFrom) {
a = b.clone();
}
fn late_init_let_tuple() {
let (p, q): (String, String);
p = "ghi".to_string();
q = p.clone();
}
#[derive(Clone)]
pub struct HasDeriveClone;
@ -208,6 +224,16 @@ fn owned_function_val(mut mut_thing: String, ref_str: &str) {
ToOwned::clone_into(ref_str, &mut mut_thing);
}
fn owned_method_macro() {
let mut s = String::from("");
format!("{} {}", "hello", "world").clone_into(&mut s);
}
fn owned_function_macro() {
let mut s = String::from("");
ToOwned::clone_into(&format!("{} {}", "hello", "world"), &mut s);
}
struct FakeToOwned;
impl FakeToOwned {
/// This looks just like `ToOwned::to_owned`

View file

@ -62,6 +62,16 @@ fn clone_method_rhs_complex(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFr
*mut_thing = (ref_thing + ref_thing).clone();
}
fn clone_method_macro() {
let mut s = String::from("");
s = format!("{} {}", "hello", "world").clone();
}
fn clone_function_macro() {
let mut s = String::from("");
s = Clone::clone(&format!("{} {}", "hello", "world"));
}
fn assign_to_init_mut_var(b: HasCloneFrom) -> HasCloneFrom {
let mut a = HasCloneFrom;
for _ in 1..10 {
@ -86,6 +96,12 @@ fn assign_to_uninit_mut_var(b: HasCloneFrom) {
a = b.clone();
}
fn late_init_let_tuple() {
let (p, q): (String, String);
p = "ghi".to_string();
q = p.clone();
}
#[derive(Clone)]
pub struct HasDeriveClone;
@ -208,6 +224,16 @@ fn owned_function_val(mut mut_thing: String, ref_str: &str) {
mut_thing = ToOwned::to_owned(ref_str);
}
fn owned_method_macro() {
let mut s = String::from("");
s = format!("{} {}", "hello", "world").to_owned();
}
fn owned_function_macro() {
let mut s = String::from("");
s = ToOwned::to_owned(&format!("{} {}", "hello", "world"));
}
struct FakeToOwned;
impl FakeToOwned {
/// This looks just like `ToOwned::to_owned`

View file

@ -62,64 +62,88 @@ LL | *mut_thing = (ref_thing + ref_thing).clone();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `mut_thing.clone_from(ref_thing + ref_thing)`
error: assigning the result of `Clone::clone()` may be inefficient
--> tests/ui/assigning_clones.rs:68:9
--> tests/ui/assigning_clones.rs:67:5
|
LL | s = format!("{} {}", "hello", "world").clone();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `s.clone_from(&format!("{} {}", "hello", "world"))`
error: assigning the result of `Clone::clone()` may be inefficient
--> tests/ui/assigning_clones.rs:72:5
|
LL | s = Clone::clone(&format!("{} {}", "hello", "world"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `Clone::clone_from(&mut s, &format!("{} {}", "hello", "world"))`
error: assigning the result of `Clone::clone()` may be inefficient
--> tests/ui/assigning_clones.rs:78:9
|
LL | a = b.clone();
| ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
error: assigning the result of `Clone::clone()` may be inefficient
--> tests/ui/assigning_clones.rs:133:5
--> tests/ui/assigning_clones.rs:149:5
|
LL | a = b.clone();
| ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
error: assigning the result of `Clone::clone()` may be inefficient
--> tests/ui/assigning_clones.rs:140:5
--> tests/ui/assigning_clones.rs:156:5
|
LL | a = b.clone();
| ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:141:5
--> tests/ui/assigning_clones.rs:157:5
|
LL | a = c.to_owned();
| ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `c.clone_into(&mut a)`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:171:5
--> tests/ui/assigning_clones.rs:187:5
|
LL | *mut_string = ref_str.to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:175:5
--> tests/ui/assigning_clones.rs:191:5
|
LL | mut_string = ref_str.to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:196:5
--> tests/ui/assigning_clones.rs:212:5
|
LL | **mut_box_string = ref_str.to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:200:5
--> tests/ui/assigning_clones.rs:216:5
|
LL | **mut_box_string = ref_str.to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:204:5
--> tests/ui/assigning_clones.rs:220:5
|
LL | *mut_thing = ToOwned::to_owned(ref_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:208:5
--> tests/ui/assigning_clones.rs:224:5
|
LL | mut_thing = ToOwned::to_owned(ref_str);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)`
error: aborting due to 20 previous errors
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:229:5
|
LL | s = format!("{} {}", "hello", "world").to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `format!("{} {}", "hello", "world").clone_into(&mut s)`
error: assigning the result of `ToOwned::to_owned()` may be inefficient
--> tests/ui/assigning_clones.rs:234:5
|
LL | s = ToOwned::to_owned(&format!("{} {}", "hello", "world"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(&format!("{} {}", "hello", "world"), &mut s)`
error: aborting due to 24 previous errors

View file

@ -0,0 +1,47 @@
#![warn(clippy::doc_lazy_continuation)]
/// > blockquote with
/// > lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn first() {}
/// > blockquote with no
/// > lazy continuation
fn first_nowarn() {}
/// > blockquote with no
///
/// lazy continuation
fn two_nowarn() {}
/// > nest here
/// >
/// > > nest here
/// > > lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn two() {}
/// > nest here
/// >
/// > > nest here
/// > > lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn three() {}
/// > * > nest here
/// > > lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn four() {}
/// > * > nest here
/// > > lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn four_point_1() {}
/// * > nest here lazy continuation
fn five() {}
/// 1. > nest here
/// > lazy continuation (this results in strange indentation, but still works)
//~^ ERROR: doc quote missing `>` marker
fn six() {}

View file

@ -0,0 +1,47 @@
#![warn(clippy::doc_lazy_continuation)]
/// > blockquote with
/// lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn first() {}
/// > blockquote with no
/// > lazy continuation
fn first_nowarn() {}
/// > blockquote with no
///
/// lazy continuation
fn two_nowarn() {}
/// > nest here
/// >
/// > > nest here
/// > lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn two() {}
/// > nest here
/// >
/// > > nest here
/// lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn three() {}
/// > * > nest here
/// lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn four() {}
/// > * > nest here
/// lazy continuation
//~^ ERROR: doc quote missing `>` marker
fn four_point_1() {}
/// * > nest here lazy continuation
fn five() {}
/// 1. > nest here
/// lazy continuation (this results in strange indentation, but still works)
//~^ ERROR: doc quote missing `>` marker
fn six() {}

View file

@ -0,0 +1,76 @@
error: doc quote missing `>` marker
--> tests/ui/doc/doc_lazy_blockquote.rs:4:5
|
LL | /// lazy continuation
| ^
|
= help: if this not intended to be a quote at all, escape it with `\>`
= note: `-D clippy::doc-lazy-continuation` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::doc_lazy_continuation)]`
help: add markers to start of line
|
LL | /// > lazy continuation
| +
error: doc quote missing `>` marker
--> tests/ui/doc/doc_lazy_blockquote.rs:20:5
|
LL | /// > lazy continuation
| ^^
|
= help: if this not intended to be a quote at all, escape it with `\>`
help: add markers to start of line
|
LL | /// > > lazy continuation
| +
error: doc quote missing `>` marker
--> tests/ui/doc/doc_lazy_blockquote.rs:27:5
|
LL | /// lazy continuation
| ^
|
= help: if this not intended to be a quote at all, escape it with `\>`
help: add markers to start of line
|
LL | /// > > lazy continuation
| +++
error: doc quote missing `>` marker
--> tests/ui/doc/doc_lazy_blockquote.rs:32:5
|
LL | /// lazy continuation
| ^
|
= help: if this not intended to be a quote at all, escape it with `\>`
help: add markers to start of line
|
LL | /// > > lazy continuation
| +++++++
error: doc quote missing `>` marker
--> tests/ui/doc/doc_lazy_blockquote.rs:37:5
|
LL | /// lazy continuation
| ^
|
= help: if this not intended to be a quote at all, escape it with `\>`
help: add markers to start of line
|
LL | /// > > lazy continuation
| +++++
error: doc quote missing `>` marker
--> tests/ui/doc/doc_lazy_blockquote.rs:45:5
|
LL | /// lazy continuation (this results in strange indentation, but still works)
| ^
|
= help: if this not intended to be a quote at all, escape it with `\>`
help: add markers to start of line
|
LL | /// > lazy continuation (this results in strange indentation, but still works)
| +
error: aborting due to 6 previous errors

View file

@ -0,0 +1,77 @@
#![warn(clippy::doc_lazy_continuation)]
/// 1. nest here
/// lazy continuation
//~^ ERROR: doc list item missing indentation
fn one() {}
/// 1. first line
/// lazy list continuations don't make warnings with this lint
//~^ ERROR: doc list item missing indentation
/// because they don't have the
//~^ ERROR: doc list item missing indentation
fn two() {}
/// - nest here
/// lazy continuation
//~^ ERROR: doc list item missing indentation
fn three() {}
/// - first line
/// lazy list continuations don't make warnings with this lint
//~^ ERROR: doc list item missing indentation
/// because they don't have the
//~^ ERROR: doc list item missing indentation
fn four() {}
/// - nest here
/// lazy continuation
//~^ ERROR: doc list item missing indentation
fn five() {}
/// - - first line
/// this will warn on the lazy continuation
//~^ ERROR: doc list item missing indentation
/// and so should this
//~^ ERROR: doc list item missing indentation
fn six() {}
/// - - first line
///
/// this is not a lazy continuation
fn seven() {}
#[rustfmt::skip]
// https://github.com/rust-lang/rust-clippy/pull/12770#issuecomment-2118601768
/// Returns a list of ProtocolDescriptors from a Serde JSON input.
///
/// Defined Protocol Identifiers for the Protocol Descriptor
/// We intentionally omit deprecated profile identifiers.
/// From Bluetooth Assigned Numbers:
/// https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
///
/// # Arguments
/// * `protocol_descriptors`: A Json Representation of the ProtocolDescriptors
/// to set up. Example:
/// 'protocol_descriptors': [
//~^ ERROR: doc list item missing indentation
/// {
/// 'protocol': 25, # u64 Representation of ProtocolIdentifier::AVDTP
/// 'params': [
/// {
/// 'data': 0x0103 # to indicate 1.3
/// },
/// {
/// 'data': 0x0105 # to indicate 1.5
/// }
/// ]
/// },
/// {
/// 'protocol': 1, # u64 Representation of ProtocolIdentifier::SDP
/// 'params': [{
/// 'data': 0x0019
/// }]
/// }
/// ]
//~^ ERROR: doc list item missing indentation
fn eight() {}

View file

@ -0,0 +1,77 @@
#![warn(clippy::doc_lazy_continuation)]
/// 1. nest here
/// lazy continuation
//~^ ERROR: doc list item missing indentation
fn one() {}
/// 1. first line
/// lazy list continuations don't make warnings with this lint
//~^ ERROR: doc list item missing indentation
/// because they don't have the
//~^ ERROR: doc list item missing indentation
fn two() {}
/// - nest here
/// lazy continuation
//~^ ERROR: doc list item missing indentation
fn three() {}
/// - first line
/// lazy list continuations don't make warnings with this lint
//~^ ERROR: doc list item missing indentation
/// because they don't have the
//~^ ERROR: doc list item missing indentation
fn four() {}
/// - nest here
/// lazy continuation
//~^ ERROR: doc list item missing indentation
fn five() {}
/// - - first line
/// this will warn on the lazy continuation
//~^ ERROR: doc list item missing indentation
/// and so should this
//~^ ERROR: doc list item missing indentation
fn six() {}
/// - - first line
///
/// this is not a lazy continuation
fn seven() {}
#[rustfmt::skip]
// https://github.com/rust-lang/rust-clippy/pull/12770#issuecomment-2118601768
/// Returns a list of ProtocolDescriptors from a Serde JSON input.
///
/// Defined Protocol Identifiers for the Protocol Descriptor
/// We intentionally omit deprecated profile identifiers.
/// From Bluetooth Assigned Numbers:
/// https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
///
/// # Arguments
/// * `protocol_descriptors`: A Json Representation of the ProtocolDescriptors
/// to set up. Example:
/// 'protocol_descriptors': [
//~^ ERROR: doc list item missing indentation
/// {
/// 'protocol': 25, # u64 Representation of ProtocolIdentifier::AVDTP
/// 'params': [
/// {
/// 'data': 0x0103 # to indicate 1.3
/// },
/// {
/// 'data': 0x0105 # to indicate 1.5
/// }
/// ]
/// },
/// {
/// 'protocol': 1, # u64 Representation of ProtocolIdentifier::SDP
/// 'params': [{
/// 'data': 0x0019
/// }]
/// }
/// ]
//~^ ERROR: doc list item missing indentation
fn eight() {}

View file

@ -0,0 +1,136 @@
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:4:5
|
LL | /// lazy continuation
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
= note: `-D clippy::doc-lazy-continuation` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::doc_lazy_continuation)]`
help: indent this line
|
LL | /// lazy continuation
| +++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:9:5
|
LL | /// lazy list continuations don't make warnings with this lint
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// lazy list continuations don't make warnings with this lint
| +++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:11:5
|
LL | /// because they don't have the
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// because they don't have the
| +++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:16:5
|
LL | /// lazy continuation
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// lazy continuation
| ++++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:21:5
|
LL | /// lazy list continuations don't make warnings with this lint
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// lazy list continuations don't make warnings with this lint
| ++++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:23:5
|
LL | /// because they don't have the
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// because they don't have the
| ++++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:28:5
|
LL | /// lazy continuation
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// lazy continuation
| ++++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:33:5
|
LL | /// this will warn on the lazy continuation
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// this will warn on the lazy continuation
| ++++++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:35:5
|
LL | /// and so should this
| ^^^^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// and so should this
| ++
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:56:5
|
LL | /// 'protocol_descriptors': [
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// 'protocol_descriptors': [
| +
error: doc list item missing indentation
--> tests/ui/doc/doc_lazy_list.rs:75:5
|
LL | /// ]
| ^
|
= help: if this is supposed to be its own paragraph, add a blank line
help: indent this line
|
LL | /// ]
| +
error: aborting due to 11 previous errors

View file

@ -1,5 +1,5 @@
//@aux-build:proc_macro_attr.rs
#![feature(rustc_attrs)]
#![warn(clippy::duplicated_attributes)]
#![cfg(any(unix, windows))]
#![allow(dead_code)]
@ -20,6 +20,10 @@ fn foo() {}
#[cfg(unix)] // cfgs are not handled
fn bar() {}
// No warning:
#[rustc_on_unimplemented(on(_Self = "&str", label = "`a"), on(_Self = "alloc::string::String", label = "a"))]
trait Abc {}
#[proc_macro_attr::duplicated_attr()] // Should not warn!
fn babar() {}

View file

@ -1,3 +1,4 @@
#![feature(const_int_from_str)]
#![warn(clippy::from_str_radix_10)]
mod some_mod {
@ -59,3 +60,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
fn issue_12732() {
const A: Result<u32, std::num::ParseIntError> = u32::from_str_radix("123", 10);
const B: () = {
let _ = u32::from_str_radix("123", 10);
};
const fn foo() {
let _ = u32::from_str_radix("123", 10);
}
}

View file

@ -1,3 +1,4 @@
#![feature(const_int_from_str)]
#![warn(clippy::from_str_radix_10)]
mod some_mod {
@ -59,3 +60,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
fn issue_12732() {
const A: Result<u32, std::num::ParseIntError> = u32::from_str_radix("123", 10);
const B: () = {
let _ = u32::from_str_radix("123", 10);
};
const fn foo() {
let _ = u32::from_str_radix("123", 10);
}
}

View file

@ -1,5 +1,5 @@
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:28:5
--> tests/ui/from_str_radix_10.rs:29:5
|
LL | u32::from_str_radix("30", 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"30".parse::<u32>()`
@ -8,43 +8,43 @@ LL | u32::from_str_radix("30", 10)?;
= help: to override `-D warnings` add `#[allow(clippy::from_str_radix_10)]`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:31:5
--> tests/ui/from_str_radix_10.rs:32:5
|
LL | i64::from_str_radix("24", 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"24".parse::<i64>()`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:33:5
--> tests/ui/from_str_radix_10.rs:34:5
|
LL | isize::from_str_radix("100", 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"100".parse::<isize>()`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:35:5
--> tests/ui/from_str_radix_10.rs:36:5
|
LL | u8::from_str_radix("7", 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"7".parse::<u8>()`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:37:5
--> tests/ui/from_str_radix_10.rs:38:5
|
LL | u16::from_str_radix(&("10".to_owned() + "5"), 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("10".to_owned() + "5").parse::<u16>()`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:39:5
--> tests/ui/from_str_radix_10.rs:40:5
|
LL | i128::from_str_radix(Test + Test, 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(Test + Test).parse::<i128>()`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:43:5
--> tests/ui/from_str_radix_10.rs:44:5
|
LL | i32::from_str_radix(string, 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `string.parse::<i32>()`
error: this call to `from_str_radix` can be replaced with a call to `str::parse`
--> tests/ui/from_str_radix_10.rs:47:5
--> tests/ui/from_str_radix_10.rs:48:5
|
LL | i32::from_str_radix(&stringier, 10)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `stringier.parse::<i32>()`

View file

@ -2,7 +2,7 @@ error: this match arm has an identical body to the `_` wildcard arm
--> tests/ui/match_same_arms.rs:12:9
|
LL | Abc::A => 0,
| ^^^^^^^^^^^ help: try removing the arm
| ^^^^^^^^^^^^^ help: try removing the arm
|
= help: or try changing either arm body
note: `_` wildcard arm here
@ -17,106 +17,114 @@ error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:18:9
|
LL | (1, .., 3) => 42,
| ----------^^^^^^
| |
| help: try merging the arm patterns: `(1, .., 3) | (.., 3)`
| ^^^^^^^^^^^^^^^^
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:19:9
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | (1, .., 3) | (.., 3) => 42,
| ~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - (.., 3) => 42,
|
LL | (.., 3) => 42,
| ^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:25:9
|
LL | 51 => 1,
| --^^^^^
| |
| help: try merging the arm patterns: `51 | 42`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:24:9
|
LL | 42 => 1,
| ^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 51 | 42 => 1,
| ~~~~~~~
help: and remove this obsolete arm
|
LL - 42 => 1,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:26:9
|
LL | 41 => 2,
| --^^^^^
| |
| help: try merging the arm patterns: `41 | 52`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:27:9
|
LL | 52 => 2,
| ^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 41 | 52 => 2,
| ~~~~~~~
help: and remove this obsolete arm
|
LL - 52 => 2,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:33:9
|
LL | 2 => 2,
| -^^^^^
| |
| help: try merging the arm patterns: `2 | 1`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:32:9
|
LL | 1 => 2,
| ^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 2 | 1 => 2,
| ~~~~~
help: and remove this obsolete arm
|
LL - 1 => 2,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:35:9
|
LL | 3 => 2,
| -^^^^^
| |
| help: try merging the arm patterns: `3 | 1`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:32:9
|
LL | 1 => 2,
| ^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 3 | 1 => 2,
| ~~~~~
help: and remove this obsolete arm
|
LL - 1 => 2,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:33:9
|
LL | 2 => 2,
| -^^^^^
| |
| help: try merging the arm patterns: `2 | 3`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:35:9
|
LL | 3 => 2,
| ^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 2 | 3 => 2,
| ~~~~~
help: and remove this obsolete arm
|
LL - 3 => 2,
LL +
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms.rs:52:17
|
LL | CommandInfo::External { name, .. } => name.to_string(),
| ----------------------------------^^^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `CommandInfo::External { name, .. } | CommandInfo::BuiltIn { name, .. }`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms.rs:51:17
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | CommandInfo::External { name, .. } | CommandInfo::BuiltIn { name, .. } => name.to_string(),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - CommandInfo::BuiltIn { name, .. } => name.to_string(),
|
LL | CommandInfo::BuiltIn { name, .. } => name.to_string(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 8 previous errors

View file

@ -0,0 +1,241 @@
#![warn(clippy::match_same_arms)]
#![allow(
clippy::disallowed_names,
clippy::diverging_sub_expression,
clippy::uninlined_format_args,
clippy::match_single_binding,
clippy::match_like_matches_macro
)]
fn bar<T>(_: T) {}
fn foo() -> bool {
unimplemented!()
}
fn match_same_arms() {
let _ = match 42 {
_ => {
foo();
let mut a = 42 + [23].len() as i32;
if true {
a += 7;
}
a = -31 - a;
a
},
};
//~^^^^^^^^^^^^^^^^^^^ ERROR: this match arm has an identical body to the `_` wildcard arm
let _ = match 42 {
51 | 42 => foo(), //~ ERROR: this match arm has an identical body to another arm
_ => true,
};
let _ = match Some(42) {
None | Some(_) => 24, //~ ERROR: this match arm has an identical body to another arm
};
let _ = match Some(42) {
Some(foo) => 24,
None => 24,
};
let _ = match Some(42) {
Some(42) => 24,
Some(a) => 24, // bindings are different
None => 0,
};
let _ = match Some(42) {
Some(a) if a > 0 => 24,
Some(a) => 24, // one arm has a guard
None => 0,
};
match (Some(42), Some(42)) {
(None, Some(a)) | (Some(a), None) => bar(a), //~ ERROR: this match arm has an identical body to another arm
_ => (),
}
// No warning because guards are different
let _ = match Some(42) {
Some(a) if a == 42 => a,
Some(a) if a == 24 => a,
Some(_) => 24,
None => 0,
};
let _ = match (Some(42), Some(42)) {
(None, Some(a)) | (Some(a), None) if a == 42 => a, //~ ERROR: this match arm has an identical body to another arm
_ => 0,
};
match (Some(42), Some(42)) {
(Some(a), ..) | (.., Some(a)) => bar(a), //~ ERROR: this match arm has an identical body to another arm
_ => (),
}
let _ = match Some(()) {
Some(()) => 0.0,
None => -0.0,
};
match (Some(42), Some("")) {
(Some(a), None) => bar(a),
(None, Some(a)) => bar(a), // bindings have different types
_ => (),
}
let x: Result<i32, &str> = Ok(3);
// No warning because of the guard.
match x {
Ok(x) if x * x == 64 => println!("ok"),
Ok(_) => println!("ok"),
Err(_) => println!("err"),
}
// This used to be a false positive; see issue #1996.
match x {
Ok(3) => println!("ok"),
Ok(x) if x * x == 64 => println!("ok 64"),
Ok(_) => println!("ok"),
Err(_) => println!("err"),
}
match (x, Some(1i32)) {
(Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x), //~ ERROR: this match arm has an identical body to another arm
_ => println!("err"),
}
// No warning; different types for `x`.
match (x, Some(1.0f64)) {
(Ok(x), Some(_)) => println!("ok {}", x),
(Ok(_), Some(x)) => println!("ok {}", x),
_ => println!("err"),
}
// False negative #2251.
match x {
Ok(_tmp) => println!("ok"),
Ok(_) | Ok(3) => println!("ok"), //~ ERROR: this match arm has an identical body to another arm
Err(_) => {
unreachable!();
},
}
// False positive #1390
macro_rules! empty {
($e:expr) => {};
}
match 0 {
0 => {
empty!(0);
},
1 => {
empty!(1);
},
x => {
empty!(x);
},
};
// still lint if the tokens are the same
match 0 {
1 | 0 => {
empty!(0);
},
x => {
empty!(x);
},
}
//~^^^^^^^ ERROR: this match arm has an identical body to another arm
match_expr_like_matches_macro_priority();
}
fn match_expr_like_matches_macro_priority() {
enum E {
A,
B,
C,
}
let x = E::A;
let _ans = match x {
E::A => false,
E::B => false,
_ => true,
};
}
fn main() {
let _ = match Some(0) {
Some(0) => 0,
Some(1) => 1,
#[cfg(feature = "foo")]
Some(2) => 2,
_ => 1,
};
enum Foo {
X(u32),
Y(u32),
Z(u32),
}
// Don't lint. `Foo::X(0)` and `Foo::Z(_)` overlap with the arm in between.
let _ = match Foo::X(0) {
Foo::X(0) => 1,
Foo::X(_) | Foo::Y(_) | Foo::Z(0) => 2,
Foo::Z(_) => 1,
_ => 0,
};
// Suggest moving `Foo::Z(_)` up.
let _ = match Foo::X(0) {
Foo::X(0) | Foo::Z(_) => 1, //~ ERROR: this match arm has an identical body to another arm
Foo::X(_) | Foo::Y(_) => 2,
_ => 0,
};
// Suggest moving `Foo::X(0)` down.
let _ = match Foo::X(0) {
Foo::Y(_) | Foo::Z(0) => 2,
Foo::Z(_) | Foo::X(0) => 1, //~ ERROR: this match arm has an identical body to another arm
_ => 0,
};
// Don't lint.
let _ = match 0 {
-2 => 1,
-5..=50 => 2,
-150..=88 => 1,
_ => 3,
};
struct Bar {
x: u32,
y: u32,
z: u32,
}
// Lint.
let _ = match None {
Some(Bar { y: 10, z: 0, .. }) => 2,
None => 50,
Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1, //~ ERROR: this match arm has an identical body to another arm
_ => 200,
};
let _ = match 0 {
0 => todo!(),
1 => todo!(),
2 => core::convert::identity::<u32>(todo!()),
3 => core::convert::identity::<u32>(todo!()),
_ => 5,
};
let _ = match 0 {
1 | 0 => cfg!(not_enable),
_ => false,
};
}

View file

@ -2,9 +2,10 @@
#![allow(
clippy::disallowed_names,
clippy::diverging_sub_expression,
clippy::uninlined_format_args
clippy::uninlined_format_args,
clippy::match_single_binding,
clippy::match_like_matches_macro
)]
//@no-rustfix
fn bar<T>(_: T) {}
fn foo() -> bool {
unimplemented!()

View file

@ -1,18 +1,18 @@
error: this match arm has an identical body to the `_` wildcard arm
--> tests/ui/match_same_arms2.rs:15:9
--> tests/ui/match_same_arms2.rs:16:9
|
LL | / 42 => {
LL | | foo();
LL | | let mut a = 42 + [23].len() as i32;
LL | | if true {
... |
LL | | a
LL | | },
| |_________^ help: try removing the arm
LL | | _ => {
| |________^ help: try removing the arm
|
= help: or try changing either arm body
note: `_` wildcard arm here
--> tests/ui/match_same_arms2.rs:24:9
--> tests/ui/match_same_arms2.rs:25:9
|
LL | / _ => {
LL | | foo();
@ -26,203 +26,200 @@ LL | | },
= help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]`
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:38:9
--> tests/ui/match_same_arms2.rs:39:9
|
LL | 51 => foo(),
| --^^^^^^^^^
| |
| help: try merging the arm patterns: `51 | 42`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:37:9
|
LL | 42 => foo(),
| ^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 51 | 42 => foo(),
| ~~~~~~~
help: and remove this obsolete arm
|
LL - 42 => foo(),
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:44:9
--> tests/ui/match_same_arms2.rs:45:9
|
LL | None => 24,
| ----^^^^^^
| |
| help: try merging the arm patterns: `None | Some(_)`
| ^^^^^^^^^^
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:43:9
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | None | Some(_) => 24,
| ~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - Some(_) => 24,
|
LL | Some(_) => 24,
| ^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:66:9
--> tests/ui/match_same_arms2.rs:67:9
|
LL | (None, Some(a)) => bar(a),
| ---------------^^^^^^^^^^
| |
| help: try merging the arm patterns: `(None, Some(a)) | (Some(a), None)`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:65:9
|
LL | (Some(a), None) => bar(a),
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | (None, Some(a)) | (Some(a), None) => bar(a),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - (Some(a), None) => bar(a),
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:80:9
--> tests/ui/match_same_arms2.rs:81:9
|
LL | (None, Some(a)) if a == 42 => a,
| ---------------^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `(None, Some(a)) | (Some(a), None)`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:79:9
|
LL | (Some(a), None) if a == 42 => a,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | (None, Some(a)) | (Some(a), None) if a == 42 => a,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - (Some(a), None) if a == 42 => a,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:85:9
|
LL | (Some(a), ..) => bar(a),
| -------------^^^^^^^^^^
| |
| help: try merging the arm patterns: `(Some(a), ..) | (.., Some(a))`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:86:9
|
LL | (.., Some(a)) => bar(a),
LL | (Some(a), ..) => bar(a),
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | (Some(a), ..) | (.., Some(a)) => bar(a),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - (.., Some(a)) => bar(a),
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:119:9
|
LL | (Ok(x), Some(_)) => println!("ok {}", x),
| ----------------^^^^^^^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `(Ok(x), Some(_)) | (Ok(_), Some(x))`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:120:9
|
LL | (Ok(_), Some(x)) => println!("ok {}", x),
LL | (Ok(x), Some(_)) => println!("ok {}", x),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | (Ok(x), Some(_)) | (Ok(_), Some(x)) => println!("ok {}", x),
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - (Ok(_), Some(x)) => println!("ok {}", x),
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:135:9
--> tests/ui/match_same_arms2.rs:136:9
|
LL | Ok(_) => println!("ok"),
| -----^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `Ok(_) | Ok(3)`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:134:9
|
LL | Ok(3) => println!("ok"),
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | Ok(_) | Ok(3) => println!("ok"),
| ~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - Ok(3) => println!("ok"),
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:162:9
--> tests/ui/match_same_arms2.rs:163:9
|
LL | 1 => {
| ^ help: try merging the arm patterns: `1 | 0`
| _________|
| |
LL | / 1 => {
LL | | empty!(0);
LL | | },
| |_________^
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:159:9
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | / 0 => {
LL | | empty!(0);
LL | | },
| |_________^
error: match expression looks like `matches!` macro
--> tests/ui/match_same_arms2.rs:181:16
LL | 1 | 0 => {
| ~~~~~
help: and remove this obsolete arm
|
LL | let _ans = match x {
| ________________^
LL | | E::A => false,
LL | | E::B => false,
LL | | _ => true,
LL | | };
| |_____^ help: try: `!matches!(x, E::A | E::B)`
LL - 0 => {
LL - empty!(0);
LL - },
|
= note: `-D clippy::match-like-matches-macro` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::match_like_matches_macro)]`
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:213:9
|
LL | Foo::X(0) => 1,
| ---------^^^^^
| |
| help: try merging the arm patterns: `Foo::X(0) | Foo::Z(_)`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:215:9
|
LL | Foo::Z(_) => 1,
| ^^^^^^^^^^^^^^
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:223:9
|
LL | Foo::Z(_) => 1,
| ---------^^^^^
| |
| help: try merging the arm patterns: `Foo::Z(_) | Foo::X(0)`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:221:9
--> tests/ui/match_same_arms2.rs:214:9
|
LL | Foo::X(0) => 1,
| ^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | Foo::X(0) | Foo::Z(_) => 1,
| ~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - Foo::Z(_) => 1,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:246:9
--> tests/ui/match_same_arms2.rs:224:9
|
LL | Foo::Z(_) => 1,
| ^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | Foo::Z(_) | Foo::X(0) => 1,
| ~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - Foo::X(0) => 1,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:247:9
|
LL | Some(Bar { y: 0, x: 5, .. }) => 1,
| ----------------------------^^^^^
| |
| help: try merging the arm patterns: `Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. })`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:243:9
|
LL | Some(Bar { x: 0, y: 5, .. }) => 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | Some(Bar { y: 0, x: 5, .. }) | Some(Bar { x: 0, y: 5, .. }) => 1,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
|
LL - Some(Bar { x: 0, y: 5, .. }) => 1,
|
error: this match arm has an identical body to another arm
--> tests/ui/match_same_arms2.rs:260:9
--> tests/ui/match_same_arms2.rs:261:9
|
LL | 1 => cfg!(not_enable),
| -^^^^^^^^^^^^^^^^^^^^
| |
| help: try merging the arm patterns: `1 | 0`
|
= help: or try changing either arm body
note: other arm here
--> tests/ui/match_same_arms2.rs:259:9
|
LL | 0 => cfg!(not_enable),
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: try changing either arm body
help: or try merging the arm patterns
|
LL | 1 | 0 => cfg!(not_enable),
| ~~~~~
help: and remove this obsolete arm
|
LL - 0 => cfg!(not_enable),
|
error: aborting due to 14 previous errors
error: aborting due to 13 previous errors

View file

@ -0,0 +1,61 @@
#![feature(non_exhaustive_omitted_patterns_lint)]
#![warn(clippy::match_same_arms)]
#![no_main]
use std::sync::atomic::Ordering; // #[non_exhaustive] enum
fn repeat() -> ! {
panic!()
}
pub fn f(x: Ordering) {
#[deny(non_exhaustive_omitted_patterns)]
match x {
Ordering::Relaxed => println!("relaxed"),
Ordering::Release => println!("release"),
Ordering::Acquire => println!("acquire"),
Ordering::AcqRel | Ordering::SeqCst => repeat(),
_ => repeat(),
}
}
mod f {
#![deny(non_exhaustive_omitted_patterns)]
use super::*;
pub fn f(x: Ordering) {
match x {
Ordering::Relaxed => println!("relaxed"),
Ordering::Release => println!("release"),
Ordering::Acquire => println!("acquire"),
Ordering::AcqRel | Ordering::SeqCst => repeat(),
_ => repeat(),
}
}
}
// Below should still lint
pub fn g(x: Ordering) {
match x {
Ordering::Relaxed => println!("relaxed"),
Ordering::Release => println!("release"),
Ordering::Acquire => println!("acquire"),
//~^ ERROR: this match arm has an identical body to the `_` wildcard arm
_ => repeat(),
}
}
mod g {
use super::*;
pub fn g(x: Ordering) {
match x {
Ordering::Relaxed => println!("relaxed"),
Ordering::Release => println!("release"),
Ordering::Acquire => println!("acquire"),
//~^ ERROR: this match arm has an identical body to the `_` wildcard arm
_ => repeat(),
}
}
}

View file

@ -1,7 +1,6 @@
#![feature(non_exhaustive_omitted_patterns_lint)]
#![warn(clippy::match_same_arms)]
#![no_main]
//@no-rustfix
use std::sync::atomic::Ordering; // #[non_exhaustive] enum
fn repeat() -> ! {

View file

@ -1,12 +1,13 @@
error: this match arm has an identical body to the `_` wildcard arm
--> tests/ui/match_same_arms_non_exhaustive.rs:45:9
--> tests/ui/match_same_arms_non_exhaustive.rs:44:9
|
LL | Ordering::AcqRel | Ordering::SeqCst => repeat(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm
LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(),
LL | |
| |________^ help: try removing the arm
|
= help: or try changing either arm body
note: `_` wildcard arm here
--> tests/ui/match_same_arms_non_exhaustive.rs:47:9
--> tests/ui/match_same_arms_non_exhaustive.rs:46:9
|
LL | _ => repeat(),
| ^^^^^^^^^^^^^
@ -14,14 +15,15 @@ LL | _ => repeat(),
= help: to override `-D warnings` add `#[allow(clippy::match_same_arms)]`
error: this match arm has an identical body to the `_` wildcard arm
--> tests/ui/match_same_arms_non_exhaustive.rs:59:13
--> tests/ui/match_same_arms_non_exhaustive.rs:58:13
|
LL | Ordering::AcqRel | Ordering::SeqCst => repeat(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the arm
LL | / Ordering::AcqRel | Ordering::SeqCst => repeat(),
LL | |
| |____________^ help: try removing the arm
|
= help: or try changing either arm body
note: `_` wildcard arm here
--> tests/ui/match_same_arms_non_exhaustive.rs:61:13
--> tests/ui/match_same_arms_non_exhaustive.rs:60:13
|
LL | _ => repeat(),
| ^^^^^^^^^^^^^

View file

@ -161,7 +161,23 @@ union U {
f: u32,
}
// Do not lint because accessing union fields from const functions is unstable
// Do not lint because accessing union fields from const functions is unstable in 1.55
#[clippy::msrv = "1.55"]
fn h(u: U) -> u32 {
unsafe { u.f }
}
mod msrv {
struct Foo(*const u8, *mut u8);
impl Foo {
#[clippy::msrv = "1.57"]
fn deref_ptr_cannot_be_const(self) -> usize {
unsafe { *self.0 as usize }
}
#[clippy::msrv = "1.58"]
fn deref_mut_ptr_cannot_be_const(self) -> usize {
unsafe { *self.1 as usize }
}
}
}

View file

@ -113,3 +113,31 @@ impl const Drop for D {
// Lint this, since it can be dropped in const contexts
// FIXME(effects)
fn d(this: D) {}
mod msrv {
struct Foo(*const u8, &'static u8);
impl Foo {
#[clippy::msrv = "1.58"]
fn deref_ptr_can_be_const(self) -> usize {
//~^ ERROR: this could be a `const fn`
unsafe { *self.0 as usize }
}
fn deref_copied_val(self) -> usize {
//~^ ERROR: this could be a `const fn`
*self.1 as usize
}
}
union Bar {
val: u8,
}
#[clippy::msrv = "1.56"]
fn union_access_can_be_const() {
//~^ ERROR: this could be a `const fn`
let bar = Bar { val: 1 };
let _ = unsafe { bar.val };
}
}

View file

@ -102,5 +102,33 @@ LL | | 46
LL | | }
| |_^
error: aborting due to 11 previous errors
error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:122:9
|
LL | / fn deref_ptr_can_be_const(self) -> usize {
LL | |
LL | | unsafe { *self.0 as usize }
LL | | }
| |_________^
error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:127:9
|
LL | / fn deref_copied_val(self) -> usize {
LL | |
LL | | *self.1 as usize
LL | | }
| |_________^
error: this could be a `const fn`
--> tests/ui/missing_const_for_fn/could_be_const.rs:138:5
|
LL | / fn union_access_can_be_const() {
LL | |
LL | | let bar = Bar { val: 1 };
LL | | let _ = unsafe { bar.val };
LL | | }
| |_____^
error: aborting due to 14 previous errors

View file

@ -191,3 +191,11 @@ fn from_declared_macro_should_lint_at_macrosite() {
// Not here.
some_macro_that_panics!()
}
pub fn issue_12760<const N: usize>() {
const {
if N == 0 {
panic!();
}
}
}

View file

@ -141,8 +141,8 @@ fn main() {
let f = |arg| {
let loc = "loc".to_owned();
let _ = std::fs::write("x", &env); // Don't lint. In environment
let _ = std::fs::write("x", arg);
let _ = std::fs::write("x", loc);
let _ = std::fs::write("x", &arg);
let _ = std::fs::write("x", &loc);
};
let _ = std::fs::write("x", &env); // Don't lint. Borrowed by `f`
f(arg);
@ -158,13 +158,13 @@ fn main() {
fn f(_: impl Debug) {}
let x = X;
f(&x); // Don't lint. Has significant drop
f(&x); // Don't lint, not copy, passed by a reference to a variable
}
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
f(x);
f(&x);
}
{
fn f(_: impl AsRef<str>) {}
@ -299,4 +299,38 @@ fn main() {
check_str(&owner.0); // Don't lint. `owner` can't be partially moved because it impl Drop
}
}
{
#[derive(Debug)]
struct X(Vec<u8>);
fn f(_: impl Debug) {}
let x = X(vec![]);
f(&x); // Don't lint, makes x unavailable later
}
{
#[derive(Debug)]
struct X;
impl Drop for X {
fn drop(&mut self) {}
}
fn f(_: impl Debug) {}
#[derive(Debug)]
struct Y(X);
let y = Y(X);
f(&y); // Don't lint. Not copy, passed by a reference to value
}
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
f(&x); // Don't lint, not a copy, makes it unavailable later
f(String::new()); // Lint, makes no difference
let y = "".to_owned();
f(&y); // Don't lint
f("".to_owned()); // Lint
}
}

View file

@ -158,7 +158,7 @@ fn main() {
fn f(_: impl Debug) {}
let x = X;
f(&x); // Don't lint. Has significant drop
f(&x); // Don't lint, not copy, passed by a reference to a variable
}
{
fn f(_: impl AsRef<str>) {}
@ -299,4 +299,38 @@ fn main() {
check_str(&owner.0); // Don't lint. `owner` can't be partially moved because it impl Drop
}
}
{
#[derive(Debug)]
struct X(Vec<u8>);
fn f(_: impl Debug) {}
let x = X(vec![]);
f(&x); // Don't lint, makes x unavailable later
}
{
#[derive(Debug)]
struct X;
impl Drop for X {
fn drop(&mut self) {}
}
fn f(_: impl Debug) {}
#[derive(Debug)]
struct Y(X);
let y = Y(X);
f(&y); // Don't lint. Not copy, passed by a reference to value
}
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
f(&x); // Don't lint, not a copy, makes it unavailable later
f(&String::new()); // Lint, makes no difference
let y = "".to_owned();
f(&y); // Don't lint
f(&"".to_owned()); // Lint
}
}

View file

@ -49,29 +49,23 @@ error: the borrowed expression implements the required traits
LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
--> tests/ui/needless_borrows_for_generic_args.rs:144:41
|
LL | let _ = std::fs::write("x", &arg);
| ^^^^ help: change this to: `arg`
error: the borrowed expression implements the required traits
--> tests/ui/needless_borrows_for_generic_args.rs:145:41
|
LL | let _ = std::fs::write("x", &loc);
| ^^^^ help: change this to: `loc`
error: the borrowed expression implements the required traits
--> tests/ui/needless_borrows_for_generic_args.rs:167:11
|
LL | f(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
--> tests/ui/needless_borrows_for_generic_args.rs:247:13
|
LL | foo(&a);
| ^^ help: change this to: `a`
error: aborting due to 12 previous errors
error: the borrowed expression implements the required traits
--> tests/ui/needless_borrows_for_generic_args.rs:331:11
|
LL | f(&String::new()); // Lint, makes no difference
| ^^^^^^^^^^^^^^ help: change this to: `String::new()`
error: the borrowed expression implements the required traits
--> tests/ui/needless_borrows_for_generic_args.rs:334:11
|
LL | f(&"".to_owned()); // Lint
| ^^^^^^^^^^^^^^ help: change this to: `"".to_owned()`
error: aborting due to 11 previous errors

View file

@ -8,10 +8,11 @@ LL | a = "zero";
|
= note: `-D clippy::needless-late-init` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_late_init)]`
help: declare `a` here
help: move the declaration `a` here
|
LL ~
LL ~ let a = "zero";
|
LL | let a = "zero";
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:30:5
@ -22,10 +23,12 @@ LL | let c;
LL | b = 1;
| ^^^^^ initialised here
|
help: declare `b` here
help: move the declaration `b` here
|
LL ~
LL | let c;
LL ~ let b = 1;
|
LL | let b = 1;
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:31:5
@ -36,10 +39,12 @@ LL | b = 1;
LL | c = 2;
| ^^^^^ initialised here
|
help: declare `c` here
help: move the declaration `c` here
|
LL ~
LL | b = 1;
LL ~ let c = 2;
|
LL | let c = 2;
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:35:5
@ -49,10 +54,11 @@ LL | let d: usize;
LL | d = 1;
| ^^^^^ initialised here
|
help: declare `d` here
help: move the declaration `d` here
|
LL ~
LL ~ let d: usize = 1;
|
LL | let d: usize = 1;
| ~~~~~~~~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:38:5
@ -62,10 +68,11 @@ LL | let e;
LL | e = format!("{}", d);
| ^^^^^^^^^^^^^^^^^^^^ initialised here
|
help: declare `e` here
help: move the declaration `e` here
|
LL ~
LL ~ let e = format!("{}", d);
|
LL | let e = format!("{}", d);
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:43:5
@ -73,20 +80,17 @@ error: unneeded late initialization
LL | let a;
| ^^^^^^
|
help: declare `a` here
|
LL | let a = match n {
| +++++++
help: remove the assignments from the `match` arms
help: move the declaration `a` here and remove the assignments from the `match` arms
|
LL ~
LL | let n = 1;
LL ~ let a = match n {
LL ~ 1 => "one",
LL | _ => {
LL ~ "two"
LL | },
LL ~ };
|
help: add a semicolon after the `match` expression
|
LL | };
| +
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:52:5
@ -94,20 +98,15 @@ error: unneeded late initialization
LL | let b;
| ^^^^^^
|
help: declare `b` here
|
LL | let b = if n == 3 {
| +++++++
help: remove the assignments from the branches
help: move the declaration `b` here and remove the assignments from the branches
|
LL ~
LL ~ let b = if n == 3 {
LL ~ "four"
LL | } else {
LL ~ "five"
LL ~ };
|
help: add a semicolon after the `if` expression
|
LL | };
| +
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:59:5
@ -115,20 +114,16 @@ error: unneeded late initialization
LL | let d;
| ^^^^^^
|
help: declare `d` here
|
LL | let d = if true {
| +++++++
help: remove the assignments from the branches
help: move the declaration `d` here and remove the assignments from the branches
|
LL ~
LL ~ let d = if true {
LL | let temp = 5;
LL ~ temp
LL | } else {
LL ~ 15
LL ~ };
|
help: add a semicolon after the `if` expression
|
LL | };
| +
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:67:5
@ -136,20 +131,15 @@ error: unneeded late initialization
LL | let e;
| ^^^^^^
|
help: declare `e` here
|
LL | let e = if true {
| +++++++
help: remove the assignments from the branches
help: move the declaration `e` here and remove the assignments from the branches
|
LL ~
LL ~ let e = if true {
LL ~ format!("{} {}", a, b)
LL | } else {
LL ~ format!("{}", n)
LL ~ };
|
help: add a semicolon after the `if` expression
|
LL | };
| +
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:74:5
@ -157,14 +147,11 @@ error: unneeded late initialization
LL | let f;
| ^^^^^^
|
help: declare `f` here
help: move the declaration `f` here and remove the assignments from the `match` arms
|
LL | let f = match 1 {
| +++++++
help: remove the assignments from the `match` arms
|
LL - 1 => f = "three",
LL + 1 => "three",
LL ~
LL ~ let f = match 1 {
LL ~ 1 => "three",
|
error: unneeded late initialization
@ -173,19 +160,15 @@ error: unneeded late initialization
LL | let g: usize;
| ^^^^^^^^^^^^^
|
help: declare `g` here
help: move the declaration `g` here and remove the assignments from the branches
|
LL | let g: usize = if true {
| ++++++++++++++
help: remove the assignments from the branches
LL ~
LL ~ let g: usize = if true {
LL ~ 5
LL | } else {
LL | panic!();
LL ~ };
|
LL - g = 5;
LL + 5
|
help: add a semicolon after the `if` expression
|
LL | };
| +
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:88:5
@ -196,10 +179,12 @@ LL | let y = SignificantDrop;
LL | x = 1;
| ^^^^^ initialised here
|
help: declare `x` here
help: move the declaration `x` here
|
LL ~
LL | let y = SignificantDrop;
LL ~ let x = 1;
|
LL | let x = 1;
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:92:5
@ -210,10 +195,12 @@ LL | let y = 1;
LL | x = SignificantDrop;
| ^^^^^^^^^^^^^^^^^^^ initialised here
|
help: declare `x` here
help: move the declaration `x` here
|
LL ~
LL | let y = 1;
LL ~ let x = SignificantDrop;
|
LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:96:5
@ -224,10 +211,14 @@ LL | let x;
LL | x = SignificantDrop;
| ^^^^^^^^^^^^^^^^^^^ initialised here
|
help: declare `x` here
help: move the declaration `x` here
|
LL ~
LL | // types that should be considered insignificant
...
LL | let y = Box::new(4);
LL ~ let x = SignificantDrop;
|
LL | let x = SignificantDrop;
| ~~~~~
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:115:5
@ -235,20 +226,17 @@ error: unneeded late initialization
LL | let a;
| ^^^^^^
|
help: declare `a` here
|
LL | let a = match n {
| +++++++
help: remove the assignments from the `match` arms
help: move the declaration `a` here and remove the assignments from the `match` arms
|
LL ~
LL | let n = 1;
LL ~ let a = match n {
LL ~ 1 => f().await,
LL | _ => {
LL ~ "two"
LL | },
LL ~ };
|
help: add a semicolon after the `match` expression
|
LL | };
| +
error: unneeded late initialization
--> tests/ui/needless_late_init.rs:132:5
@ -256,20 +244,17 @@ error: unneeded late initialization
LL | let a;
| ^^^^^^
|
help: declare `a` here
|
LL | let a = match n {
| +++++++
help: remove the assignments from the `match` arms
help: move the declaration `a` here and remove the assignments from the `match` arms
|
LL ~
LL | let n = 1;
LL ~ let a = match n {
LL ~ 1 => f(),
LL | _ => {
LL ~ "two"
LL | },
LL ~ };
|
help: add a semicolon after the `match` expression
|
LL | };
| +
error: aborting due to 16 previous errors

View file

@ -1,6 +1,5 @@
#![feature(fn_traits, unboxed_closures)]
#![warn(clippy::no_effect_underscore_binding)]
#![allow(dead_code, path_statements)]
#![allow(
clippy::deref_addrof,
clippy::redundant_field_names,
@ -33,7 +32,6 @@ impl Neg for Cout {
}
}
struct Unit;
struct Tuple(i32);
struct Struct {
field: i32,
@ -42,10 +40,6 @@ enum Enum {
Tuple(i32),
Struct { field: i32 },
}
struct DropUnit;
impl Drop for DropUnit {
fn drop(&mut self) {}
}
struct DropStruct {
field: i32,
}
@ -117,15 +111,9 @@ impl FnOnce<(&str,)> for GreetStruct3 {
fn main() {
let s = get_struct();
let s2 = get_struct();
0;
//~^ ERROR: statement with no effect
//~| NOTE: `-D clippy::no-effect` implied by `-D warnings`
s2;
//~^ ERROR: statement with no effect
Unit;
//~^ ERROR: statement with no effect
Tuple(0);
//~^ ERROR: statement with no effect
Struct { field: 0 };
@ -192,7 +180,6 @@ fn main() {
unsafe { unsafe_fn() };
let _used = get_struct();
let _x = vec![1];
DropUnit;
DropStruct { field: 0 };
DropTuple(0);
DropEnum::Tuple(0);

View file

@ -1,5 +1,5 @@
error: statement with no effect
--> tests/ui/no_effect.rs:122:5
--> tests/ui/no_effect.rs:115:5
|
LL | 0;
| ^^
@ -8,151 +8,139 @@ LL | 0;
= help: to override `-D warnings` add `#[allow(clippy::no_effect)]`
error: statement with no effect
--> tests/ui/no_effect.rs:125:5
|
LL | s2;
| ^^^
error: statement with no effect
--> tests/ui/no_effect.rs:127:5
|
LL | Unit;
| ^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:129:5
--> tests/ui/no_effect.rs:117:5
|
LL | Tuple(0);
| ^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:131:5
--> tests/ui/no_effect.rs:119:5
|
LL | Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:133:5
--> tests/ui/no_effect.rs:121:5
|
LL | Struct { ..s };
| ^^^^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:135:5
--> tests/ui/no_effect.rs:123:5
|
LL | Union { a: 0 };
| ^^^^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:137:5
--> tests/ui/no_effect.rs:125:5
|
LL | Enum::Tuple(0);
| ^^^^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:139:5
--> tests/ui/no_effect.rs:127:5
|
LL | Enum::Struct { field: 0 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:141:5
--> tests/ui/no_effect.rs:129:5
|
LL | 5 + 6;
| ^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:143:5
--> tests/ui/no_effect.rs:131:5
|
LL | *&42;
| ^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:145:5
--> tests/ui/no_effect.rs:133:5
|
LL | &6;
| ^^^
error: statement with no effect
--> tests/ui/no_effect.rs:147:5
--> tests/ui/no_effect.rs:135:5
|
LL | (5, 6, 7);
| ^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:149:5
--> tests/ui/no_effect.rs:137:5
|
LL | ..;
| ^^^
error: statement with no effect
--> tests/ui/no_effect.rs:151:5
--> tests/ui/no_effect.rs:139:5
|
LL | 5..;
| ^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:153:5
--> tests/ui/no_effect.rs:141:5
|
LL | ..5;
| ^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:155:5
--> tests/ui/no_effect.rs:143:5
|
LL | 5..6;
| ^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:157:5
--> tests/ui/no_effect.rs:145:5
|
LL | 5..=6;
| ^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:159:5
--> tests/ui/no_effect.rs:147:5
|
LL | [42, 55];
| ^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:161:5
--> tests/ui/no_effect.rs:149:5
|
LL | [42, 55][1];
| ^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:163:5
--> tests/ui/no_effect.rs:151:5
|
LL | (42, 55).1;
| ^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:165:5
--> tests/ui/no_effect.rs:153:5
|
LL | [42; 55];
| ^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:167:5
--> tests/ui/no_effect.rs:155:5
|
LL | [42; 55][13];
| ^^^^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:170:5
--> tests/ui/no_effect.rs:158:5
|
LL | || x += 5;
| ^^^^^^^^^^
error: statement with no effect
--> tests/ui/no_effect.rs:173:5
--> tests/ui/no_effect.rs:161:5
|
LL | FooString { s: s };
| ^^^^^^^^^^^^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
--> tests/ui/no_effect.rs:175:9
--> tests/ui/no_effect.rs:163:9
|
LL | let _unused = 1;
| ^^^^^^^
@ -161,22 +149,22 @@ LL | let _unused = 1;
= help: to override `-D warnings` add `#[allow(clippy::no_effect_underscore_binding)]`
error: binding to `_` prefixed variable with no side-effect
--> tests/ui/no_effect.rs:178:9
--> tests/ui/no_effect.rs:166:9
|
LL | let _penguin = || println!("Some helpful closure");
| ^^^^^^^^
error: binding to `_` prefixed variable with no side-effect
--> tests/ui/no_effect.rs:180:9
--> tests/ui/no_effect.rs:168:9
|
LL | let _duck = Struct { field: 0 };
| ^^^^^
error: binding to `_` prefixed variable with no side-effect
--> tests/ui/no_effect.rs:182:9
--> tests/ui/no_effect.rs:170:9
|
LL | let _cat = [2, 4, 6, 8][2];
| ^^^^
error: aborting due to 29 previous errors
error: aborting due to 27 previous errors

View file

@ -675,4 +675,60 @@ fn should_not_trigger_on_significant_iterator_drop() {
}
}
// https://github.com/rust-lang/rust-clippy/issues/9072
fn should_not_trigger_lint_if_place_expr_has_significant_drop() {
let x = Mutex::new(vec![1, 2, 3]);
let x_guard = x.lock().unwrap();
match x_guard[0] {
1 => println!("1!"),
x => println!("{x}"),
}
match x_guard.len() {
1 => println!("1!"),
x => println!("{x}"),
}
}
struct Guard<'a, T>(MutexGuard<'a, T>);
struct Ref<'a, T>(&'a T);
impl<'a, T> Guard<'a, T> {
fn guard(&self) -> &MutexGuard<T> {
&self.0
}
fn guard_ref(&self) -> Ref<MutexGuard<T>> {
Ref(&self.0)
}
fn take(self) -> Box<MutexGuard<'a, T>> {
Box::new(self.0)
}
}
fn should_not_trigger_for_significant_drop_ref() {
let mutex = Mutex::new(vec![1, 2]);
let guard = Guard(mutex.lock().unwrap());
match guard.guard().len() {
0 => println!("empty"),
_ => println!("not empty"),
}
match guard.guard_ref().0.len() {
0 => println!("empty"),
_ => println!("not empty"),
}
match guard.take().len() {
//~^ ERROR: temporary with significant `Drop` in `match` scrutinee will live until the
//~| NOTE: this might lead to deadlocks or other unexpected behavior
0 => println!("empty"),
_ => println!("not empty"),
};
}
fn main() {}

View file

@ -28,6 +28,9 @@ LL | match s.lock_m().get_the_value() {
LL | println!("{}", s.lock_m().get_the_value());
| ---------- another value with significant `Drop` created here
...
LL | println!("{}", s.lock_m().get_the_value());
| ---------- another value with significant `Drop` created here
...
LL | }
| - temporary lives until here
|
@ -47,6 +50,9 @@ LL | match s.lock_m_m().get_the_value() {
LL | println!("{}", s.lock_m().get_the_value());
| ---------- another value with significant `Drop` created here
...
LL | println!("{}", s.lock_m().get_the_value());
| ---------- another value with significant `Drop` created here
...
LL | }
| - temporary lives until here
|
@ -360,7 +366,7 @@ LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | _ => println!("Value is {}", s.lock().deref()),
| ---------------- another value with significant `Drop` created here
| -------- another value with significant `Drop` created here
LL | };
| - temporary lives until here
|
@ -378,7 +384,7 @@ LL | match s.lock().deref().deref() {
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | matcher => println!("Value is {}", s.lock().deref()),
| ---------------- another value with significant `Drop` created here
| -------- another value with significant `Drop` created here
LL | _ => println!("Value was not a match"),
LL | };
| - temporary lives until here
@ -499,5 +505,21 @@ LL ~ let value = mutex.lock().unwrap().foo();
LL ~ match value {
|
error: aborting due to 26 previous errors
error: temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression
--> tests/ui/significant_drop_in_scrutinee.rs:726:11
|
LL | match guard.take().len() {
| ^^^^^^^^^^^^^^^^^^
...
LL | };
| - temporary lives until here
|
= note: this might lead to deadlocks or other unexpected behavior
help: try moving the temporary above the match
|
LL ~ let value = guard.take().len();
LL ~ match value {
|
error: aborting due to 27 previous errors

View file

@ -21,6 +21,8 @@ fn main() {
let _ = check_files_ref_mut(&[(FileType::Account, path)]);
let _ = check_files_self_and_arg(&[(FileType::Account, path)]);
let _ = check_files_mut_path_buf(&[(FileType::Account, std::path::PathBuf::new())]);
check_mut_iteratee_and_modify_inner_variable();
}
// `check_files` and its variants are based on:
@ -138,3 +140,33 @@ fn check_files_mut_path_buf(files: &[(FileType, std::path::PathBuf)]) -> bool {
fn get_file_path(_file_type: &FileType) -> Result<std::path::PathBuf, std::io::Error> {
Ok(std::path::PathBuf::new())
}
// Issue 12098
// https://github.com/rust-lang/rust-clippy/issues/12098
// no message emits
fn check_mut_iteratee_and_modify_inner_variable() {
struct Test {
list: Vec<String>,
mut_this: bool,
}
impl Test {
fn list(&self) -> &[String] {
&self.list
}
}
let mut test = Test {
list: vec![String::from("foo"), String::from("bar")],
mut_this: false,
};
for _item in test.list().to_vec() {
println!("{}", _item);
test.mut_this = true;
{
test.mut_this = true;
}
}
}

View file

@ -21,6 +21,8 @@ fn main() {
let _ = check_files_ref_mut(&[(FileType::Account, path)]);
let _ = check_files_self_and_arg(&[(FileType::Account, path)]);
let _ = check_files_mut_path_buf(&[(FileType::Account, std::path::PathBuf::new())]);
check_mut_iteratee_and_modify_inner_variable();
}
// `check_files` and its variants are based on:
@ -138,3 +140,33 @@ fn check_files_mut_path_buf(files: &[(FileType, std::path::PathBuf)]) -> bool {
fn get_file_path(_file_type: &FileType) -> Result<std::path::PathBuf, std::io::Error> {
Ok(std::path::PathBuf::new())
}
// Issue 12098
// https://github.com/rust-lang/rust-clippy/issues/12098
// no message emits
fn check_mut_iteratee_and_modify_inner_variable() {
struct Test {
list: Vec<String>,
mut_this: bool,
}
impl Test {
fn list(&self) -> &[String] {
&self.list
}
}
let mut test = Test {
list: vec![String::from("foo"), String::from("bar")],
mut_this: false,
};
for _item in test.list().to_vec() {
println!("{}", _item);
test.mut_this = true;
{
test.mut_this = true;
}
}
}

View file

@ -1,5 +1,5 @@
error: unnecessary use of `copied`
--> tests/ui/unnecessary_iter_cloned.rs:29:22
--> tests/ui/unnecessary_iter_cloned.rs:31:22
|
LL | for (t, path) in files.iter().copied() {
| ^^^^^^^^^^^^^^^^^^^^^
@ -17,7 +17,7 @@ LL + let other = match get_file_path(t) {
|
error: unnecessary use of `copied`
--> tests/ui/unnecessary_iter_cloned.rs:44:22
--> tests/ui/unnecessary_iter_cloned.rs:46:22
|
LL | for (t, path) in files.iter().copied() {
| ^^^^^^^^^^^^^^^^^^^^^

View file

@ -86,8 +86,51 @@ mod module {
#[rustfmt::skip]
#[allow(unused_import_braces)]
#[allow(unused_braces)]
use module::{Struct};
fn main() {
test_indented_attr();
}
// Regression test for https://github.com/rust-lang/rust-clippy/issues/4467
#[allow(dead_code)]
use std::collections as puppy_doggy;
// Regression test for https://github.com/rust-lang/rust-clippy/issues/11595
pub mod hidden_glob_reexports {
#![allow(unreachable_pub)]
mod my_prelude {
pub struct MyCoolTypeInternal;
pub use MyCoolTypeInternal as MyCoolType;
}
mod my_uncool_type {
pub(crate) struct MyUncoolType;
}
// This exports `MyCoolType`.
pub use my_prelude::*;
// This hides `my_prelude::MyCoolType`.
#[allow(hidden_glob_reexports)]
use my_uncool_type::MyUncoolType as MyCoolType;
}
// Regression test for https://github.com/rust-lang/rust-clippy/issues/10878
pub mod ambiguous_glob_exports {
#![allow(unreachable_pub)]
mod my_prelude {
pub struct MyType;
}
mod my_type {
pub struct MyType;
}
#[allow(ambiguous_glob_reexports)]
pub use my_prelude::*;
pub use my_type::*;
}

View file

@ -86,8 +86,51 @@ mod module {
#[rustfmt::skip]
#[allow(unused_import_braces)]
#[allow(unused_braces)]
use module::{Struct};
fn main() {
test_indented_attr();
}
// Regression test for https://github.com/rust-lang/rust-clippy/issues/4467
#[allow(dead_code)]
use std::collections as puppy_doggy;
// Regression test for https://github.com/rust-lang/rust-clippy/issues/11595
pub mod hidden_glob_reexports {
#![allow(unreachable_pub)]
mod my_prelude {
pub struct MyCoolTypeInternal;
pub use MyCoolTypeInternal as MyCoolType;
}
mod my_uncool_type {
pub(crate) struct MyUncoolType;
}
// This exports `MyCoolType`.
pub use my_prelude::*;
// This hides `my_prelude::MyCoolType`.
#[allow(hidden_glob_reexports)]
use my_uncool_type::MyUncoolType as MyCoolType;
}
// Regression test for https://github.com/rust-lang/rust-clippy/issues/10878
pub mod ambiguous_glob_exports {
#![allow(unreachable_pub)]
mod my_prelude {
pub struct MyType;
}
mod my_type {
pub struct MyType;
}
#[allow(ambiguous_glob_reexports)]
pub use my_prelude::*;
pub use my_type::*;
}

View file

@ -0,0 +1,14 @@
#[deny(clippy::while_float)]
fn main() {
let mut x = 0.0_f32;
while x < 42.0_f32 {
x += 0.5;
}
while x < 42.0 {
x += 1.0;
}
let mut x = 0;
while x < 42 {
x += 1;
}
}

View file

@ -0,0 +1,20 @@
error: while condition comparing floats
--> tests/ui/while_float.rs:4:11
|
LL | while x < 42.0_f32 {
| ^^^^^^^^^^^^
|
note: the lint level is defined here
--> tests/ui/while_float.rs:1:8
|
LL | #[deny(clippy::while_float)]
| ^^^^^^^^^^^^^^^^^^^
error: while condition comparing floats
--> tests/ui/while_float.rs:7:11
|
LL | while x < 42.0 {
| ^^^^^^^^
error: aborting due to 2 previous errors