-
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.
Add
clippy::result_as_ref_deref
lint
- Loading branch information
1 parent
897f0e4
commit e1a8ff9
Showing
8 changed files
with
304 additions
and
17 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![allow(unused, clippy::redundant_clone, clippy::useless_vec)] | ||
#![warn(clippy::result_as_ref_deref)] | ||
|
||
use std::ffi::{CString, OsString}; | ||
use std::ops::{Deref, DerefMut}; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let mut res = Ok::<_, ()>(String::from("123")); | ||
|
||
let _ = res.clone().as_deref().map(str::len); | ||
|
||
#[rustfmt::skip] | ||
let _ = res.clone().as_deref() | ||
.map(str::len); | ||
|
||
let _ = res.as_deref_mut(); | ||
|
||
let _ = res.as_deref(); | ||
let _ = res.as_deref(); | ||
let _ = res.as_deref_mut(); | ||
let _ = res.as_deref_mut(); | ||
let _ = Ok::<_, ()>(CString::new(vec![]).unwrap()).as_deref(); | ||
let _ = Ok::<_, ()>(OsString::new()).as_deref(); | ||
let _ = Ok::<_, ()>(PathBuf::new()).as_deref(); | ||
let _ = Ok::<_, ()>(Vec::<()>::new()).as_deref(); | ||
let _ = Ok::<_, ()>(Vec::<()>::new()).as_deref_mut(); | ||
|
||
let _ = res.as_deref(); | ||
let _ = res.clone().as_deref_mut().map(|x| x.len()); | ||
|
||
let vc = vec![String::new()]; | ||
let _ = Ok::<_, ()>(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted | ||
|
||
let _: Result<&str, &()> = Ok(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted | ||
|
||
let _ = res.as_deref(); | ||
let _ = res.as_deref_mut(); | ||
|
||
let _ = res.as_deref(); | ||
} | ||
|
||
#[clippy::msrv = "1.46"] | ||
fn msrv_1_46() { | ||
let res = Ok::<_, ()>(String::from("123")); | ||
let _ = res.as_ref().map(String::as_str); | ||
} | ||
|
||
#[clippy::msrv = "1.47"] | ||
fn msrv_1_47() { | ||
let res = Ok::<_, ()>(String::from("123")); | ||
let _ = res.as_deref(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#![allow(unused, clippy::redundant_clone, clippy::useless_vec)] | ||
#![warn(clippy::result_as_ref_deref)] | ||
|
||
use std::ffi::{CString, OsString}; | ||
use std::ops::{Deref, DerefMut}; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let mut res = Ok::<_, ()>(String::from("123")); | ||
|
||
let _ = res.clone().as_ref().map(Deref::deref).map(str::len); | ||
|
||
#[rustfmt::skip] | ||
let _ = res.clone() | ||
.as_ref().map( | ||
Deref::deref | ||
) | ||
.map(str::len); | ||
|
||
let _ = res.as_mut().map(DerefMut::deref_mut); | ||
|
||
let _ = res.as_ref().map(String::as_str); | ||
let _ = res.as_ref().map(|x| x.as_str()); | ||
let _ = res.as_mut().map(String::as_mut_str); | ||
let _ = res.as_mut().map(|x| x.as_mut_str()); | ||
let _ = Ok::<_, ()>(CString::new(vec![]).unwrap()) | ||
.as_ref() | ||
.map(CString::as_c_str); | ||
let _ = Ok::<_, ()>(OsString::new()).as_ref().map(OsString::as_os_str); | ||
let _ = Ok::<_, ()>(PathBuf::new()).as_ref().map(PathBuf::as_path); | ||
let _ = Ok::<_, ()>(Vec::<()>::new()).as_ref().map(Vec::as_slice); | ||
let _ = Ok::<_, ()>(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice); | ||
|
||
let _ = res.as_ref().map(|x| x.deref()); | ||
let _ = res.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len()); | ||
|
||
let vc = vec![String::new()]; | ||
let _ = Ok::<_, ()>(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted | ||
|
||
let _: Result<&str, &()> = Ok(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted | ||
|
||
let _ = res.as_ref().map(|x| &**x); | ||
let _ = res.as_mut().map(|x| &mut **x); | ||
|
||
let _ = res.as_ref().map(std::ops::Deref::deref); | ||
} | ||
|
||
#[clippy::msrv = "1.46"] | ||
fn msrv_1_46() { | ||
let res = Ok::<_, ()>(String::from("123")); | ||
let _ = res.as_ref().map(String::as_str); | ||
} | ||
|
||
#[clippy::msrv = "1.47"] | ||
fn msrv_1_47() { | ||
let res = Ok::<_, ()>(String::from("123")); | ||
let _ = res.as_ref().map(String::as_str); | ||
} |
Oops, something went wrong.