Skip to content

Commit bfa7a9b

Browse files
committed
Add tests for generic code
1 parent ff4a850 commit bfa7a9b

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

tests/ui/useless_asref.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(useless_asref)]
22

3+
use std::fmt::Debug;
4+
35
struct FakeAsRef;
46

57
#[allow(should_implement_trait)]
@@ -54,6 +56,9 @@ fn not_ok() {
5456
foo_rslice(mrrrrrslice);
5557
}
5658
foo_rrrrmr((&&&&MoreRef).as_ref());
59+
60+
generic_not_ok(mrslice);
61+
generic_ok(mrslice);
5762
}
5863

5964
fn ok() {
@@ -87,7 +92,26 @@ fn ok() {
8792
}
8893
FakeAsRef.as_ref();
8994
foo_rrrrmr(MoreRef.as_ref());
95+
96+
generic_not_ok(arr.as_mut());
97+
generic_ok(&mut arr);
9098
}
99+
100+
fn foo_mrt<T: Debug + ?Sized>(t: &mut T) { println!("{:?}", t); }
101+
fn foo_rt<T: Debug + ?Sized>(t: &T) { println!("{:?}", t); }
102+
103+
fn generic_not_ok<T: AsMut<T> + AsRef<T> + Debug + ?Sized>(mrt: &mut T) {
104+
foo_mrt(mrt.as_mut());
105+
foo_mrt(mrt);
106+
foo_rt(mrt.as_ref());
107+
foo_rt(mrt);
108+
}
109+
110+
fn generic_ok<U: AsMut<T> + AsRef<T> + ?Sized, T: Debug + ?Sized>(mru: &mut U) {
111+
foo_mrt(mru.as_mut());
112+
foo_rt(mru.as_ref());
113+
}
114+
91115
fn main() {
92116
not_ok();
93117
ok();

tests/ui/useless_asref.stderr

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: this call to `as_ref` does nothing
2-
--> $DIR/useless_asref.rs:29:18
2+
--> $DIR/useless_asref.rs:31:18
33
|
4-
29 | foo_rstr(rstr.as_ref());
4+
31 | foo_rstr(rstr.as_ref());
55
| ^^^^^^^^^^^^^ help: try this: `rstr`
66
|
77
note: lint level defined here
@@ -11,50 +11,62 @@ note: lint level defined here
1111
| ^^^^^^^^^^^^^
1212

1313
error: this call to `as_ref` does nothing
14-
--> $DIR/useless_asref.rs:31:20
14+
--> $DIR/useless_asref.rs:33:20
1515
|
16-
31 | foo_rslice(rslice.as_ref());
16+
33 | foo_rslice(rslice.as_ref());
1717
| ^^^^^^^^^^^^^^^ help: try this: `rslice`
1818

1919
error: this call to `as_mut` does nothing
20-
--> $DIR/useless_asref.rs:35:21
20+
--> $DIR/useless_asref.rs:37:21
2121
|
22-
35 | foo_mrslice(mrslice.as_mut());
22+
37 | foo_mrslice(mrslice.as_mut());
2323
| ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
2424

2525
error: this call to `as_ref` does nothing
26-
--> $DIR/useless_asref.rs:37:20
26+
--> $DIR/useless_asref.rs:39:20
2727
|
28-
37 | foo_rslice(mrslice.as_ref());
28+
39 | foo_rslice(mrslice.as_ref());
2929
| ^^^^^^^^^^^^^^^^ help: try this: `mrslice`
3030

3131
error: this call to `as_ref` does nothing
32-
--> $DIR/useless_asref.rs:44:20
32+
--> $DIR/useless_asref.rs:46:20
3333
|
34-
44 | foo_rslice(rrrrrslice.as_ref());
34+
46 | foo_rslice(rrrrrslice.as_ref());
3535
| ^^^^^^^^^^^^^^^^^^^ help: try this: `rrrrrslice`
3636

3737
error: this call to `as_ref` does nothing
38-
--> $DIR/useless_asref.rs:46:18
38+
--> $DIR/useless_asref.rs:48:18
3939
|
40-
46 | foo_rstr(rrrrrstr.as_ref());
40+
48 | foo_rstr(rrrrrstr.as_ref());
4141
| ^^^^^^^^^^^^^^^^^ help: try this: `rrrrrstr`
4242

4343
error: this call to `as_mut` does nothing
44-
--> $DIR/useless_asref.rs:51:21
44+
--> $DIR/useless_asref.rs:53:21
4545
|
46-
51 | foo_mrslice(mrrrrrslice.as_mut());
46+
53 | foo_mrslice(mrrrrrslice.as_mut());
4747
| ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
4848

4949
error: this call to `as_ref` does nothing
50-
--> $DIR/useless_asref.rs:53:20
50+
--> $DIR/useless_asref.rs:55:20
5151
|
52-
53 | foo_rslice(mrrrrrslice.as_ref());
52+
55 | foo_rslice(mrrrrrslice.as_ref());
5353
| ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice`
5454

5555
error: this call to `as_ref` does nothing
56-
--> $DIR/useless_asref.rs:56:16
56+
--> $DIR/useless_asref.rs:58:16
5757
|
58-
56 | foo_rrrrmr((&&&&MoreRef).as_ref());
58+
58 | foo_rrrrmr((&&&&MoreRef).as_ref());
5959
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(&&&&MoreRef)`
6060

61+
error: this call to `as_mut` does nothing
62+
--> $DIR/useless_asref.rs:104:13
63+
|
64+
104 | foo_mrt(mrt.as_mut());
65+
| ^^^^^^^^^^^^ help: try this: `mrt`
66+
67+
error: this call to `as_ref` does nothing
68+
--> $DIR/useless_asref.rs:106:12
69+
|
70+
106 | foo_rt(mrt.as_ref());
71+
| ^^^^^^^^^^^^ help: try this: `mrt`
72+

0 commit comments

Comments
 (0)