Merge remote-tracking branch 'upstream/master' into rustup

This commit is contained in:
Philipp Krones 2023-09-25 10:26:11 +02:00
commit 81fe8dc084
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
210 changed files with 4057 additions and 2370 deletions

View file

@ -18,7 +18,6 @@ use test_utils::IS_RUSTC_TEST_SUITE;
// in the depinfo file (otherwise cargo thinks they are unused)
extern crate clippy_lints;
extern crate clippy_utils;
extern crate derive_new;
extern crate futures;
extern crate if_chain;
extern crate itertools;
@ -33,7 +32,6 @@ mod test_utils;
static TEST_DEPENDENCIES: &[&str] = &[
"clippy_lints",
"clippy_utils",
"derive_new",
"futures",
"if_chain",
"itertools",

View file

@ -0,0 +1 @@
literal-representation-threshold = 0xFFFFFF

View file

@ -0,0 +1,6 @@
#![warn(clippy::decimal_literal_representation)]
fn main() {
let _ = 8388608;
let _ = 0x00FF_FFFF;
//~^ ERROR: integer literal has a better hexadecimal representation
}

View file

@ -0,0 +1,6 @@
#![warn(clippy::decimal_literal_representation)]
fn main() {
let _ = 8388608;
let _ = 16777215;
//~^ ERROR: integer literal has a better hexadecimal representation
}

View file

@ -0,0 +1,11 @@
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:4:13
|
LL | let _ = 16777215;
| ^^^^^^^^ help: consider: `0x00FF_FFFF`
|
= note: `-D clippy::decimal-literal-representation` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
allowed-scripts = ["Cyrillic"]

View file

@ -0,0 +1,6 @@
#![warn(clippy::disallowed_script_idents)]
fn main() {
let счётчик = 10;
let = 10;
//~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuration
}

View file

@ -0,0 +1,11 @@
error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana
--> $DIR/disallowed_script_idents.rs:4:9
|
LL | let カウンタ = 10;
| ^^^^^^^^
|
= note: `-D clippy::disallowed-script-idents` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_script_idents)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
enum-variant-name-threshold = 5

View file

@ -0,0 +1,16 @@
enum Foo {
AFoo,
BFoo,
CFoo,
DFoo,
}
enum Foo2 {
//~^ ERROR: all variants have the same postfix
AFoo,
BFoo,
CFoo,
DFoo,
EFoo,
}
fn main() {}

View file

@ -0,0 +1,18 @@
error: all variants have the same postfix: `Foo`
--> $DIR/enum_variant_names.rs:7:1
|
LL | / enum Foo2 {
LL | |
LL | | AFoo,
LL | | BFoo,
... |
LL | | EFoo,
LL | | }
| |_^
|
= help: remove the postfixes and use full paths to the variants instead of glob imports
= note: `-D clippy::enum-variant-names` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
enum-variant-size-threshold = 500

View file

@ -0,0 +1,11 @@
enum Fine {
A(()),
B([u8; 500]),
}
enum Bad {
//~^ ERROR: large size difference between variants
A(()),
B(Box<[u8; 501]>),
}
fn main() {}

View file

@ -0,0 +1,11 @@
enum Fine {
A(()),
B([u8; 500]),
}
enum Bad {
//~^ ERROR: large size difference between variants
A(()),
B([u8; 501]),
}
fn main() {}

View file

@ -0,0 +1,21 @@
error: large size difference between variants
--> $DIR/enum_variant_size.rs:5:1
|
LL | / enum Bad {
LL | |
LL | | A(()),
| | ----- the second-largest variant contains at least 0 bytes
LL | | B([u8; 501]),
| | ------------ the largest variant contains at least 501 bytes
LL | | }
| |_^ the entire enum is at least 502 bytes
|
= note: `-D clippy::large-enum-variant` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]`
help: consider boxing the large fields to reduce the total size of the enum
|
LL | B(Box<[u8; 501]>),
| ~~~~~~~~~~~~~~
error: aborting due to previous error

View file

@ -0,0 +1 @@
enum-variant-name-threshold = 0

View file

@ -0,0 +1,3 @@
enum Actions {}
fn main() {}

View file

@ -0,0 +1 @@
enforce-iter-loop-reborrow = true

View file

@ -0,0 +1,10 @@
#![warn(clippy::explicit_iter_loop)]
fn main() {
let mut vec = vec![1, 2, 3];
let rmvec = &mut vec;
for _ in &*rmvec {}
//~^ ERROR: it is more concise to loop over references to containers
for _ in &mut *rmvec {}
//~^ ERROR: it is more concise to loop over references to containers
}

View file

@ -0,0 +1,10 @@
#![warn(clippy::explicit_iter_loop)]
fn main() {
let mut vec = vec![1, 2, 3];
let rmvec = &mut vec;
for _ in rmvec.iter() {}
//~^ ERROR: it is more concise to loop over references to containers
for _ in rmvec.iter_mut() {}
//~^ ERROR: it is more concise to loop over references to containers
}

View file

@ -0,0 +1,17 @@
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/explicit_iter_loop.rs:6:14
|
LL | for _ in rmvec.iter() {}
| ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec`
|
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]`
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/explicit_iter_loop.rs:8:14
|
LL | for _ in rmvec.iter_mut() {}
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec`
error: aborting due to 2 previous errors

View file

@ -0,0 +1 @@
stack-size-threshold = 1000

View file

@ -0,0 +1,17 @@
#![warn(clippy::large_stack_frames)]
// We use this helper function instead of writing [0; 4294967297] directly to represent a
// case that large_stack_arrays can't catch
fn create_array<const N: usize>() -> [u8; N] {
[0; N]
}
fn f() {
let _x = create_array::<1000>();
}
fn f2() {
//~^ ERROR: this function allocates a large amount of stack space
let _x = create_array::<1001>();
}
fn main() {}

View file

@ -0,0 +1,15 @@
error: this function allocates a large amount of stack space
--> $DIR/large_stack_frames.rs:12:1
|
LL | / fn f2() {
LL | |
LL | | let _x = create_array::<1001>();
LL | | }
| |_^
|
= note: allocating large amounts of stack space can overflow the stack
= note: `-D clippy::large-stack-frames` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
pass-by-value-size-limit = 512

View file

@ -0,0 +1,7 @@
#![warn(clippy::large_types_passed_by_value)]
fn f(_v: [u8; 512]) {}
fn f2(_v: &[u8; 513]) {}
//~^ ERROR: this argument (513 byte) is passed by value
fn main() {}

View file

@ -0,0 +1,7 @@
#![warn(clippy::large_types_passed_by_value)]
fn f(_v: [u8; 512]) {}
fn f2(_v: [u8; 513]) {}
//~^ ERROR: this argument (513 byte) is passed by value
fn main() {}

View file

@ -0,0 +1,11 @@
error: this argument (513 byte) is passed by value, but might be more efficient if passed by reference (limit: 512 byte)
--> $DIR/large_types_passed_by_value.rs:4:11
|
LL | fn f2(_v: [u8; 513]) {}
| ^^^^^^^^^ help: consider passing by reference instead: `&[u8; 513]`
|
= note: `-D clippy::large-types-passed-by-value` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
matches-for-let-else = "AllTypes"

View file

@ -0,0 +1,10 @@
#![warn(clippy::manual_let_else)]
enum Foo {
A(u8),
B,
}
fn main() {
let Foo::A(x) = Foo::A(1) else { return };
}

View file

@ -0,0 +1,14 @@
#![warn(clippy::manual_let_else)]
enum Foo {
A(u8),
B,
}
fn main() {
let x = match Foo::A(1) {
//~^ ERROR: this could be rewritten as `let...else`
Foo::A(x) => x,
Foo::B => return,
};
}

View file

@ -0,0 +1,15 @@
error: this could be rewritten as `let...else`
--> $DIR/manual_let_else.rs:9:5
|
LL | / let x = match Foo::A(1) {
LL | |
LL | | Foo::A(x) => x,
LL | | Foo::B => return,
LL | | };
| |______^ help: consider writing: `let Foo::A(x) = Foo::A(1) else { return };`
|
= note: `-D clippy::manual-let-else` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
allowed-dotfiles = ["dot"]

View file

@ -0,0 +1,9 @@
#![warn(clippy::path_ends_with_ext)]
use std::path::Path;
fn f(p: &Path) {
p.ends_with(".dot");
}
fn main() {}

View file

@ -0,0 +1 @@
large-error-threshold = 512

View file

@ -0,0 +1,10 @@
#![warn(clippy::result_large_err)]
fn f() -> Result<(), [u8; 511]> {
todo!()
}
fn f2() -> Result<(), [u8; 512]> {
//~^ ERROR: the `Err`-variant returned from this function is very large
todo!()
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: the `Err`-variant returned from this function is very large
--> $DIR/result_large_err.rs:6:12
|
LL | fn f2() -> Result<(), [u8; 512]> {
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
= help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>`
= note: `-D clippy::result-large-err` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::result_large_err)]`
error: aborting due to previous error

View file

@ -10,6 +10,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
allow-print-in-tests
allow-private-module-inception
allow-unwrap-in-tests
allowed-dotfiles
allowed-idents-below-min-chars
allowed-scripts
arithmetic-side-effects-allowed
@ -82,6 +83,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
allow-print-in-tests
allow-private-module-inception
allow-unwrap-in-tests
allowed-dotfiles
allowed-idents-below-min-chars
allowed-scripts
arithmetic-side-effects-allowed

View file

@ -0,0 +1,5 @@
fn f(x: Box<[u8; 500]>) {}
//~^ ERROR: local variable doesn't need to be boxed here
fn f2(x: Box<[u8; 501]>) {}
fn main() {}

View file

@ -0,0 +1,11 @@
error: local variable doesn't need to be boxed here
--> $DIR/boxed_local.rs:1:6
|
LL | fn f(x: Box<[u8; 500]>) {}
| ^
|
= note: `-D clippy::boxed-local` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::boxed_local)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
too-large-for-stack = 500

View file

@ -0,0 +1,9 @@
#![warn(clippy::useless_vec)]
fn main() {
let x = [0u8; 500];
//~^ ERROR: useless use of `vec!`
x.contains(&1);
let y = vec![0u8; 501];
y.contains(&1);
}

View file

@ -0,0 +1,9 @@
#![warn(clippy::useless_vec)]
fn main() {
let x = vec![0u8; 500];
//~^ ERROR: useless use of `vec!`
x.contains(&1);
let y = vec![0u8; 501];
y.contains(&1);
}

View file

@ -0,0 +1,11 @@
error: useless use of `vec!`
--> $DIR/useless_vec.rs:4:13
|
LL | let x = vec![0u8; 500];
| ^^^^^^^^^^^^^^ help: you can use an array directly: `[0u8; 500]`
|
= note: `-D clippy::useless-vec` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::useless_vec)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
too-many-arguments-threshold = 10

