Add tests for explicit_deref_methods lints from within proc macros
Signed-off-by: Justus Flügel <justusfluegel@gmail.com>
This commit is contained in:
parent
e513ecc939
commit
3e65620bef
3 changed files with 43 additions and 13 deletions
|
|
@ -1,3 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![warn(clippy::explicit_deref_methods)]
|
||||
#![allow(unused_variables, unused_must_use)]
|
||||
#![allow(
|
||||
|
|
@ -14,6 +15,8 @@
|
|||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
extern crate proc_macros;
|
||||
|
||||
fn concat(deref_str: &str) -> String {
|
||||
format!("{}bar", deref_str)
|
||||
}
|
||||
|
|
@ -121,6 +124,18 @@ fn main() {
|
|||
let b: &str = expr_deref!(&*a);
|
||||
//~^ explicit_deref_methods
|
||||
|
||||
proc_macros::external! {
|
||||
let a: &mut String = &mut String::from("foo");
|
||||
let b: &str = a.deref();
|
||||
}
|
||||
|
||||
// Issue #15168
|
||||
proc_macros::with_span! {
|
||||
span
|
||||
let a: &mut String = &mut String::from("foo");
|
||||
let b: &str = a.deref();
|
||||
}
|
||||
|
||||
// The struct does not implement Deref trait
|
||||
#[derive(Copy, Clone)]
|
||||
struct NoLint(u32);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
#![warn(clippy::explicit_deref_methods)]
|
||||
#![allow(unused_variables, unused_must_use)]
|
||||
#![allow(
|
||||
|
|
@ -14,6 +15,8 @@
|
|||
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
extern crate proc_macros;
|
||||
|
||||
fn concat(deref_str: &str) -> String {
|
||||
format!("{}bar", deref_str)
|
||||
}
|
||||
|
|
@ -121,6 +124,18 @@ fn main() {
|
|||
let b: &str = expr_deref!(a.deref());
|
||||
//~^ explicit_deref_methods
|
||||
|
||||
proc_macros::external! {
|
||||
let a: &mut String = &mut String::from("foo");
|
||||
let b: &str = a.deref();
|
||||
}
|
||||
|
||||
// Issue #15168
|
||||
proc_macros::with_span! {
|
||||
span
|
||||
let a: &mut String = &mut String::from("foo");
|
||||
let b: &str = a.deref();
|
||||
}
|
||||
|
||||
// The struct does not implement Deref trait
|
||||
#[derive(Copy, Clone)]
|
||||
struct NoLint(u32);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:55:19
|
||||
--> tests/ui/explicit_deref_methods.rs:58:19
|
||||
|
|
||||
LL | let b: &str = a.deref();
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
|
@ -8,73 +8,73 @@ LL | let b: &str = a.deref();
|
|||
= help: to override `-D warnings` add `#[allow(clippy::explicit_deref_methods)]`
|
||||
|
||||
error: explicit `deref_mut` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:58:23
|
||||
--> tests/ui/explicit_deref_methods.rs:61:23
|
||||
|
|
||||
LL | let b: &mut str = a.deref_mut();
|
||||
| ^^^^^^^^^^^^^ help: try: `&mut **a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:62:39
|
||||
--> tests/ui/explicit_deref_methods.rs:65:39
|
||||
|
|
||||
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:62:50
|
||||
--> tests/ui/explicit_deref_methods.rs:65:50
|
||||
|
|
||||
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:66:20
|
||||
--> tests/ui/explicit_deref_methods.rs:69:20
|
||||
|
|
||||
LL | println!("{}", a.deref());
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:70:11
|
||||
--> tests/ui/explicit_deref_methods.rs:73:11
|
||||
|
|
||||
LL | match a.deref() {
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:75:28
|
||||
--> tests/ui/explicit_deref_methods.rs:78:28
|
||||
|
|
||||
LL | let b: String = concat(a.deref());
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:78:13
|
||||
--> tests/ui/explicit_deref_methods.rs:81:13
|
||||
|
|
||||
LL | let b = just_return(a).deref();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:81:28
|
||||
--> tests/ui/explicit_deref_methods.rs:84:28
|
||||
|
|
||||
LL | let b: String = concat(just_return(a).deref());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `just_return(a)`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:121:31
|
||||
--> tests/ui/explicit_deref_methods.rs:124:31
|
||||
|
|
||||
LL | let b: &str = expr_deref!(a.deref());
|
||||
| ^^^^^^^^^ help: try: `&*a`
|
||||
|
||||
error: explicit `deref` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:139:14
|
||||
--> tests/ui/explicit_deref_methods.rs:154:14
|
||||
|
|
||||
LL | let _ = &Deref::deref(&"foo");
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `*&"foo"`
|
||||
|
||||
error: explicit `deref_mut` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:141:14
|
||||
--> tests/ui/explicit_deref_methods.rs:156:14
|
||||
|
|
||||
LL | let _ = &DerefMut::deref_mut(&mut x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut **&mut x`
|
||||
|
||||
error: explicit `deref_mut` method call
|
||||
--> tests/ui/explicit_deref_methods.rs:142:14
|
||||
--> tests/ui/explicit_deref_methods.rs:157:14
|
||||
|
|
||||
LL | let _ = &DerefMut::deref_mut((&mut &mut x).deref_mut());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut ***(&mut &mut x)`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue