blob: b62e9107a561e2432b8e859501f410ab32e64b1b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#![warn(clippy::owned_cow)]
use std::borrow::Cow;
use std::ffi::{CString, OsString};
use std::path::PathBuf;
fn main() {
let x: Cow<'static, str> = Cow::Owned(String::from("Hi!"));
//~^ ERROR: needlessly owned Cow type
let y: Cow<'_, [u8]> = Cow::Owned(vec![]);
//~^ ERROR: needlessly owned Cow type
let z: Cow<'_, [_]> = Cow::Owned(vec![2_i32]);
//~^ ERROR: needlessly owned Cow type
let o: Cow<'_, std::ffi::OsStr> = Cow::Owned(OsString::new());
//~^ ERROR: needlessly owned Cow type
let c: Cow<'_, std::ffi::CStr> = Cow::Owned(CString::new("").unwrap());
//~^ ERROR: needlessly owned Cow type
let p: Cow<'_, std::path::Path> = Cow::Owned(PathBuf::new());
//~^ ERROR: needlessly owned Cow type
// false positive: borrowed type
let b: Cow<'_, str> = Cow::Borrowed("Hi!");
}
|