diff --git a/tests/ui/useless_asref.rs b/tests/ui/useless_asref.rs index ef0174ad71f..8599d67c767 100644 --- a/tests/ui/useless_asref.rs +++ b/tests/ui/useless_asref.rs @@ -1,5 +1,7 @@ #![deny(useless_asref)] +use std::fmt::Debug; + struct FakeAsRef; #[allow(should_implement_trait)] @@ -54,6 +56,9 @@ fn not_ok() { foo_rslice(mrrrrrslice); } foo_rrrrmr((&&&&MoreRef).as_ref()); + + generic_not_ok(mrslice); + generic_ok(mrslice); } fn ok() { @@ -87,7 +92,26 @@ fn ok() { } FakeAsRef.as_ref(); foo_rrrrmr(MoreRef.as_ref()); + + generic_not_ok(arr.as_mut()); + generic_ok(&mut arr); } + +fn foo_mrt(t: &mut T) { println!("{:?}", t); } +fn foo_rt(t: &T) { println!("{:?}", t); } + +fn generic_not_ok + AsRef + Debug + ?Sized>(mrt: &mut T) { + foo_mrt(mrt.as_mut()); + foo_mrt(mrt); + foo_rt(mrt.as_ref()); + foo_rt(mrt); +} + +fn generic_ok + AsRef + ?Sized, T: Debug + ?Sized>(mru: &mut U) { + foo_mrt(mru.as_mut()); + foo_rt(mru.as_ref()); +} + fn main() { not_ok(); ok(); diff --git a/tests/ui/useless_asref.stderr b/tests/ui/useless_asref.stderr index 8cc869ad775..4b6af9b877e 100644 --- a/tests/ui/useless_asref.stderr +++ b/tests/ui/useless_asref.stderr @@ -1,7 +1,7 @@ error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:29:18 + --> $DIR/useless_asref.rs:31:18 | -29 | foo_rstr(rstr.as_ref()); +31 | foo_rstr(rstr.as_ref()); | ^^^^^^^^^^^^^ help: try this: `rstr` | note: lint level defined here @@ -11,50 +11,62 @@ note: lint level defined here | ^^^^^^^^^^^^^ error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:31:20 + --> $DIR/useless_asref.rs:33:20 | -31 | foo_rslice(rslice.as_ref()); +33 | foo_rslice(rslice.as_ref()); | ^^^^^^^^^^^^^^^ help: try this: `rslice` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:35:21 + --> $DIR/useless_asref.rs:37:21 | -35 | foo_mrslice(mrslice.as_mut()); +37 | foo_mrslice(mrslice.as_mut()); | ^^^^^^^^^^^^^^^^ help: try this: `mrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:37:20 + --> $DIR/useless_asref.rs:39:20 | -37 | foo_rslice(mrslice.as_ref()); +39 | foo_rslice(mrslice.as_ref()); | ^^^^^^^^^^^^^^^^ help: try this: `mrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:44:20 + --> $DIR/useless_asref.rs:46:20 | -44 | foo_rslice(rrrrrslice.as_ref()); +46 | foo_rslice(rrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^ help: try this: `rrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:46:18 + --> $DIR/useless_asref.rs:48:18 | -46 | foo_rstr(rrrrrstr.as_ref()); +48 | foo_rstr(rrrrrstr.as_ref()); | ^^^^^^^^^^^^^^^^^ help: try this: `rrrrrstr` error: this call to `as_mut` does nothing - --> $DIR/useless_asref.rs:51:21 + --> $DIR/useless_asref.rs:53:21 | -51 | foo_mrslice(mrrrrrslice.as_mut()); +53 | foo_mrslice(mrrrrrslice.as_mut()); | ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:53:20 + --> $DIR/useless_asref.rs:55:20 | -53 | foo_rslice(mrrrrrslice.as_ref()); +55 | foo_rslice(mrrrrrslice.as_ref()); | ^^^^^^^^^^^^^^^^^^^^ help: try this: `mrrrrrslice` error: this call to `as_ref` does nothing - --> $DIR/useless_asref.rs:56:16 + --> $DIR/useless_asref.rs:58:16 | -56 | foo_rrrrmr((&&&&MoreRef).as_ref()); +58 | foo_rrrrmr((&&&&MoreRef).as_ref()); | ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `(&&&&MoreRef)` +error: this call to `as_mut` does nothing + --> $DIR/useless_asref.rs:104:13 + | +104 | foo_mrt(mrt.as_mut()); + | ^^^^^^^^^^^^ help: try this: `mrt` + +error: this call to `as_ref` does nothing + --> $DIR/useless_asref.rs:106:12 + | +106 | foo_rt(mrt.as_ref()); + | ^^^^^^^^^^^^ help: try this: `mrt` +