rust/tests/ui/option_as_ref_deref.fixed

45 lines
1.2 KiB
Rust
Raw Normal View History

2019-12-23 05:48:15 +01:00
// run-rustfix
#![allow(unused_imports, clippy::redundant_clone)]
#![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 15:48:38 +02:00
let _ = opt.as_deref();
let _ = opt.as_deref_mut();
// Issue #5927
let _ = opt.as_deref();
2019-12-23 05:48:15 +01:00
}