Skip to content

Commit 309af43

Browse files
committed
Update type UI tests to use private items
1 parent 2212127 commit 309af43

File tree

6 files changed

+79
-60
lines changed

6 files changed

+79
-60
lines changed

tests/ui/box_vec.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#![warn(clippy::all)]
2-
#![allow(clippy::boxed_local, clippy::needless_pass_by_value)]
3-
#![allow(clippy::blacklisted_name)]
2+
#![allow(
3+
clippy::boxed_local,
4+
clippy::needless_pass_by_value,
5+
clippy::blacklisted_name,
6+
unused
7+
)]
48

59
macro_rules! boxit {
610
($init:expr, $x:ty) => {
@@ -11,22 +15,22 @@ macro_rules! boxit {
1115
fn test_macro() {
1216
boxit!(Vec::new(), Vec<u8>);
1317
}
14-
pub fn test(foo: Box<Vec<bool>>) {
15-
println!("{:?}", foo.get(0))
16-
}
18+
fn test(foo: Box<Vec<bool>>) {}
1719

18-
pub fn test2(foo: Box<dyn Fn(Vec<u32>)>) {
20+
fn test2(foo: Box<dyn Fn(Vec<u32>)>) {
1921
// pass if #31 is fixed
2022
foo(vec![1, 2, 3])
2123
}
2224

23-
pub fn test_local_not_linted() {
25+
fn test_local_not_linted() {
2426
let _: Box<Vec<bool>>;
2527
}
2628

27-
fn main() {
28-
test(Box::new(Vec::new()));
29-
test2(Box::new(|v| println!("{:?}", v)));
30-
test_macro();
31-
test_local_not_linted();
29+
// All of these test should be allowed because they are part of the
30+
// public api and `avoid_breaking_exported_api` is `false` by default.
31+
pub fn pub_test(foo: Box<Vec<bool>>) {}
32+
pub fn pub_test_ret() -> Box<Vec<bool>> {
33+
Box::new(Vec::new())
3234
}
35+
36+
fn main() {}

tests/ui/box_vec.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: you seem to be trying to use `Box<Vec<T>>`. Consider using just `Vec<T>`
2-
--> $DIR/box_vec.rs:14:18
2+
--> $DIR/box_vec.rs:18:14
33
|
4-
LL | pub fn test(foo: Box<Vec<bool>>) {
5-
| ^^^^^^^^^^^^^^
4+
LL | fn test(foo: Box<Vec<bool>>) {}
5+
| ^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::box-vec` implied by `-D warnings`
88
= help: `Vec<T>` is already on the heap, `Box<Vec<T>>` makes an extra allocation

tests/ui/linkedlist.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(associated_type_defaults)]
22
#![warn(clippy::linkedlist)]
3-
#![allow(dead_code, clippy::needless_pass_by_value)]
3+
#![allow(unused, dead_code, clippy::needless_pass_by_value)]
44

55
extern crate alloc;
66
use alloc::collections::linked_list::LinkedList;
@@ -20,24 +20,29 @@ impl Foo for LinkedList<u8> {
2020
const BAR: Option<LinkedList<u8>> = None;
2121
}
2222

23-
struct Bar;
23+
pub struct Bar {
24+
priv_linked_list_field: LinkedList<u8>,
25+
pub pub_linked_list_field: LinkedList<u8>,
26+
}
2427
impl Bar {
2528
fn foo(_: LinkedList<u8>) {}
2629
}
2730

28-
pub fn test(my_favourite_linked_list: LinkedList<u8>) {
29-
println!("{:?}", my_favourite_linked_list)
30-
}
31-
32-
pub fn test_ret() -> Option<LinkedList<u8>> {
33-
unimplemented!();
31+
// All of these test should be trigger the lint because they are not
32+
// part of the public api
33+
fn test(my_favorite_linked_list: LinkedList<u8>) {}
34+
fn test_ret() -> Option<LinkedList<u8>> {
35+
None
3436
}
35-
36-
pub fn test_local_not_linted() {
37+
fn test_local_not_linted() {
3738
let _: LinkedList<u8>;
3839
}
3940

40-
fn main() {
41-
test(LinkedList::new());
42-
test_local_not_linted();
41+
// All of these test should be allowed because they are part of the
42+
// public api and `avoid_breaking_exported_api` is `false` by default.
43+
pub fn pub_test(the_most_awesome_linked_list: LinkedList<u8>) {}
44+
pub fn pub_test_ret() -> Option<LinkedList<u8>> {
45+
None
4346
}
47+
48+
fn main() {}

tests/ui/linkedlist.stderr

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,36 @@ LL | const BAR: Option<LinkedList<u8>>;
4040
= help: a `VecDeque` might work
4141

4242
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
43-
--> $DIR/linkedlist.rs:25:15
43+
--> $DIR/linkedlist.rs:24:29
44+
|
45+
LL | priv_linked_list_field: LinkedList<u8>,
46+
| ^^^^^^^^^^^^^^
47+
|
48+
= help: a `VecDeque` might work
49+
50+
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
51+
--> $DIR/linkedlist.rs:28:15
4452
|
4553
LL | fn foo(_: LinkedList<u8>) {}
4654
| ^^^^^^^^^^^^^^
4755
|
4856
= help: a `VecDeque` might work
4957

5058
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
51-
--> $DIR/linkedlist.rs:28:39
59+
--> $DIR/linkedlist.rs:33:34
5260
|
53-
LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
54-
| ^^^^^^^^^^^^^^
61+
LL | fn test(my_favorite_linked_list: LinkedList<u8>) {}
62+
| ^^^^^^^^^^^^^^
5563
|
5664
= help: a `VecDeque` might work
5765

5866
error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
59-
--> $DIR/linkedlist.rs:32:29
67+
--> $DIR/linkedlist.rs:34:25
6068
|
61-
LL | pub fn test_ret() -> Option<LinkedList<u8>> {
62-
| ^^^^^^^^^^^^^^
69+
LL | fn test_ret() -> Option<LinkedList<u8>> {
70+
| ^^^^^^^^^^^^^^
6371
|
6472
= help: a `VecDeque` might work
6573

66-
error: aborting due to 8 previous errors
74+
error: aborting due to 9 previous errors
6775

tests/ui/rc_mutex.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#![warn(clippy::rc_mutex)]
2-
#![allow(clippy::blacklisted_name)]
2+
#![allow(unused, clippy::blacklisted_name)]
33

44
use std::rc::Rc;
55
use std::sync::Mutex;
66

7-
pub struct MyStruct {
7+
pub struct MyStructWithPrivItem {
88
foo: Rc<Mutex<i32>>,
99
}
1010

11+
pub struct MyStructWithPubItem {
12+
pub foo: Rc<Mutex<i32>>,
13+
}
14+
1115
pub struct SubT<T> {
1216
foo: T,
1317
}
@@ -17,18 +21,16 @@ pub enum MyEnum {
1721
Two,
1822
}
1923

20-
pub fn test1<T>(foo: Rc<Mutex<T>>) {}
21-
22-
pub fn test2(foo: Rc<Mutex<MyEnum>>) {}
24+
// All of these test should be trigger the lint because they are not
25+
// part of the public api
26+
fn test1<T>(foo: Rc<Mutex<T>>) {}
27+
fn test2(foo: Rc<Mutex<MyEnum>>) {}
28+
fn test3(foo: Rc<Mutex<SubT<usize>>>) {}
2329

24-
pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {}
30+
// All of these test should be allowed because they are part of the
31+
// public api and `avoid_breaking_exported_api` is `false` by default.
32+
pub fn pub_test1<T>(foo: Rc<Mutex<T>>) {}
33+
pub fn pub_test2(foo: Rc<Mutex<MyEnum>>) {}
34+
pub fn pub_test3(foo: Rc<Mutex<SubT<usize>>>) {}
2535

26-
fn main() {
27-
test1(Rc::new(Mutex::new(1)));
28-
test2(Rc::new(Mutex::new(MyEnum::One)));
29-
test3(Rc::new(Mutex::new(SubT { foo: 1 })));
30-
31-
let _my_struct = MyStruct {
32-
foo: Rc::new(Mutex::new(1)),
33-
};
34-
}
36+
fn main() {}

tests/ui/rc_mutex.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ LL | foo: Rc<Mutex<i32>>,
88
= help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
99

1010
error: usage of `Rc<Mutex<_>>`
11-
--> $DIR/rc_mutex.rs:20:22
11+
--> $DIR/rc_mutex.rs:26:18
1212
|
13-
LL | pub fn test1<T>(foo: Rc<Mutex<T>>) {}
14-
| ^^^^^^^^^^^^
13+
LL | fn test1<T>(foo: Rc<Mutex<T>>) {}
14+
| ^^^^^^^^^^^^
1515
|
1616
= help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
1717

1818
error: usage of `Rc<Mutex<_>>`
19-
--> $DIR/rc_mutex.rs:22:19
19+
--> $DIR/rc_mutex.rs:27:15
2020
|
21-
LL | pub fn test2(foo: Rc<Mutex<MyEnum>>) {}
22-
| ^^^^^^^^^^^^^^^^^
21+
LL | fn test2(foo: Rc<Mutex<MyEnum>>) {}
22+
| ^^^^^^^^^^^^^^^^^
2323
|
2424
= help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
2525

2626
error: usage of `Rc<Mutex<_>>`
27-
--> $DIR/rc_mutex.rs:24:19
27+
--> $DIR/rc_mutex.rs:28:15
2828
|
29-
LL | pub fn test3(foo: Rc<Mutex<SubT<usize>>>) {}
30-
| ^^^^^^^^^^^^^^^^^^^^^^
29+
LL | fn test3(foo: Rc<Mutex<SubT<usize>>>) {}
30+
| ^^^^^^^^^^^^^^^^^^^^^^
3131
|
3232
= help: consider using `Rc<RefCell<_>>` or `Arc<Mutex<_>>` instead
3333

0 commit comments

Comments
 (0)