diff options
| author | bors <bors@rust-lang.org> | 2021-08-12 20:20:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-12 20:20:58 +0000 |
| commit | b4d76b42fd12d963eddafb7e1d9b8559951f73be (patch) | |
| tree | a2976cce333f6e856bd6a65c8d8a6917715488c7 /tests | |
| parent | 7bfc26ec8e7a454786668e7e52ffe527fc649735 (diff) | |
| parent | c02dcd5405cc11270bef963c37837a944a672f6a (diff) | |
| download | rust-b4d76b42fd12d963eddafb7e1d9b8559951f73be.tar.gz rust-b4d76b42fd12d963eddafb7e1d9b8559951f73be.zip | |
Auto merge of #7560 - xFrednet:7289-configuration-for-every-type-lint, r=camsteffen
Use `avoid-breaking-exported-api` configuration in types module This PR empowers our lovely `avoid-breaking-exported-api` configuration value to also influence the emission of lints inside the `types` module. (That's pretty much it, not really a change worthy of writing a fairy tale about. Don't get me wrong, I would love to write a short one, but I sadly need to study now). --- Closes: rust-lang/rust-clippy#7489 changelog: The `avoid-breaking-exported-api` configuration now also works for [`box_vec`], [`redundant_allocation`], [`rc_buffer`], [`vec_box`], [`option_option`], [`linkedlist`], [`rc_mutex`] changelog: [`rc_mutex`]: update the lint message to comply with the normal format --- r? `@camsteffen,` as you implemented the configuration value cc: `@flip1995,` as we've discussed this change in rust-lang/rust-clippy#7308
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/box_vec.rs | 28 | ||||
| -rw-r--r-- | tests/ui/box_vec.stderr | 6 | ||||
| -rw-r--r-- | tests/ui/linkedlist.rs | 31 | ||||
| -rw-r--r-- | tests/ui/linkedlist.stderr | 24 | ||||
| -rw-r--r-- | tests/ui/rc_mutex.rs | 32 | ||||
| -rw-r--r-- | tests/ui/rc_mutex.stderr | 33 |
6 files changed, 90 insertions, 64 deletions
diff --git a/tests/ui/box_vec.rs b/tests/ui/box_vec.rs index 87b67c23704..1d6366972da 100644 --- a/tests/ui/box_vec.rs +++ b/tests/ui/box_vec.rs @@ -1,6 +1,10 @@ #![warn(clippy::all)] -#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] -#![allow(clippy::blacklisted_name)] +#![allow( + clippy::boxed_local, + clippy::needless_pass_by_value, + clippy::blacklisted_name, + unused +)] macro_rules! boxit { ($init:expr, $x:ty) => { @@ -11,22 +15,22 @@ macro_rules! boxit { fn test_macro() { boxit!(Vec::new(), Vec<u8>); } -pub fn test(foo: Box<Vec<bool>>) { - println!("{:?}", foo.get(0)) -} +fn test(foo: Box<Vec<bool>>) {} -pub fn test2(foo: Box<dyn Fn(Vec<u32>)>) { +fn test2(foo: Box<dyn Fn(Vec<u32>)>) { // pass if #31 is fixed foo(vec![1, 2, 3]) } -pub fn test_local_not_linted() { +fn test_local_not_linted() { let _: Box<Vec<bool>>; } -fn main() { - test(Box::new(Vec::new())); - test2(Box::new(|v| println!("{:?}", v))); - test_macro(); - test_local_not_linted(); +// All of these test should be allowed because they are part of the +// public api and `avoid_breaking_exported_api` is `false` by default. +pub fn pub_test(foo: Box<Vec<bool>>) {} +pub fn pub_test_ret() -> Box<Vec<bool>> { + Box::new(Vec::new()) } + +fn main() {} diff --git a/tests/ui/box_vec.stderr b/tests/ui/box_vec.stderr index 9b789334bae..58c1f13fb87 100644 --- a/tests/ui/box_vec.stderr +++ b/tests/ui/box_vec.stderr @@ -1,8 +1,8 @@ error: you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>` - --> $DIR/box_vec.rs:14:18 + --> $DIR/box_vec.rs:18:14 | -LL | pub fn test(foo: Box<Vec<bool>>) { - | ^^^^^^^^^^^^^^ +LL | fn test(foo: Box<Vec<bool>>) {} + | ^^^^^^^^^^^^^^ | = note: `-D clippy::box-vec` implied by `-D warnings` = help: `Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation diff --git a/tests/ui/linkedlist.rs b/tests/ui/linkedlist.rs index 2c3b25cd45e..690ea810a62 100644 --- a/tests/ui/linkedlist.rs +++ b/tests/ui/linkedlist.rs @@ -1,6 +1,6 @@ #![feature(associated_type_defaults)] #![warn(clippy::linkedlist)] -#![allow(dead_code, clippy::needless_pass_by_value)] +#![allow(unused, dead_code, clippy::needless_pass_by_value)] extern crate alloc; use alloc::collections::linked_list::LinkedList; @@ -20,24 +20,29 @@ impl Foo for LinkedList<u8> { const BAR: Option<LinkedList<u8>> = None; } -struct Bar; +pub struct Bar { + priv_linked_list_field: LinkedList<u8>, + pub pub_linked_list_field: LinkedList<u8>, +} impl Bar { fn foo(_: LinkedList<u8>) {} } -pub fn test(my_favourite_linked_list: LinkedList<u8>) { - println!("{:?}", my_favourite_linked_list) -} - -pub fn test_ret() -> Option<LinkedList<u8>> { - unimplemented!(); +// All of these test should be trigger the lint because they are not +// part of the public api +fn test(my_favorite_linked_list: LinkedList<u8>) {} +fn test_ret() -> Option<LinkedList<u8>> { + None } - -pub fn test_local_not_linted() { +fn test_local_not_linted() { let _: LinkedList<u8>; } -fn main() { - test(LinkedList::new()); - test_local_not_linted(); +// All of these test should be allowed because they are part of the +// public api and `avoid_breaking_exported_api` is `false` by default. +pub fn pub_test(the_most_awesome_linked_list: LinkedList<u8>) {} +pub fn pub_test_ret() -> Option<LinkedList<u8>> { + None } + +fn main() {} diff --git a/tests/ui/linkedlist.stderr b/tests/ui/linkedlist.stderr index 38ae71714d6..51327df1321 100644 --- a/tests/ui/linkedlist.stderr +++ b/tests/ui/linkedlist.stderr @@ -40,7 +40,15 @@ LL | const BAR: Option<LinkedList<u8>>; = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:25:15 + --> $DIR/linkedlist.rs:24:29 + | +LL | priv_linked_list_field: LinkedList<u8>, + | ^^^^^^^^^^^^^^ + | + = help: a `VecDeque` might work + +error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? + --> $DIR/linkedlist.rs:28:15 | LL | fn foo(_: LinkedList<u8>) {} | ^^^^^^^^^^^^^^ @@ -48,20 +56,20 @@ LL | fn foo(_: LinkedList<u8>) {} = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:28:39 + --> $DIR/linkedlist.rs:33:34 | -LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) { - | ^^^^^^^^^^^^^^ +LL | fn test(my_favorite_linked_list: LinkedList<u8>) {} + | ^^^^^^^^^^^^^^ | = help: a `VecDeque` might work error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure? - --> $DIR/linkedlist.rs:32:29 + --> $DIR/linkedlist.rs:34:25 | -LL | pub fn test_ret() -> Option<LinkedList<u8>> { - | ^^^^^^^^^^^^^^ +LL | fn test_ret() -> Option<LinkedList<u8>> { + | ^^^^^^^^^^^^^^ | = help: a `VecDeque` might work -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/tests/ui/rc_mutex.rs b/tests/ui/rc_mutex.rs index 657a3ecf6a0..18e8a2e01e0 100644 --- a/tests/ui/rc_mutex.rs +++ b/tests/ui/rc_mutex.rs @@ -1,13 +1,17 @@ #![warn(clippy::rc_mutex)] -#![allow(clippy::blacklisted_name)] +#![allow(unused, clippy::blacklisted_name)] use std::rc::Rc; use std::sync::Mutex; -pub struct MyStruct { +pub struct MyStructWithPrivItem { foo: Rc<Mutex<i32>>, } +pub struct MyStructWithPubItem { + pub foo: Rc<Mutex<i32>>, +} + pub struct SubT<T> { foo: T, } @@ -17,18 +21,16 @@ pub enum MyEnum { Two, } -pub fn test1<T>(foo: Rc<Mutex<T>>) {} - -pub fn test2(foo: Rc<Mutex<MyEnum>>) {} +// All of these test should be trigger the lint because they are not +// part of the public api +fn test1<T>(foo: Rc<Mutex<T>>) {} +fn test2(foo: Rc<Mutex<MyEnum>>) {} +fn test3(foo: Rc<Mutex<SubT<usize>>>) {} -pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {} +// All of these test should be allowed because they are part of the +// public api and `avoid_breaking_exported_api` is `false` by default. +pub fn pub_test1<T>(foo: Rc<Mutex<T>>) {} +pub fn pub_test2(foo: Rc<Mutex<MyEnum>>) {} +pub fn pub_test3(foo: Rc<Mutex<SubT<usize>>>) {} -fn main() { - test1(Rc::new(Mutex::new(1))); - test2(Rc::new(Mutex::new(MyEnum::One))); - test3(Rc::new(Mutex::new(SubT { foo: 1 }))); - - let _my_struct = MyStruct { - foo: Rc::new(Mutex::new(1)), - }; -} +fn main() {} diff --git a/tests/ui/rc_mutex.stderr b/tests/ui/rc_mutex.stderr index 8e58e2bc2d0..fe84361d781 100644 --- a/tests/ui/rc_mutex.stderr +++ b/tests/ui/rc_mutex.stderr @@ -1,28 +1,35 @@ -error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead +error: usage of `Rc<Mutex<_>>` --> $DIR/rc_mutex.rs:8:10 | LL | foo: Rc<Mutex<i32>>, | ^^^^^^^^^^^^^^ | = note: `-D clippy::rc-mutex` implied by `-D warnings` + = help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead -error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead - --> $DIR/rc_mutex.rs:20:22 +error: usage of `Rc<Mutex<_>>` + --> $DIR/rc_mutex.rs:26:18 | -LL | pub fn test1<T>(foo: Rc<Mutex<T>>) {} - | ^^^^^^^^^^^^ +LL | fn test1<T>(foo: Rc<Mutex<T>>) {} + | ^^^^^^^^^^^^ + | + = help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead -error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead - --> $DIR/rc_mutex.rs:22:19 +error: usage of `Rc<Mutex<_>>` + --> $DIR/rc_mutex.rs:27:15 + | +LL | fn test2(foo: Rc<Mutex<MyEnum>>) {} + | ^^^^^^^^^^^^^^^^^ | -LL | pub fn test2(foo: Rc<Mutex<MyEnum>>) {} - | ^^^^^^^^^^^^^^^^^ + = help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead -error: found `Rc<Mutex<_>>`. Consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead - --> $DIR/rc_mutex.rs:24:19 +error: usage of `Rc<Mutex<_>>` + --> $DIR/rc_mutex.rs:28:15 + | +LL | fn test3(foo: Rc<Mutex<SubT<usize>>>) {} + | ^^^^^^^^^^^^^^^^^^^^^^ | -LL | pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {} - | ^^^^^^^^^^^^^^^^^^^^^^ + = help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead error: aborting due to 4 previous errors |
