2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2019-12-22 22:48:15 -06:00
|
|
|
|
2023-06-06 15:56:57 -05:00
|
|
|
#![allow(unused, clippy::redundant_clone, clippy::useless_vec)]
|
2019-12-22 22:48:15 -06:00
|
|
|
#![warn(clippy::option_as_ref_deref)]
|
|
|
|
|
|
|
|
use std::ffi::{CString, OsString};
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut opt = Some(String::from("123"));
|
|
|
|
|
|
|
|
let _ = opt.clone().as_deref().map(str::len);
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
let _ = opt.clone().as_deref()
|
|
|
|
.map(str::len);
|
|
|
|
|
|
|
|
let _ = opt.as_deref_mut();
|
|
|
|
|
|
|
|
let _ = opt.as_deref();
|
|
|
|
let _ = opt.as_deref();
|
|
|
|
let _ = opt.as_deref_mut();
|
|
|
|
let _ = opt.as_deref_mut();
|
|
|
|
let _ = Some(CString::new(vec![]).unwrap()).as_deref();
|
|
|
|
let _ = Some(OsString::new()).as_deref();
|
|
|
|
let _ = Some(PathBuf::new()).as_deref();
|
|
|
|
let _ = Some(Vec::<()>::new()).as_deref();
|
|
|
|
let _ = Some(Vec::<()>::new()).as_deref_mut();
|
|
|
|
|
|
|
|
let _ = opt.as_deref();
|
|
|
|
let _ = opt.clone().as_deref_mut().map(|x| x.len());
|
|
|
|
|
|
|
|
let vc = vec![String::new()];
|
|
|
|
let _ = Some(1_usize).as_ref().map(|x| vc[*x].as_str()); // should not be linted
|
|
|
|
|
|
|
|
let _: Option<&str> = Some(&String::new()).as_ref().map(|x| x.as_str()); // should not be linted
|
2020-04-06 08:48:38 -05:00
|
|
|
|
|
|
|
let _ = opt.as_deref();
|
|
|
|
let _ = opt.as_deref_mut();
|
2020-08-21 00:23:04 -05:00
|
|
|
|
|
|
|
// Issue #5927
|
|
|
|
let _ = opt.as_deref();
|
2019-12-22 22:48:15 -06:00
|
|
|
}
|
2022-10-21 16:35:39 -05:00
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.39"]
|
2022-10-21 16:35:39 -05:00
|
|
|
fn msrv_1_39() {
|
|
|
|
let opt = Some(String::from("123"));
|
|
|
|
let _ = opt.as_ref().map(String::as_str);
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.40"]
|
2022-10-21 16:35:39 -05:00
|
|
|
fn msrv_1_40() {
|
|
|
|
let opt = Some(String::from("123"));
|
|
|
|
let _ = opt.as_deref();
|
|
|
|
}
|