View file

@ -0,0 +1,7 @@
#![warn(clippy::too_many_arguments)]
fn not_too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8) {}
fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {}
//~^ ERROR: this function has too many arguments
fn main() {}

View file

@ -0,0 +1,11 @@
error: this function has too many arguments (11/10)
--> $DIR/too_many_arguments.rs:4:1
|
LL | fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::too-many-arguments` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
type-complexity-threshold = 500

View file

@ -0,0 +1,7 @@
// 480
fn f(_: (u8, (u8, (u8, (u8, (u8, (u8,))))))) {}
// 550
fn f2(_: (u8, (u8, (u8, (u8, (u8, (u8, u8))))))) {}
//~^ ERROR: very complex type used
fn main() {}

View file

@ -0,0 +1,11 @@
error: very complex type used. Consider factoring parts into `type` definitions
--> $DIR/type_complexity.rs:4:10
|
LL | fn f2(_: (u8, (u8, (u8, (u8, (u8, (u8, u8))))))) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::type-complexity` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::type_complexity)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
max-trait-bounds = 5

View file

@ -0,0 +1,18 @@
#![warn(clippy::type_repetition_in_bounds)]
fn f<T>()
where
T: Copy + Clone + Sync + Send + ?Sized + Unpin,
T: PartialEq,
{
}
fn f2<T>()
where
T: Copy + Clone + Sync + Send + ?Sized,
T: Unpin + PartialEq,
//~^ ERROR: this type has already been used as a bound predicate
{
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: this type has already been used as a bound predicate
--> $DIR/main.rs:13:5
|
LL | T: Unpin + PartialEq,
| ^^^^^^^^^^^^^^^^^^^^
|
= help: consider combining the bounds: `T: Copy + Clone + Sync + Send + ?Sized + Unpin + PartialEq`
= note: `-D clippy::type-repetition-in-bounds` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::type_repetition_in_bounds)]`
error: aborting due to previous error

View file

@ -1,2 +0,0 @@
accept-comment-above-statement = true
accept-comment-above-attributes = true

View file

@ -0,0 +1,2 @@
# default configuration has `accept-comment-above-statement` and
# `accept-comment-above-attributes` true

View file

@ -0,0 +1,3 @@
# test with these options disabled
accept-comment-above-statement = false
accept-comment-above-attributes = false

View file

@ -1,5 +1,5 @@
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:263:19
--> $DIR/undocumented_unsafe_blocks.rs:266:19
|
LL | /* Safety: */ unsafe {}
| ^^^^^^^^^
@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {}
= help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]`
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:267:5
--> $DIR/undocumented_unsafe_blocks.rs:270:5
|
LL | unsafe {}
| ^^^^^^^^^
@ -17,7 +17,7 @@ LL | unsafe {}
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:271:14
--> $DIR/undocumented_unsafe_blocks.rs:274:14
|
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
| ^^^^^^^^^^^^^
@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:271:29
--> $DIR/undocumented_unsafe_blocks.rs:274:29
|
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
| ^^^^^^^^^^^^^
@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:271:48
--> $DIR/undocumented_unsafe_blocks.rs:274:48
|
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
| ^^^^^^^^^^^^^
@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:275:18
--> $DIR/undocumented_unsafe_blocks.rs:278:18
|
LL | let _ = (42, unsafe {}, "test", unsafe {});
| ^^^^^^^^^
@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:275:37
--> $DIR/undocumented_unsafe_blocks.rs:278:37
|
LL | let _ = (42, unsafe {}, "test", unsafe {});
| ^^^^^^^^^
@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:279:14
--> $DIR/undocumented_unsafe_blocks.rs:282:14
|
LL | let _ = *unsafe { &42 };
| ^^^^^^^^^^^^^^
@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 };
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:284:19
--> $DIR/undocumented_unsafe_blocks.rs:287:19
|
LL | let _ = match unsafe {} {
| ^^^^^^^^^
@ -73,7 +73,7 @@ LL | let _ = match unsafe {} {
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:290:14
--> $DIR/undocumented_unsafe_blocks.rs:293:14
|
LL | let _ = &unsafe {};
| ^^^^^^^^^
@ -81,7 +81,7 @@ LL | let _ = &unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:294:14
--> $DIR/undocumented_unsafe_blocks.rs:297:14
|
LL | let _ = [unsafe {}; 5];
| ^^^^^^^^^
@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:298:13
--> $DIR/undocumented_unsafe_blocks.rs:301:13
|
LL | let _ = unsafe {};
| ^^^^^^^^^
@ -97,7 +97,7 @@ LL | let _ = unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:308:8
--> $DIR/undocumented_unsafe_blocks.rs:311:8
|
LL | t!(unsafe {});
| ^^^^^^^^^
@ -105,7 +105,7 @@ LL | t!(unsafe {});
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:314:13
--> $DIR/undocumented_unsafe_blocks.rs:317:13
|
LL | unsafe {}
| ^^^^^^^^^
@ -117,7 +117,7 @@ LL | t!();
= note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:322:5
--> $DIR/undocumented_unsafe_blocks.rs:325:5
|
LL | unsafe {} // SAFETY:
| ^^^^^^^^^
@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY:
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:326:5
--> $DIR/undocumented_unsafe_blocks.rs:329:5
|
LL | unsafe {
| ^^^^^^^^
@ -133,7 +133,7 @@ LL | unsafe {
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:336:5
--> $DIR/undocumented_unsafe_blocks.rs:339:5
|
LL | unsafe {};
| ^^^^^^^^^
@ -141,7 +141,7 @@ LL | unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:340:20
--> $DIR/undocumented_unsafe_blocks.rs:343:20
|
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:347:5
--> $DIR/undocumented_unsafe_blocks.rs:350:5
|
LL | unsafe impl A for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -157,7 +157,7 @@ LL | unsafe impl A for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:354:9
--> $DIR/undocumented_unsafe_blocks.rs:357:9
|
LL | unsafe impl B for (u32) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:375:13
--> $DIR/undocumented_unsafe_blocks.rs:378:13
|
LL | unsafe impl T for $t {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -177,7 +177,7 @@ LL | no_safety_comment!(());
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:400:13
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
LL | unsafe impl T for $t {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -189,7 +189,7 @@ LL | no_safety_comment!(());
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:408:5
--> $DIR/undocumented_unsafe_blocks.rs:411:5
|
LL | unsafe impl T for (i32) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:400:13
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
LL | unsafe impl T for $t {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -209,7 +209,7 @@ LL | no_safety_comment!(u32);
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:414:5
--> $DIR/undocumented_unsafe_blocks.rs:417:5
|
LL | unsafe impl T for (bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:460:5
--> $DIR/undocumented_unsafe_blocks.rs:463:5
|
LL | unsafe impl NoComment for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:464:19
--> $DIR/undocumented_unsafe_blocks.rs:467:19
|
LL | /* SAFETY: */ unsafe impl InlineComment for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:468:5
--> $DIR/undocumented_unsafe_blocks.rs:471:5
|
LL | unsafe impl TrailingComment for () {} // SAFETY:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
= help: consider adding a safety comment on the preceding line
error: constant item has unnecessary safety comment
--> $DIR/undocumented_unsafe_blocks.rs:472:5
--> $DIR/undocumented_unsafe_blocks.rs:475:5
|
LL | const BIG_NUMBER: i32 = 1000000;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider removing the safety comment
--> $DIR/undocumented_unsafe_blocks.rs:471:5
--> $DIR/undocumented_unsafe_blocks.rs:474:5
|
LL | // SAFETY:
| ^^^^^^^^^^
@ -255,7 +255,7 @@ LL | // SAFETY:
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]`
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:473:5
--> $DIR/undocumented_unsafe_blocks.rs:476:5
|
LL | unsafe impl Interference for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:480:5
--> $DIR/undocumented_unsafe_blocks.rs:483:5
|
LL | unsafe impl ImplInFn for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:489:1
--> $DIR/undocumented_unsafe_blocks.rs:492:1
|
LL | unsafe impl CrateRoot for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {}
= help: consider adding a safety comment on the preceding line
error: statement has unnecessary safety comment
--> $DIR/undocumented_unsafe_blocks.rs:502:5
--> $DIR/undocumented_unsafe_blocks.rs:505:5
|
LL | / let _ = {
LL | | if unsafe { true } {
@ -291,13 +291,13 @@ LL | | };
| |______^
|
help: consider removing the safety comment
--> $DIR/undocumented_unsafe_blocks.rs:501:5
--> $DIR/undocumented_unsafe_blocks.rs:504:5
|
LL | // SAFETY: this is more than one level away, so it should warn
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:503:12
--> $DIR/undocumented_unsafe_blocks.rs:506:12
|
LL | if unsafe { true } {
| ^^^^^^^^^^^^^^^
@ -305,7 +305,7 @@ LL | if unsafe { true } {
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:506:23
--> $DIR/undocumented_unsafe_blocks.rs:509:23
|
LL | let bar = unsafe {};
| ^^^^^^^^^

View file

@ -1,5 +1,5 @@
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:262:19
--> $DIR/undocumented_unsafe_blocks.rs:266:19
|
LL | /* Safety: */ unsafe {}
| ^^^^^^^^^
@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {}
= help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]`
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:266:5
--> $DIR/undocumented_unsafe_blocks.rs:270:5
|
LL | unsafe {}
| ^^^^^^^^^
@ -17,7 +17,7 @@ LL | unsafe {}
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:270:14
--> $DIR/undocumented_unsafe_blocks.rs:274:14
|
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
| ^^^^^^^^^^^^^
@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:270:29
--> $DIR/undocumented_unsafe_blocks.rs:274:29
|
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
| ^^^^^^^^^^^^^
@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:270:48
--> $DIR/undocumented_unsafe_blocks.rs:274:48
|
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
| ^^^^^^^^^^^^^
@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:274:18
--> $DIR/undocumented_unsafe_blocks.rs:278:18
|
LL | let _ = (42, unsafe {}, "test", unsafe {});
| ^^^^^^^^^
@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:274:37
--> $DIR/undocumented_unsafe_blocks.rs:278:37
|
LL | let _ = (42, unsafe {}, "test", unsafe {});
| ^^^^^^^^^
@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:278:14
--> $DIR/undocumented_unsafe_blocks.rs:282:14
|
LL | let _ = *unsafe { &42 };
| ^^^^^^^^^^^^^^
@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 };
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:283:19
--> $DIR/undocumented_unsafe_blocks.rs:287:19
|
LL | let _ = match unsafe {} {
| ^^^^^^^^^
@ -73,7 +73,7 @@ LL | let _ = match unsafe {} {
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:289:14
--> $DIR/undocumented_unsafe_blocks.rs:293:14
|
LL | let _ = &unsafe {};
| ^^^^^^^^^
@ -81,7 +81,7 @@ LL | let _ = &unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:293:14
--> $DIR/undocumented_unsafe_blocks.rs:297:14
|
LL | let _ = [unsafe {}; 5];
| ^^^^^^^^^
@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5];
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:297:13
--> $DIR/undocumented_unsafe_blocks.rs:301:13
|
LL | let _ = unsafe {};
| ^^^^^^^^^
@ -97,7 +97,7 @@ LL | let _ = unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:307:8
--> $DIR/undocumented_unsafe_blocks.rs:311:8
|
LL | t!(unsafe {});
| ^^^^^^^^^
@ -105,7 +105,7 @@ LL | t!(unsafe {});
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:313:13
--> $DIR/undocumented_unsafe_blocks.rs:317:13
|
LL | unsafe {}
| ^^^^^^^^^
@ -117,7 +117,7 @@ LL | t!();
= note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:321:5
--> $DIR/undocumented_unsafe_blocks.rs:325:5
|
LL | unsafe {} // SAFETY:
| ^^^^^^^^^
@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY:
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:325:5
--> $DIR/undocumented_unsafe_blocks.rs:329:5
|
LL | unsafe {
| ^^^^^^^^
@ -133,7 +133,7 @@ LL | unsafe {
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:335:5
--> $DIR/undocumented_unsafe_blocks.rs:339:5
|
LL | unsafe {};
| ^^^^^^^^^
@ -141,7 +141,7 @@ LL | unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:339:20
--> $DIR/undocumented_unsafe_blocks.rs:343:20
|
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:346:5
--> $DIR/undocumented_unsafe_blocks.rs:350:5
|
LL | unsafe impl A for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -157,7 +157,7 @@ LL | unsafe impl A for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:353:9
--> $DIR/undocumented_unsafe_blocks.rs:357:9
|
LL | unsafe impl B for (u32) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:374:13
--> $DIR/undocumented_unsafe_blocks.rs:378:13
|
LL | unsafe impl T for $t {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -177,7 +177,7 @@ LL | no_safety_comment!(());
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:399:13
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
LL | unsafe impl T for $t {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -189,7 +189,7 @@ LL | no_safety_comment!(());
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:407:5
--> $DIR/undocumented_unsafe_blocks.rs:411:5
|
LL | unsafe impl T for (i32) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:399:13
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
LL | unsafe impl T for $t {}
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -209,7 +209,7 @@ LL | no_safety_comment!(u32);
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:413:5
--> $DIR/undocumented_unsafe_blocks.rs:417:5
|
LL | unsafe impl T for (bool) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:459:5
--> $DIR/undocumented_unsafe_blocks.rs:463:5
|
LL | unsafe impl NoComment for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:463:19
--> $DIR/undocumented_unsafe_blocks.rs:467:19
|
LL | /* SAFETY: */ unsafe impl InlineComment for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:467:5
--> $DIR/undocumented_unsafe_blocks.rs:471:5
|
LL | unsafe impl TrailingComment for () {} // SAFETY:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
= help: consider adding a safety comment on the preceding line
error: constant item has unnecessary safety comment
--> $DIR/undocumented_unsafe_blocks.rs:471:5
--> $DIR/undocumented_unsafe_blocks.rs:475:5
|
LL | const BIG_NUMBER: i32 = 1000000;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider removing the safety comment
--> $DIR/undocumented_unsafe_blocks.rs:470:5
--> $DIR/undocumented_unsafe_blocks.rs:474:5
|
LL | // SAFETY:
| ^^^^^^^^^^
@ -255,7 +255,7 @@ LL | // SAFETY:
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]`
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:472:5
--> $DIR/undocumented_unsafe_blocks.rs:476:5
|
LL | unsafe impl Interference for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:479:5
--> $DIR/undocumented_unsafe_blocks.rs:483:5
|
LL | unsafe impl ImplInFn for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe impl missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:488:1
--> $DIR/undocumented_unsafe_blocks.rs:492:1
|
LL | unsafe impl CrateRoot for () {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {}
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:498:9
--> $DIR/undocumented_unsafe_blocks.rs:502:9
|
LL | unsafe {};
| ^^^^^^^^^
@ -287,7 +287,7 @@ LL | unsafe {};
= help: consider adding a safety comment on the preceding line
error: statement has unnecessary safety comment
--> $DIR/undocumented_unsafe_blocks.rs:501:5
--> $DIR/undocumented_unsafe_blocks.rs:505:5
|
LL | / let _ = {
LL | | if unsafe { true } {
@ -299,13 +299,13 @@ LL | | };
| |______^
|
help: consider removing the safety comment
--> $DIR/undocumented_unsafe_blocks.rs:500:5
--> $DIR/undocumented_unsafe_blocks.rs:504:5
|
LL | // SAFETY: this is more than one level away, so it should warn
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:502:12
--> $DIR/undocumented_unsafe_blocks.rs:506:12
|
LL | if unsafe { true } {
| ^^^^^^^^^^^^^^^
@ -313,7 +313,7 @@ LL | if unsafe { true } {
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:505:23
--> $DIR/undocumented_unsafe_blocks.rs:509:23
|
LL | let bar = unsafe {};
| ^^^^^^^^^
@ -321,21 +321,13 @@ LL | let bar = unsafe {};
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:523:9
--> $DIR/undocumented_unsafe_blocks.rs:527:9
|
LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:527:9
|
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:531:9
|
@ -344,5 +336,61 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line()
|
= help: consider adding a safety comment on the preceding line
error: aborting due to 39 previous errors
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:535:9
|
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:541:5
|
LL | unsafe {}
| ^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:545:5
|
LL | unsafe {
| ^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:552:9
|
LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:557:9
|
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:563:9
|
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: unsafe block missing a safety comment
--> $DIR/undocumented_unsafe_blocks.rs:568:5
|
LL | unsafe {}
| ^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
error: aborting due to 45 previous errors

View file

@ -1,4 +1,7 @@
//@aux-build:../../ui/auxiliary/proc_macro_unsafe.rs
//@revisions: default disabled
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/default
//@[disabled] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/disabled
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
#![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)]
@ -491,7 +494,7 @@ unsafe impl CrateRoot for () {}
// SAFETY: ok
unsafe impl CrateRoot for (i32) {}
fn issue_9142() {
fn nested_block_separation_issue_9142() {
// SAFETY: ok
let _ =
// we need this comment to avoid rustfmt putting
@ -518,49 +521,50 @@ pub const unsafe fn a_const_function_with_a_very_long_name_to_break_the_line() -
2
}
fn issue_10832() {
// Safety: A safety comment
fn separate_line_from_let_issue_10832() {
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
let _some_variable_with_a_very_long_name_to_break_the_line =
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
// Safety: Another safety comment
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
// Safety: Yet another safety comment
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
}
fn issue_8679<T: Copy>() {
// SAFETY:
fn above_expr_attribute_issue_8679<T: Copy>() {
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
#[allow(unsafe_code)]
unsafe {}
// SAFETY:
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
#[expect(unsafe_code, reason = "totally safe")]
unsafe {
*std::ptr::null::<T>()
};
// Safety: A safety comment
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
#[allow(unsafe_code)]
let _some_variable_with_a_very_long_name_to_break_the_line =
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
// Safety: Another safety comment
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
#[allow(unsafe_code)]
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
// Safety: Yet another safety comment
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
#[allow(unsafe_code)]
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
#[allow(non_upper_case_globals)]
static _some_static_with_a_very_long_name_to_break_the_line: u32 =
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
// SAFETY:
#[allow(unsafe_code)]
// This also works I guess
// This shouldn't work either
unsafe {}
}

View file

@ -0,0 +1 @@
unnecessary-box-size = 64

View file

@ -0,0 +1,11 @@
#![warn(clippy::unnecessary_box_returns)]
fn f() -> [u8; 64] {
//~^ ERROR: boxed return of the sized type `[u8; 64]`
todo!()
}
fn f2() -> Box<[u8; 65]> {
todo!()
}
fn main() {}

View file

@ -0,0 +1,11 @@
#![warn(clippy::unnecessary_box_returns)]
fn f() -> Box<[u8; 64]> {
//~^ ERROR: boxed return of the sized type `[u8; 64]`
todo!()
}
fn f2() -> Box<[u8; 65]> {
todo!()
}
fn main() {}

View file

@ -0,0 +1,12 @@
error: boxed return of the sized type `[u8; 64]`
--> $DIR/unnecessary_box_returns.rs:3:11
|
LL | fn f() -> Box<[u8; 64]> {
| ^^^^^^^^^^^^^ help: try: `[u8; 64]`
|
= help: changing this also requires a change to the return expressions in this function
= note: `-D clippy::unnecessary-box-returns` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_box_returns)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
verbose-bit-mask-threshold = 31

View file

@ -0,0 +1,7 @@
#![warn(clippy::verbose_bit_mask)]
fn main() {
let v: i32 = 0;
let _ = v & 0b11111 == 0;
let _ = v.trailing_zeros() >= 6;
//~^ ERROR: bit mask could be simplified
}

View file

@ -0,0 +1,7 @@
#![warn(clippy::verbose_bit_mask)]
fn main() {
let v: i32 = 0;
let _ = v & 0b11111 == 0;
let _ = v & 0b111111 == 0;
//~^ ERROR: bit mask could be simplified
}

View file

@ -0,0 +1,11 @@
error: bit mask could be simplified with a call to `trailing_zeros`
--> $DIR/verbose_bit_mask.rs:5:13
|
LL | let _ = v & 0b111111 == 0;
| ^^^^^^^^^^^^^^^^^ help: try: `v.trailing_zeros() >= 6`
|
= note: `-D clippy::verbose-bit-mask` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::verbose_bit_mask)]`
error: aborting due to previous error

View file

@ -0,0 +1 @@
warn-on-all-wildcard-imports = true

View file

@ -0,0 +1,11 @@
#![warn(clippy::wildcard_imports)]
mod prelude {
pub const FOO: u8 = 1;
}
use prelude::FOO;
//~^ ERROR: usage of wildcard import
fn main() {
let _ = FOO;
}

View file

@ -0,0 +1,11 @@
#![warn(clippy::wildcard_imports)]
mod prelude {
pub const FOO: u8 = 1;
}
use prelude::*;
//~^ ERROR: usage of wildcard import
fn main() {
let _ = FOO;
}

View file

@ -0,0 +1,11 @@
error: usage of wildcard import
--> $DIR/wildcard_imports.rs:6:5
|
LL | use prelude::*;
| ^^^^^^^^^^ help: try: `prelude::FOO`
|
= note: `-D clippy::wildcard-imports` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::wildcard_imports)]`
error: aborting due to previous error

View file

@ -361,3 +361,7 @@ fn avoid_subtract_overflow(q: u32) {
//~^ ERROR: casting `u32` to `u8` may truncate the value
c as usize;
}
fn issue11426() {
(&42u8 >> 0xa9008fb6c9d81e42_0e25730562a601c8_u128) as usize;
}

View file

@ -49,3 +49,14 @@ mod cast_lossless_in_impl {
enum Test {
A = u32::MAX as i64 + 1,
}
fn issue11458() {
macro_rules! sign_cast {
($var: ident, $src: ty, $dest: ty) => {
<$dest>::from_ne_bytes(($var as $src).to_ne_bytes())
};
}
let x = 10_u128;
let _ = i32::from(sign_cast!(x, u8, i8));
let _ = i32::from(sign_cast!(x, u8, i8) + 1);
}

View file

@ -49,3 +49,14 @@ mod cast_lossless_in_impl {
enum Test {
A = u32::MAX as i64 + 1,
}
fn issue11458() {
macro_rules! sign_cast {
($var: ident, $src: ty, $dest: ty) => {
<$dest>::from_ne_bytes(($var as $src).to_ne_bytes())
};
}
let x = 10_u128;
let _ = sign_cast!(x, u8, i8) as i32;
let _ = (sign_cast!(x, u8, i8) + 1) as i32;
}

View file

@ -115,5 +115,17 @@ error: casting `u8` to `u16` may become silently lossy if you later change the t
LL | let _ = (1u8 + 1u8) as u16;
| ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)`
error: aborting due to 19 previous errors
error: casting `i8` to `i32` may become silently lossy if you later change the type
--> $DIR/cast_lossless_integer.rs:60:13
|
LL | let _ = sign_cast!(x, u8, i8) as i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8))`
error: casting `i8` to `i32` may become silently lossy if you later change the type
--> $DIR/cast_lossless_integer.rs:61:13
|
LL | let _ = (sign_cast!(x, u8, i8) + 1) as i32;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i32::from(sign_cast!(x, u8, i8) + 1)`
error: aborting due to 21 previous errors

View file

@ -1,7 +1,6 @@
#![allow(clippy::non_canonical_clone_impl, clippy::non_canonical_partial_ord_impl, dead_code)]
#![warn(clippy::expl_impl_clone_on_copy)]
#[derive(Copy)]
struct Qux;

View file

@ -1,5 +1,5 @@
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:8:1
--> $DIR/derive.rs:7:1
|
LL | / impl Clone for Qux {
LL | |
@ -10,7 +10,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:8:1
--> $DIR/derive.rs:7:1
|
LL | / impl Clone for Qux {
LL | |
@ -23,7 +23,7 @@ LL | | }
= help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]`
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:33:1
--> $DIR/derive.rs:32:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | |
@ -34,7 +34,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:33:1
--> $DIR/derive.rs:32:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | |
@ -45,7 +45,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:45:1
--> $DIR/derive.rs:44:1
|
LL | / impl Clone for BigArray {
LL | |
@ -56,7 +56,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:45:1
--> $DIR/derive.rs:44:1
|
LL | / impl Clone for BigArray {
LL | |
@ -67,7 +67,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:57:1
--> $DIR/derive.rs:56:1
|
LL | / impl Clone for FnPtr {
LL | |
@ -78,7 +78,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:57:1
--> $DIR/derive.rs:56:1
|
LL | / impl Clone for FnPtr {
LL | |
@ -89,7 +89,7 @@ LL | | }
| |_^
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:78:1
--> $DIR/derive.rs:77:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | |
@ -100,7 +100,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:78:1
--> $DIR/derive.rs:77:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | |

View file

@ -7,7 +7,8 @@
clippy::option_map_unit_fn,
clippy::redundant_closure_call,
clippy::uninlined_format_args,
clippy::useless_vec
clippy::useless_vec,
clippy::unnecessary_map_on_constructor
)]
use std::path::{Path, PathBuf};

View file

@ -7,7 +7,8 @@
clippy::option_map_unit_fn,
clippy::redundant_closure_call,
clippy::uninlined_format_args,
clippy::useless_vec
clippy::useless_vec,
clippy::unnecessary_map_on_constructor
)]
use std::path::{Path, PathBuf};

View file

@ -1,5 +1,5 @@
error: redundant closure
--> $DIR/eta.rs:28:27
--> $DIR/eta.rs:29:27
|
LL | let a = Some(1u8).map(|a| foo(a));
| ^^^^^^^^^^ help: replace the closure with the function itself: `foo`
@ -8,31 +8,31 @@ LL | let a = Some(1u8).map(|a| foo(a));
= help: to override `-D warnings` add `#[allow(clippy::redundant_closure)]`
error: redundant closure
--> $DIR/eta.rs:32:40
--> $DIR/eta.rs:33:40
|
LL | let _: Option<Vec<u8>> = true.then(|| vec![]); // special case vec!
| ^^^^^^^^^ help: replace the closure with `Vec::new`: `std::vec::Vec::new`
error: redundant closure
--> $DIR/eta.rs:33:35
--> $DIR/eta.rs:34:35
|
LL | let d = Some(1u8).map(|a| foo((|b| foo2(b))(a))); //is adjusted?
| ^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo2`
error: redundant closure
--> $DIR/eta.rs:34:26
--> $DIR/eta.rs:35:26
|
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted
| ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below`
error: redundant closure
--> $DIR/eta.rs:41:27
--> $DIR/eta.rs:42:27
|
LL | let e = Some(1u8).map(|a| generic(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
error: redundant closure
--> $DIR/eta.rs:93:51
--> $DIR/eta.rs:94:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `TestStruct::foo`
@ -41,127 +41,127 @@ LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
= help: to override `-D warnings` add `#[allow(clippy::redundant_closure_for_method_calls)]`
error: redundant closure
--> $DIR/eta.rs:94:51
--> $DIR/eta.rs:95:51
|
LL | let e = Some(TestStruct { some_ref: &i }).map(|a| a.trait_foo());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `TestTrait::trait_foo`
error: redundant closure
--> $DIR/eta.rs:96:42
--> $DIR/eta.rs:97:42
|
LL | let e = Some(&mut vec![1, 2, 3]).map(|v| v.clear());
| ^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::vec::Vec::clear`
error: redundant closure
--> $DIR/eta.rs:100:29
--> $DIR/eta.rs:101:29
|
LL | let e = Some("str").map(|s| s.to_string());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::string::ToString::to_string`
error: redundant closure
--> $DIR/eta.rs:101:27
--> $DIR/eta.rs:102:27
|
LL | let e = Some('a').map(|s| s.to_uppercase());
| ^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_uppercase`
error: redundant closure
--> $DIR/eta.rs:103:65
--> $DIR/eta.rs:104:65
|
LL | let e: std::vec::Vec<char> = vec!['a', 'b', 'c'].iter().map(|c| c.to_ascii_uppercase()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `char::to_ascii_uppercase`
error: redundant closure
--> $DIR/eta.rs:166:22
--> $DIR/eta.rs:167:22
|
LL | requires_fn_once(|| x());
| ^^^^^^ help: replace the closure with the function itself: `x`
error: redundant closure
--> $DIR/eta.rs:173:27
--> $DIR/eta.rs:174:27
|
LL | let a = Some(1u8).map(|a| foo_ptr(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `foo_ptr`
error: redundant closure
--> $DIR/eta.rs:178:27
--> $DIR/eta.rs:179:27
|
LL | let a = Some(1u8).map(|a| closure(a));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `closure`
error: redundant closure
--> $DIR/eta.rs:210:28
--> $DIR/eta.rs:211:28
|
LL | x.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
error: redundant closure
--> $DIR/eta.rs:211:28
--> $DIR/eta.rs:212:28
|
LL | y.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut add_to_res`
error: redundant closure
--> $DIR/eta.rs:212:28
--> $DIR/eta.rs:213:28
|
LL | z.into_iter().for_each(|x| add_to_res(x));
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `add_to_res`
error: redundant closure
--> $DIR/eta.rs:219:21
--> $DIR/eta.rs:220:21
|
LL | Some(1).map(|n| closure(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut closure`
error: redundant closure
--> $DIR/eta.rs:223:21
--> $DIR/eta.rs:224:21
|
LL | Some(1).map(|n| in_loop(n));
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop`
error: redundant closure
--> $DIR/eta.rs:316:18
--> $DIR/eta.rs:317:18
|
LL | takes_fn_mut(|| f());
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
error: redundant closure
--> $DIR/eta.rs:319:19
--> $DIR/eta.rs:320:19
|
LL | takes_fn_once(|| f());
| ^^^^^^ help: replace the closure with the function itself: `&mut f`
error: redundant closure
--> $DIR/eta.rs:323:26
--> $DIR/eta.rs:324:26
|
LL | move || takes_fn_mut(|| f_used_once())
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `&mut f_used_once`
error: redundant closure
--> $DIR/eta.rs:335:19
--> $DIR/eta.rs:336:19
|
LL | array_opt.map(|a| a.as_slice());
| ^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8; 3]>::as_slice`
error: redundant closure
--> $DIR/eta.rs:338:19
--> $DIR/eta.rs:339:19
|
LL | slice_opt.map(|s| s.len());
| ^^^^^^^^^^^ help: replace the closure with the method itself: `<[u8]>::len`
error: redundant closure
--> $DIR/eta.rs:341:17
--> $DIR/eta.rs:342:17
|
LL | ptr_opt.map(|p| p.is_null());
| ^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<*const usize>::is_null`
error: redundant closure
--> $DIR/eta.rs:345:17
--> $DIR/eta.rs:346:17
|
LL | dyn_opt.map(|d| d.method_on_dyn());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
error: redundant closure
--> $DIR/eta.rs:388:19
--> $DIR/eta.rs:389:19
|
LL | let _ = f(&0, |x, y| f2(x, y));
| ^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `f2`

View file

@ -22,9 +22,9 @@ mod rustc_ok {
#[expect(illegal_floating_point_literal_pattern)]
match x {
5.0 => {}
6.0 => {}
_ => {}
5.0 => {},
6.0 => {},
_ => {},
}
}
}
@ -41,9 +41,9 @@ mod rustc_warn {
#[expect(illegal_floating_point_literal_pattern)]
//~^ ERROR: this lint expectation is unfulfilled
match x {
5 => {}
6 => {}
_ => {}
5 => {},
6 => {},
_ => {},
}
}
}

View file

@ -113,4 +113,19 @@ with_span!(
}
);
mod issue11302 {
use std::fmt::Debug;
use std::marker::PhantomData;
#[derive(Debug)]
struct Wrapper<T>(PhantomData<T>);
fn store<T: 'static>(v: &mut Vec<Box<dyn Debug>>)
where
Wrapper<T>: Debug,
{
v.push(Box::new(Wrapper(PhantomData)));
}
}
fn main() {}

View file

@ -113,4 +113,19 @@ with_span!(
}
);
mod issue11302 {
use std::fmt::Debug;
use std::marker::PhantomData;
#[derive(Debug)]
struct Wrapper<T>(PhantomData<T>);
fn store<T: 'static>(v: &mut Vec<Box<dyn Debug>>)
where
Wrapper<T>: Debug,
{
v.push(Box::new(Wrapper(PhantomData)));
}
}
fn main() {}

View file

@ -55,3 +55,27 @@ fn main() {
fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str> {
iter.filter_map(|(_, s): (&str, _)| Some(s)).collect()
}
fn issue11503() {
let bools: &[bool] = &[true, false, false, true];
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| *b).map(|(i, b)| i).collect();
// Need to insert multiple derefs if there is more than one layer of references
let bools: &[&&bool] = &[&&true, &&false, &&false, &&true];
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| ***b).map(|(i, b)| i).collect();
// Should also suggest derefs when going through a mutable reference
let bools: &[&mut bool] = &[&mut true];
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| **b).map(|(i, b)| i).collect();
// Should also suggest derefs when going through a custom deref
struct DerefToBool;
impl std::ops::Deref for DerefToBool {
type Target = bool;
fn deref(&self) -> &Self::Target {
&true
}
}
let bools: &[&&DerefToBool] = &[&&DerefToBool];
let _: Vec<usize> = bools.iter().enumerate().filter(|&(i, b)| ****b).map(|(i, b)| i).collect();
}

View file

@ -55,3 +55,27 @@ fn main() {
fn issue11309<'a>(iter: impl Iterator<Item = (&'a str, &'a str)>) -> Vec<&'a str> {
iter.filter_map(|(_, s): (&str, _)| Some(s)).collect()
}
fn issue11503() {
let bools: &[bool] = &[true, false, false, true];
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
// Need to insert multiple derefs if there is more than one layer of references
let bools: &[&&bool] = &[&&true, &&false, &&false, &&true];
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
// Should also suggest derefs when going through a mutable reference
let bools: &[&mut bool] = &[&mut true];
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
// Should also suggest derefs when going through a custom deref
struct DerefToBool;
impl std::ops::Deref for DerefToBool {
type Target = bool;
fn deref(&self) -> &Self::Target {
&true
}
}
let bools: &[&&DerefToBool] = &[&&DerefToBool];
let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
}

View file

@ -37,5 +37,29 @@ error: usage of `bool::then` in `filter_map`
LL | v.clone().iter().filter_map(|i| (i == &NonCopy).then(|| i));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&i| (i == &NonCopy)).map(|i| i)`
error: aborting due to 6 previous errors
error: usage of `bool::then` in `filter_map`
--> $DIR/filter_map_bool_then.rs:61:50
|
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| *b).map(|(i, b)| i)`
error: usage of `bool::then` in `filter_map`
--> $DIR/filter_map_bool_then.rs:65:50
|
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ***b).map(|(i, b)| i)`
error: usage of `bool::then` in `filter_map`
--> $DIR/filter_map_bool_then.rs:69:50
|
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| **b).map(|(i, b)| i)`
error: usage of `bool::then` in `filter_map`
--> $DIR/filter_map_bool_then.rs:80:50
|
LL | let _: Vec<usize> = bools.iter().enumerate().filter_map(|(i, b)| b.then(|| i)).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `filter` then `map` instead: `filter(|&(i, b)| ****b).map(|(i, b)| i)`
error: aborting due to 10 previous errors

View file

@ -436,4 +436,27 @@ impl DifferingErrors {
}
}
// Issue #11165
pub struct Aliased1;
pub type Alias1 = Aliased1;
impl Alias1 {
pub fn len(&self) -> usize {
todo!()
}
pub fn is_empty(&self) -> bool {
todo!()
}
}
pub struct Aliased2;
pub type Alias2 = Aliased2;
impl Alias2 {
pub fn len(&self) -> usize {
//~^ ERROR: type `Alias2` has a public `len` method, but no `is_empty` method
todo!()
}
}
fn main() {}

View file

@ -141,5 +141,11 @@ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `
LL | pub async fn len(&self) -> Result<usize, ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 15 previous errors
error: type `Alias2` has a public `len` method, but no `is_empty` method
--> $DIR/len_without_is_empty.rs:456:5
|
LL | pub fn len(&self) -> usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 16 previous errors

View file

@ -177,3 +177,5 @@ fn attributes() {
async fn issue10433() {
let _pending: () = std::future::pending().await;
}
pub async fn issue11502(a: ()) {}

View file

@ -177,3 +177,5 @@ fn attributes() {
async fn issue10433() {
let _pending: () = std::future::pending().await;
}
pub async fn issue11502(a: ()) {}

View file

@ -5,6 +5,7 @@
clippy::unit_arg,
clippy::match_ref_pats,
clippy::redundant_pattern_matching,
clippy::unnecessary_map_on_constructor,
for_loops_over_fallibles,
dead_code
)]

View file

@ -5,6 +5,7 @@
clippy::unit_arg,
clippy::match_ref_pats,
clippy::redundant_pattern_matching,
clippy::unnecessary_map_on_constructor,
for_loops_over_fallibles,
dead_code
)]

View file

@ -1,5 +1,5 @@
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:13:5
--> $DIR/manual_map_option.rs:14:5
|
LL | / match Some(0) {
LL | | Some(_) => Some(2),
@ -11,7 +11,7 @@ LL | | };
= help: to override `-D warnings` add `#[allow(clippy::manual_map)]`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:18:5
--> $DIR/manual_map_option.rs:19:5
|
LL | / match Some(0) {
LL | | Some(x) => Some(x + 1),
@ -20,7 +20,7 @@ LL | | };
| |_____^ help: try: `Some(0).map(|x| x + 1)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:23:5
--> $DIR/manual_map_option.rs:24:5
|
LL | / match Some("") {
LL | | Some(x) => Some(x.is_empty()),
@ -29,7 +29,7 @@ LL | | };
| |_____^ help: try: `Some("").map(|x| x.is_empty())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:28:5
--> $DIR/manual_map_option.rs:29:5
|
LL | / if let Some(x) = Some(0) {
LL | | Some(!x)
@ -39,7 +39,7 @@ LL | | };
| |_____^ help: try: `Some(0).map(|x| !x)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:35:5
--> $DIR/manual_map_option.rs:36:5
|
LL | / match Some(0) {
LL | | Some(x) => { Some(std::convert::identity(x)) }
@ -48,7 +48,7 @@ LL | | };
| |_____^ help: try: `Some(0).map(std::convert::identity)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:40:5
--> $DIR/manual_map_option.rs:41:5
|
LL | / match Some(&String::new()) {
LL | | Some(x) => Some(str::len(x)),
@ -57,7 +57,7 @@ LL | | };
| |_____^ help: try: `Some(&String::new()).map(|x| str::len(x))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:50:5
--> $DIR/manual_map_option.rs:51:5
|
LL | / match &Some([0, 1]) {
LL | | Some(x) => Some(x[0]),
@ -66,7 +66,7 @@ LL | | };
| |_____^ help: try: `Some([0, 1]).as_ref().map(|x| x[0])`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:55:5
--> $DIR/manual_map_option.rs:56:5
|
LL | / match &Some(0) {
LL | | &Some(x) => Some(x * 2),
@ -75,7 +75,7 @@ LL | | };
| |_____^ help: try: `Some(0).map(|x| x * 2)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:60:5
--> $DIR/manual_map_option.rs:61:5
|
LL | / match Some(String::new()) {
LL | | Some(ref x) => Some(x.is_empty()),
@ -84,7 +84,7 @@ LL | | };
| |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:65:5
--> $DIR/manual_map_option.rs:66:5
|
LL | / match &&Some(String::new()) {
LL | | Some(x) => Some(x.len()),
@ -93,7 +93,7 @@ LL | | };
| |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:70:5
--> $DIR/manual_map_option.rs:71:5
|
LL | / match &&Some(0) {
LL | | &&Some(x) => Some(x + x),
@ -102,7 +102,7 @@ LL | | };
| |_____^ help: try: `Some(0).map(|x| x + x)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:83:9
--> $DIR/manual_map_option.rs:84:9
|
LL | / match &mut Some(String::new()) {
LL | | Some(x) => Some(x.push_str("")),
@ -111,7 +111,7 @@ LL | | };
| |_________^ help: try: `Some(String::new()).as_mut().map(|x| x.push_str(""))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:89:5
--> $DIR/manual_map_option.rs:90:5
|
LL | / match &mut Some(String::new()) {
LL | | Some(ref x) => Some(x.len()),
@ -120,7 +120,7 @@ LL | | };
| |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:94:5
--> $DIR/manual_map_option.rs:95:5
|
LL | / match &mut &Some(String::new()) {
LL | | Some(x) => Some(x.is_empty()),
@ -129,7 +129,7 @@ LL | | };
| |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.is_empty())`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:99:5
--> $DIR/manual_map_option.rs:100:5
|
LL | / match Some((0, 1, 2)) {
LL | | Some((x, y, z)) => Some(x + y + z),
@ -138,7 +138,7 @@ LL | | };
| |_____^ help: try: `Some((0, 1, 2)).map(|(x, y, z)| x + y + z)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:104:5
--> $DIR/manual_map_option.rs:105:5
|
LL | / match Some([1, 2, 3]) {
LL | | Some([first, ..]) => Some(first),
@ -147,7 +147,7 @@ LL | | };
| |_____^ help: try: `Some([1, 2, 3]).map(|[first, ..]| first)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:109:5
--> $DIR/manual_map_option.rs:110:5
|
LL | / match &Some((String::new(), "test")) {
LL | | Some((x, y)) => Some((y, x)),
@ -156,7 +156,7 @@ LL | | };
| |_____^ help: try: `Some((String::new(), "test")).as_ref().map(|(x, y)| (y, x))`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:167:5
--> $DIR/manual_map_option.rs:168:5
|
LL | / match Some(0) {
LL | | Some(x) => Some(vec![x]),
@ -165,7 +165,7 @@ LL | | };
| |_____^ help: try: `Some(0).map(|x| vec![x])`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:172:5
--> $DIR/manual_map_option.rs:173:5
|
LL | / match option_env!("") {
LL | | Some(x) => Some(String::from(x)),
@ -174,7 +174,7 @@ LL | | };
| |_____^ help: try: `option_env!("").map(String::from)`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:192:12
--> $DIR/manual_map_option.rs:193:12
|
LL | } else if let Some(x) = Some(0) {
| ____________^
@ -185,7 +185,7 @@ LL | | };
| |_____^ help: try: `{ Some(0).map(|x| x + 1) }`
error: manual implementation of `Option::map`
--> $DIR/manual_map_option.rs:200:12
--> $DIR/manual_map_option.rs:201:12
|
LL | } else if let Some(x) = Some(0) {
| ____________^

View file

@ -131,21 +131,6 @@ fn main() {
0
}
}
let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap();
let _ = std::path::Path::new(".").join(".");
deref_target_is_x(X);
multiple_constraints([[""]]);
multiple_constraints_normalizes_to_same(X, X);
let _ = Some("").unwrap_or("");
let _ = std::fs::write("x", "".to_string());
only_sized(&""); // Don't lint. `Sized` is only bound
let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound
let _ = Box::new(&""); // Don't lint. Type parameter appears in return type
ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter
refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't
multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments
}
#[allow(clippy::needless_borrowed_reference)]
@ -201,103 +186,6 @@ mod issue9160 {
}
}
#[derive(Clone, Copy)]
struct X;
impl std::ops::Deref for X {
type Target = X;
fn deref(&self) -> &Self::Target {
self
}
}
fn deref_target_is_x<T>(_: T)
where
T: std::ops::Deref<Target = X>,
{
}
fn multiple_constraints<T, U, V, X, Y>(_: T)
where
T: IntoIterator<Item = U> + IntoIterator<Item = X>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
X: IntoIterator<Item = Y>,
Y: AsRef<std::ffi::OsStr>,
{
}
fn multiple_constraints_normalizes_to_same<T, U, V>(_: T, _: V)
where
T: std::ops::Deref<Target = U>,
U: std::ops::Deref<Target = V>,
{
}
fn only_sized<T>(_: T) {}
fn ref_as_ref_path<T: 'static>(_: &'static T)
where
&'static T: AsRef<std::path::Path>,
{
}
trait RefsOnly {
type Referent;
}
impl<T> RefsOnly for &T {
type Referent = T;
}
fn refs_only<T, U>(_: T)
where
T: RefsOnly<Referent = U>,
{
}
fn multiple_constraints_normalizes_to_different<T, U, V>(_: T, _: U)
where
T: IntoIterator<Item = U>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
{
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
mod copyable_iterator {
#[derive(Clone, Copy)]
struct Iter;
impl Iterator for Iter {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
None
}
}
fn takes_iter(_: impl Iterator) {}
fn dont_warn(mut x: Iter) {
takes_iter(&mut x);
}
#[allow(unused_mut)]
fn warn(mut x: &mut Iter) {
takes_iter(x)
}
}
#[clippy::msrv = "1.52.0"]
mod under_msrv {
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
#[clippy::msrv = "1.53.0"]
mod meets_msrv {
fn foo() {
let _ = std::process::Command::new("ls").args(["-a", "-l"]).status().unwrap();
}
}
fn issue9383() {
// Should not lint because unions need explicit deref when accessing field
use std::mem::ManuallyDrop;
@ -326,184 +214,6 @@ fn issue9383() {
}
}
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
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", &env); // Don't lint. Borrowed by `f`
f(arg);
}
mod significant_drop {
#[derive(Debug)]
struct X;
#[derive(Debug)]
struct Y;
impl Drop for Y {
fn drop(&mut self) {}
}
fn foo(x: X, y: Y) {
debug(x);
debug(&y); // Don't lint. Has significant drop
}
fn debug(_: impl std::fmt::Debug) {}
}
mod used_exactly_once {
fn foo(x: String) {
use_x(x);
}
fn use_x(_: impl AsRef<str>) {}
}
mod used_more_than_once {
fn foo(x: String) {
use_x(&x);
use_x_again(&x);
}
fn use_x(_: impl AsRef<str>) {}
fn use_x_again(_: impl AsRef<str>) {}
}
// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
mod issue_9111 {
struct A;
impl Extend<u8> for A {
fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
unimplemented!()
}
}
impl<'a> Extend<&'a u8> for A {
fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
unimplemented!()
}
}
fn main() {
let mut a = A;
a.extend(&[]); // vs a.extend([]);
}
}
mod issue_9710 {
fn main() {
let string = String::new();
for _i in 0..10 {
f(&string);
}
}
fn f<T: AsRef<str>>(_: T) {}
}
mod issue_9739 {
fn foo<D: std::fmt::Display>(_it: impl IntoIterator<Item = D>) {}
fn main() {
foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
}
mod issue_9739_method_variant {
struct S;
impl S {
fn foo<D: std::fmt::Display>(&self, _it: impl IntoIterator<Item = D>) {}
}
fn main() {
S.foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
}
mod issue_9782 {
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
fn main() {
let a: [u8; 100] = [0u8; 100];
// 100
foo::<[u8; 100]>(a);
foo(a);
// 16
foo::<&[u8]>(&a);
foo(a.as_slice());
// 8
foo::<&[u8; 100]>(&a);
foo(a);
}
}
mod issue_9782_type_relative_variant {
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
fn main() {
let a: [u8; 100] = [0u8; 100];
S::foo::<&[u8; 100]>(&a);
}
}
mod issue_9782_method_variant {
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(&self, t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
fn main() {
let a: [u8; 100] = [0u8; 100];
S.foo::<&[u8; 100]>(&a);
}
}
mod issue_10535 {
static SOME_STATIC: String = String::new();
static UNIT: () = compute(&SOME_STATIC);
pub const fn compute<T>(_: T)
where
T: Copy,
{
}
}
mod issue_10253 {
struct S;
trait X {

View file

@ -131,21 +131,6 @@ fn main() {
0
}
}
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
let _ = std::path::Path::new(".").join(&&".");
deref_target_is_x(&X);
multiple_constraints(&[[""]]);
multiple_constraints_normalizes_to_same(&X, X);
let _ = Some("").unwrap_or(&"");
let _ = std::fs::write("x", &"".to_string());
only_sized(&""); // Don't lint. `Sized` is only bound
let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound
let _ = Box::new(&""); // Don't lint. Type parameter appears in return type
ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter
refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't
multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments
}
#[allow(clippy::needless_borrowed_reference)]
@ -201,103 +186,6 @@ mod issue9160 {
}
}
#[derive(Clone, Copy)]
struct X;
impl std::ops::Deref for X {
type Target = X;
fn deref(&self) -> &Self::Target {
self
}
}
fn deref_target_is_x<T>(_: T)
where
T: std::ops::Deref<Target = X>,
{
}
fn multiple_constraints<T, U, V, X, Y>(_: T)
where
T: IntoIterator<Item = U> + IntoIterator<Item = X>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
X: IntoIterator<Item = Y>,
Y: AsRef<std::ffi::OsStr>,
{
}
fn multiple_constraints_normalizes_to_same<T, U, V>(_: T, _: V)
where
T: std::ops::Deref<Target = U>,
U: std::ops::Deref<Target = V>,
{
}
fn only_sized<T>(_: T) {}
fn ref_as_ref_path<T: 'static>(_: &'static T)
where
&'static T: AsRef<std::path::Path>,
{
}
trait RefsOnly {
type Referent;
}
impl<T> RefsOnly for &T {
type Referent = T;
}
fn refs_only<T, U>(_: T)
where
T: RefsOnly<Referent = U>,
{
}
fn multiple_constraints_normalizes_to_different<T, U, V>(_: T, _: U)
where
T: IntoIterator<Item = U>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
{
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
mod copyable_iterator {
#[derive(Clone, Copy)]
struct Iter;
impl Iterator for Iter {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
None
}
}
fn takes_iter(_: impl Iterator) {}
fn dont_warn(mut x: Iter) {
takes_iter(&mut x);
}
#[allow(unused_mut)]
fn warn(mut x: &mut Iter) {
takes_iter(&mut x)
}
}
#[clippy::msrv = "1.52.0"]
mod under_msrv {
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
#[clippy::msrv = "1.53.0"]
mod meets_msrv {
fn foo() {
let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
}
}
fn issue9383() {
// Should not lint because unions need explicit deref when accessing field
use std::mem::ManuallyDrop;
@ -326,184 +214,6 @@ fn issue9383() {
}
}
fn closure_test() {
let env = "env".to_owned();
let arg = "arg".to_owned();
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", &env); // Don't lint. Borrowed by `f`
f(arg);
}
mod significant_drop {
#[derive(Debug)]
struct X;
#[derive(Debug)]
struct Y;
impl Drop for Y {
fn drop(&mut self) {}
}
fn foo(x: X, y: Y) {
debug(&x);
debug(&y); // Don't lint. Has significant drop
}
fn debug(_: impl std::fmt::Debug) {}
}
mod used_exactly_once {
fn foo(x: String) {
use_x(&x);
}
fn use_x(_: impl AsRef<str>) {}
}
mod used_more_than_once {
fn foo(x: String) {
use_x(&x);
use_x_again(&x);
}
fn use_x(_: impl AsRef<str>) {}
fn use_x_again(_: impl AsRef<str>) {}
}
// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
mod issue_9111 {
struct A;
impl Extend<u8> for A {
fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
unimplemented!()
}
}
impl<'a> Extend<&'a u8> for A {
fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
unimplemented!()
}
}
fn main() {
let mut a = A;
a.extend(&[]); // vs a.extend([]);
}
}
mod issue_9710 {
fn main() {
let string = String::new();
for _i in 0..10 {
f(&string);
}
}
fn f<T: AsRef<str>>(_: T) {}
}
mod issue_9739 {
fn foo<D: std::fmt::Display>(_it: impl IntoIterator<Item = D>) {}
fn main() {
foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
}
mod issue_9739_method_variant {
struct S;
impl S {
fn foo<D: std::fmt::Display>(&self, _it: impl IntoIterator<Item = D>) {}
}
fn main() {
S.foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
}
mod issue_9782 {
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
fn main() {
let a: [u8; 100] = [0u8; 100];
// 100
foo::<[u8; 100]>(a);
foo(a);
// 16
foo::<&[u8]>(&a);
foo(a.as_slice());
// 8
foo::<&[u8; 100]>(&a);
foo(&a);
}
}
mod issue_9782_type_relative_variant {
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
fn main() {
let a: [u8; 100] = [0u8; 100];
S::foo::<&[u8; 100]>(&a);
}
}
mod issue_9782_method_variant {
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(&self, t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
fn main() {
let a: [u8; 100] = [0u8; 100];
S.foo::<&[u8; 100]>(&a);
}
}
mod issue_10535 {
static SOME_STATIC: String = String::new();
static UNIT: () = compute(&SOME_STATIC);
pub const fn compute<T>(_: T)
where
T: Copy,
{
}
}
mod issue_10253 {
struct S;
trait X {

View file

@ -121,101 +121,17 @@ error: this expression creates a reference which is immediately dereferenced by
LL | (&&5).foo();
| ^^^^^ help: change this to: `(&5)`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:135:51
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:136:44
|
LL | let _ = std::path::Path::new(".").join(&&".");
| ^^^^^ help: change this to: `"."`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:137:23
|
LL | deref_target_is_x(&X);
| ^^ help: change this to: `X`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:138:26
|
LL | multiple_constraints(&[[""]]);
| ^^^^^^^ help: change this to: `[[""]]`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:139:45
|
LL | multiple_constraints_normalizes_to_same(&X, X);
| ^^ help: change this to: `X`
error: this expression creates a reference which is immediately dereferenced by the compiler
--> $DIR/needless_borrow.rs:140:32
|
LL | let _ = Some("").unwrap_or(&"");
| ^^^ help: change this to: `""`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:141:33
|
LL | let _ = std::fs::write("x", &"".to_string());
| ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()`
error: this expression borrows a value the compiler would automatically borrow
--> $DIR/needless_borrow.rs:190:13
--> $DIR/needless_borrow.rs:175:13
|
LL | (&self.f)()
| ^^^^^^^^^ help: change this to: `(self.f)`
error: this expression borrows a value the compiler would automatically borrow
--> $DIR/needless_borrow.rs:199:13
--> $DIR/needless_borrow.rs:184:13
|
LL | (&mut self.f)()
| ^^^^^^^^^^^^^ help: change this to: `(self.f)`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:283:20
|
LL | takes_iter(&mut x)
| ^^^^^^ help: change this to: `x`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:297:55
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:335:37
|
LL | let _ = std::fs::write("x", &arg);
| ^^^^ help: change this to: `arg`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:336:37
|
LL | let _ = std::fs::write("x", &loc);
| ^^^^ help: change this to: `loc`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:354:15
|
LL | debug(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:363:15
|
LL | use_x(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrow.rs:457:13
|
LL | foo(&a);
| ^^ help: change this to: `a`
error: aborting due to 36 previous errors
error: aborting due to 22 previous errors

View file

@ -0,0 +1,287 @@
#![warn(clippy::needless_borrows_for_generic_args)]
#![allow(
clippy::unnecessary_to_owned,
clippy::unnecessary_literal_unwrap,
clippy::needless_borrow
)]
use core::ops::Deref;
use std::any::Any;
use std::ffi::OsStr;
use std::fmt::{Debug, Display};
use std::path::Path;
use std::process::Command;
fn main() {
let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap();
let _ = Path::new(".").join(".");
let _ = Any::type_id(&""); // Don't lint. `Any` is only bound
let _ = Box::new(&""); // Don't lint. Type parameter appears in return type
let _ = Some("").unwrap_or(&"");
let _ = std::fs::write("x", "".to_string());
{
#[derive(Clone, Copy)]
struct X;
impl Deref for X {
type Target = X;
fn deref(&self) -> &Self::Target {
self
}
}
fn deref_target_is_x<T: Deref<Target = X>>(_: T) {}
deref_target_is_x(X);
}
{
fn multiple_constraints<T, U, V, X, Y>(_: T)
where
T: IntoIterator<Item = U> + IntoIterator<Item = X>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
X: IntoIterator<Item = Y>,
Y: AsRef<OsStr>,
{
}
multiple_constraints([[""]]);
}
{
#[derive(Clone, Copy)]
struct X;
impl Deref for X {
type Target = X;
fn deref(&self) -> &Self::Target {
self
}
}
fn multiple_constraints_normalizes_to_same<T, U, V>(_: T, _: V)
where
T: Deref<Target = U>,
U: Deref<Target = V>,
{
}
multiple_constraints_normalizes_to_same(X, X);
}
{
fn only_sized<T>(_: T) {}
only_sized(&""); // Don't lint. `Sized` is only bound
}
{
fn ref_as_ref_path<T: 'static>(_: &'static T)
where
&'static T: AsRef<Path>,
{
}
ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter
}
{
trait RefsOnly {
type Referent;
}
impl<T> RefsOnly for &T {
type Referent = T;
}
fn refs_only<T, U>(_: T)
where
T: RefsOnly<Referent = U>,
{
}
refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't
}
{
fn multiple_constraints_normalizes_to_different<T, U, V>(_: T, _: U)
where
T: IntoIterator<Item = U>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
{
}
multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
{
#[derive(Clone, Copy)]
struct Iter;
impl Iterator for Iter {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
None
}
}
fn takes_iter(_: impl Iterator) {}
fn dont_warn(mut x: Iter) {
takes_iter(&mut x);
}
#[allow(unused_mut)]
fn warn(mut x: &mut Iter) {
takes_iter(x)
}
}
#[clippy::msrv = "1.52.0"]
{
let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
};
#[clippy::msrv = "1.53.0"]
{
let _ = Command::new("ls").args(["-a", "-l"]).status().unwrap();
};
{
let env = "env".to_owned();
let arg = "arg".to_owned();
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", &env); // Don't lint. Borrowed by `f`
f(arg);
}
{
#[derive(Debug)]
struct X;
impl Drop for X {
fn drop(&mut self) {}
}
fn f(_: impl Debug) {}
let x = X;
f(&x); // Don't lint. Has significant drop
}
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
f(x);
}
{
fn f(_: impl AsRef<str>) {}
fn f2(_: impl AsRef<str>) {}
let x = String::new();
f(&x);
f2(&x);
}
// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
// issue 9111
{
struct A;
impl Extend<u8> for A {
fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
unimplemented!()
}
}
impl<'a> Extend<&'a u8> for A {
fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
unimplemented!()
}
}
let mut a = A;
a.extend(&[]); // vs a.extend([]);
}
// issue 9710
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
for _ in 0..10 {
f(&x);
}
}
// issue 9739
{
fn foo<D: Display>(_it: impl IntoIterator<Item = D>) {}
foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
{
struct S;
impl S {
fn foo<D: Display>(&self, _it: impl IntoIterator<Item = D>) {}
}
S.foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
// issue 9782
{
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
let a: [u8; 100] = [0u8; 100];
// 100
foo::<[u8; 100]>(a);
foo(a);
// 16
foo::<&[u8]>(&a);
foo(a.as_slice());
// 8
foo::<&[u8; 100]>(&a);
foo(a);
}
{
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
let a: [u8; 100] = [0u8; 100];
S::foo::<&[u8; 100]>(&a);
}
{
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(&self, t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
let a: [u8; 100] = [0u8; 100];
S.foo::<&[u8; 100]>(&a);
}
// issue 10535
{
static SOME_STATIC: String = String::new();
static UNIT: () = compute(&SOME_STATIC);
pub const fn compute<T>(_: T)
where
T: Copy,
{
}
}
}

View file

@ -0,0 +1,287 @@
#![warn(clippy::needless_borrows_for_generic_args)]
#![allow(
clippy::unnecessary_to_owned,
clippy::unnecessary_literal_unwrap,
clippy::needless_borrow
)]
use core::ops::Deref;
use std::any::Any;
use std::ffi::OsStr;
use std::fmt::{Debug, Display};
use std::path::Path;
use std::process::Command;
fn main() {
let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
let _ = Path::new(".").join(&&".");
let _ = Any::type_id(&""); // Don't lint. `Any` is only bound
let _ = Box::new(&""); // Don't lint. Type parameter appears in return type
let _ = Some("").unwrap_or(&"");
let _ = std::fs::write("x", &"".to_string());
{
#[derive(Clone, Copy)]
struct X;
impl Deref for X {
type Target = X;
fn deref(&self) -> &Self::Target {
self
}
}
fn deref_target_is_x<T: Deref<Target = X>>(_: T) {}
deref_target_is_x(&X);
}
{
fn multiple_constraints<T, U, V, X, Y>(_: T)
where
T: IntoIterator<Item = U> + IntoIterator<Item = X>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
X: IntoIterator<Item = Y>,
Y: AsRef<OsStr>,
{
}
multiple_constraints(&[[""]]);
}
{
#[derive(Clone, Copy)]
struct X;
impl Deref for X {
type Target = X;
fn deref(&self) -> &Self::Target {
self
}
}
fn multiple_constraints_normalizes_to_same<T, U, V>(_: T, _: V)
where
T: Deref<Target = U>,
U: Deref<Target = V>,
{
}
multiple_constraints_normalizes_to_same(&X, X);
}
{
fn only_sized<T>(_: T) {}
only_sized(&""); // Don't lint. `Sized` is only bound
}
{
fn ref_as_ref_path<T: 'static>(_: &'static T)
where
&'static T: AsRef<Path>,
{
}
ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter
}
{
trait RefsOnly {
type Referent;
}
impl<T> RefsOnly for &T {
type Referent = T;
}
fn refs_only<T, U>(_: T)
where
T: RefsOnly<Referent = U>,
{
}
refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't
}
{
fn multiple_constraints_normalizes_to_different<T, U, V>(_: T, _: U)
where
T: IntoIterator<Item = U>,
U: IntoIterator<Item = V>,
V: AsRef<str>,
{
}
multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments
}
// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321
{
#[derive(Clone, Copy)]
struct Iter;
impl Iterator for Iter {
type Item = ();
fn next(&mut self) -> Option<Self::Item> {
None
}
}
fn takes_iter(_: impl Iterator) {}
fn dont_warn(mut x: Iter) {
takes_iter(&mut x);
}
#[allow(unused_mut)]
fn warn(mut x: &mut Iter) {
takes_iter(&mut x)
}
}
#[clippy::msrv = "1.52.0"]
{
let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
};
#[clippy::msrv = "1.53.0"]
{
let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
};
{
let env = "env".to_owned();
let arg = "arg".to_owned();
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", &env); // Don't lint. Borrowed by `f`
f(arg);
}
{
#[derive(Debug)]
struct X;
impl Drop for X {
fn drop(&mut self) {}
}
fn f(_: impl Debug) {}
let x = X;
f(&x); // Don't lint. Has significant drop
}
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
f(&x);
}
{
fn f(_: impl AsRef<str>) {}
fn f2(_: impl AsRef<str>) {}
let x = String::new();
f(&x);
f2(&x);
}
// https://github.com/rust-lang/rust-clippy/issues/9111#issuecomment-1277114280
// issue 9111
{
struct A;
impl Extend<u8> for A {
fn extend<T: IntoIterator<Item = u8>>(&mut self, _: T) {
unimplemented!()
}
}
impl<'a> Extend<&'a u8> for A {
fn extend<T: IntoIterator<Item = &'a u8>>(&mut self, _: T) {
unimplemented!()
}
}
let mut a = A;
a.extend(&[]); // vs a.extend([]);
}
// issue 9710
{
fn f(_: impl AsRef<str>) {}
let x = String::new();
for _ in 0..10 {
f(&x);
}
}
// issue 9739
{
fn foo<D: Display>(_it: impl IntoIterator<Item = D>) {}
foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
{
struct S;
impl S {
fn foo<D: Display>(&self, _it: impl IntoIterator<Item = D>) {}
}
S.foo(if std::env::var_os("HI").is_some() {
&[0]
} else {
&[] as &[u32]
});
}
// issue 9782
{
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
let a: [u8; 100] = [0u8; 100];
// 100
foo::<[u8; 100]>(a);
foo(a);
// 16
foo::<&[u8]>(&a);
foo(a.as_slice());
// 8
foo::<&[u8; 100]>(&a);
foo(&a);
}
{
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
let a: [u8; 100] = [0u8; 100];
S::foo::<&[u8; 100]>(&a);
}
{
struct S;
impl S {
fn foo<T: AsRef<[u8]>>(&self, t: T) {
println!("{}", std::mem::size_of::<T>());
let _t: &[u8] = t.as_ref();
}
}
let a: [u8; 100] = [0u8; 100];
S.foo::<&[u8; 100]>(&a);
}
// issue 10535
{
static SOME_STATIC: String = String::new();
static UNIT: () = compute(&SOME_STATIC);
pub const fn compute<T>(_: T)
where
T: Copy,
{
}
}
}

View file

@ -0,0 +1,77 @@
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:16:37
|
LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
|
= note: `-D clippy::needless-borrows-for-generic-args` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_borrows_for_generic_args)]`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:17:33
|
LL | let _ = Path::new(".").join(&&".");
| ^^^^^ help: change this to: `"."`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:21:33
|
LL | let _ = std::fs::write("x", &"".to_string());
| ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:36:27
|
LL | deref_target_is_x(&X);
| ^^ help: change this to: `X`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:49:30
|
LL | multiple_constraints(&[[""]]);
| ^^^^^^^ help: change this to: `[[""]]`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:69:49
|
LL | multiple_constraints_normalizes_to_same(&X, X);
| ^^ help: change this to: `X`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:127:24
|
LL | takes_iter(&mut x)
| ^^^^^^ help: change this to: `x`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:136:41
|
LL | let _ = Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
--> $DIR/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
--> $DIR/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
--> $DIR/needless_borrows_for_generic_args.rs:167:11
|
LL | f(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
--> $DIR/needless_borrows_for_generic_args.rs:247:13
|
LL | foo(&a);
| ^^ help: change this to: `a`
error: aborting due to 12 previous errors

View file

@ -10,7 +10,7 @@
/// unimplemented!();
/// }
/// ```
///
///
/// With an explicit return type it should lint too
/// ```edition2015
/// fn main() -> () {
@ -18,7 +18,7 @@
/// unimplemented!();
/// }
/// ```
///
///
/// This should, too.
/// ```rust
/// fn main() {
@ -26,7 +26,7 @@
/// unimplemented!();
/// }
/// ```
///
///
/// This one too.
/// ```no_run
/// // the fn is not always the first line

Some files were not shown because too many files have changed in this diff Show more