-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,38 @@ | ||
#![feature(tool_lints)] | ||
#![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)] | ||
#![warn(clippy::explicit_deref_method)] | ||
|
||
use std::ops::{Deref, DerefMut}; | ||
|
||
#[allow(clippy::many_single_char_names, clippy::clone_double_ref)] | ||
#[allow(unused_variables)] | ||
#[warn(clippy::explicit_deref_method)] | ||
fn main() { | ||
let a: &mut String = &mut String::from("foo"); | ||
|
||
// these should require linting | ||
{ | ||
let b: &str = a.deref(); | ||
} | ||
let b: &str = a.deref(); | ||
|
||
{ | ||
let b: &mut str = a.deref_mut(); | ||
} | ||
let b: &mut str = a.deref_mut(); | ||
|
||
{ | ||
let b: String = a.deref().clone(); | ||
} | ||
|
||
{ | ||
let b: usize = a.deref_mut().len(); | ||
} | ||
|
||
{ | ||
let b: &usize = &a.deref().len(); | ||
} | ||
let b: String = a.deref().clone(); | ||
|
||
{ | ||
// only first deref should get linted here | ||
let b: &str = a.deref().deref(); | ||
} | ||
let b: usize = a.deref_mut().len(); | ||
|
||
{ | ||
// both derefs should get linted here | ||
let b: String = format!("{}, {}", a.deref(), a.deref()); | ||
} | ||
let b: &usize = &a.deref().len(); | ||
|
||
// only first deref should get linted here | ||
let b: &str = a.deref().deref(); | ||
|
||
// both derefs should get linted here | ||
let b: String = format!("{}, {}", a.deref(), a.deref()); | ||
|
||
// these should not require linting | ||
{ | ||
let b: &str = &*a; | ||
} | ||
|
||
{ | ||
let b: &mut str = &mut *a; | ||
} | ||
let b: &str = &*a; | ||
|
||
let b: &mut str = &mut *a; | ||
|
||
{ | ||
macro_rules! expr_deref { ($body:expr) => { $body.deref() } } | ||
let b: &str = expr_deref!(a); | ||
macro_rules! expr_deref { | ||
($body:expr) => { | ||
$body.deref() | ||
}; | ||
} | ||
let b: &str = expr_deref!(a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
error: explicit deref method call | ||
--> $DIR/dereference.rs:13:23 | ||
--> $DIR/dereference.rs:10:19 | ||
| | ||
13 | let b: &str = a.deref(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
LL | let b: &str = a.deref(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
| | ||
= note: `-D clippy::explicit-deref-method` implied by `-D warnings` | ||
|
||
error: explicit deref_mut method call | ||
--> $DIR/dereference.rs:17:27 | ||
--> $DIR/dereference.rs:12:23 | ||
| | ||
17 | let b: &mut str = a.deref_mut(); | ||
| ^^^^^^^^^^^^^ help: try this: `&mut *a` | ||
LL | let b: &mut str = a.deref_mut(); | ||
| ^^^^^^^^^^^^^ help: try this: `&mut *a` | ||
|
||
error: explicit deref method call | ||
--> $DIR/dereference.rs:21:25 | ||
--> $DIR/dereference.rs:14:21 | ||
| | ||
21 | let b: String = a.deref().clone(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
LL | let b: String = a.deref().clone(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
|
||
error: explicit deref_mut method call | ||
--> $DIR/dereference.rs:25:24 | ||
--> $DIR/dereference.rs:16:20 | ||
| | ||
25 | let b: usize = a.deref_mut().len(); | ||
| ^^^^^^^^^^^^^ help: try this: `&mut *a` | ||
LL | let b: usize = a.deref_mut().len(); | ||
| ^^^^^^^^^^^^^ help: try this: `&mut *a` | ||
|
||
error: explicit deref method call | ||
--> $DIR/dereference.rs:29:26 | ||
--> $DIR/dereference.rs:18:22 | ||
| | ||
29 | let b: &usize = &a.deref().len(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
LL | let b: &usize = &a.deref().len(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
|
||
error: explicit deref method call | ||
--> $DIR/dereference.rs:34:23 | ||
--> $DIR/dereference.rs:21:19 | ||
| | ||
34 | let b: &str = a.deref().deref(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
LL | let b: &str = a.deref().deref(); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
|
||
error: explicit deref method call | ||
--> $DIR/dereference.rs:39:43 | ||
--> $DIR/dereference.rs:24:39 | ||
| | ||
39 | let b: String = format!("{}, {}", a.deref(), a.deref()); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
|
||
error: explicit deref method call | ||
--> $DIR/dereference.rs:39:54 | ||
--> $DIR/dereference.rs:24:50 | ||
| | ||
39 | let b: String = format!("{}, {}", a.deref(), a.deref()); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
LL | let b: String = format!("{}, {}", a.deref(), a.deref()); | ||
| ^^^^^^^^^ help: try this: `&*a` | ||
|
||
error: aborting due to 8 previous errors | ||
|