about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/owned_cow.rs
blob: 0e0f14711b7f820ddeed102704d03c627c941528 (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, String> = Cow::Owned(String::from("Hi!"));
    //~^ ERROR: needlessly owned Cow type
    let y: Cow<'_, Vec<u8>> = Cow::Owned(vec![]);
    //~^ ERROR: needlessly owned Cow type
    let z: Cow<'_, Vec<_>> = Cow::Owned(vec![2_i32]);
    //~^ ERROR: needlessly owned Cow type
    let o: Cow<'_, OsString> = Cow::Owned(OsString::new());
    //~^ ERROR: needlessly owned Cow type
    let c: Cow<'_, CString> = Cow::Owned(CString::new("").unwrap());
    //~^ ERROR: needlessly owned Cow type
    let p: Cow<'_, PathBuf> = Cow::Owned(PathBuf::new());
    //~^ ERROR: needlessly owned Cow type

    // false positive: borrowed type
    let b: Cow<'_, str> = Cow::Borrowed("Hi!");
}