rust/tests/ui/ptr_arg.rs

87 lines
1.6 KiB
Rust
Raw Normal View History

2019-09-16 10:50:36 -05:00
#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
2018-07-28 10:34:52 -05:00
#![warn(clippy::ptr_arg)]
use std::borrow::Cow;
2017-02-08 07:58:07 -06:00
fn do_vec(x: &Vec<i64>) {
//Nothing here
}
2018-12-09 16:26:16 -06:00
fn do_vec_mut(x: &mut Vec<i64>) {
// no error here
//Nothing here
}
2017-02-08 07:58:07 -06:00
fn do_str(x: &String) {
//Nothing here either
}
2018-12-09 16:26:16 -06:00
fn do_str_mut(x: &mut String) {
// no error here
//Nothing here either
}
2018-12-09 16:26:16 -06:00
fn main() {}
trait Foo {
type Item;
2017-02-08 07:58:07 -06:00
fn do_vec(x: &Vec<i64>);
fn do_item(x: &Self::Item);
}
struct Bar;
// no error, in trait impl (#425)
impl Foo for Bar {
type Item = Vec<u8>;
fn do_vec(x: &Vec<i64>) {}
fn do_item(x: &Vec<u8>) {}
}
fn cloned(x: &Vec<u8>) -> Vec<u8> {
let e = x.clone();
let f = e.clone(); // OK
let g = x;
let h = g.clone(); // Alas, we cannot reliably detect this without following data.
let i = (e).clone();
x.clone()
}
fn str_cloned(x: &String) -> String {
let a = x.clone();
let b = x.clone();
let c = b.clone();
2018-12-09 16:26:16 -06:00
let d = a.clone().clone().clone();
x.clone()
}
fn false_positive_capacity(x: &Vec<u8>, y: &String) {
let a = x.capacity();
let b = y.clone();
let c = y.as_str();
}
fn false_positive_capacity_too(x: &String) -> String {
2018-12-09 16:26:16 -06:00
if x.capacity() > 1024 {
panic!("Too large!");
}
x.clone()
}
#[allow(dead_code)]
2018-12-09 16:26:16 -06:00
fn test_cow_with_ref(c: &Cow<[i32]>) {}
#[allow(dead_code)]
fn test_cow(c: Cow<[i32]>) {
let _c = c;
}
2018-09-05 07:59:07 -05:00
trait Foo2 {
fn do_string(&self);
}
// no error for &self references where self is of type String (#2293)
2018-12-09 16:26:16 -06:00
impl Foo2 for String {
fn do_string(&self) {}
}