2021-10-12 14:09:54 +00:00
|
|
|
#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
|
2018-07-28 15:34:52 +00:00
|
|
|
#![warn(clippy::ptr_arg)]
|
2015-05-04 06:15:24 +00:00
|
|
|
|
2018-04-05 15:59:35 +00:00
|
|
|
use std::borrow::Cow;
|
2020-12-25 11:45:04 +00:00
|
|
|
use std::path::PathBuf;
|
2018-04-05 15:59:35 +00:00
|
|
|
|
2017-02-08 13:58:07 +00:00
|
|
|
fn do_vec(x: &Vec<i64>) {
|
2015-08-11 18:22:20 +00:00
|
|
|
//Nothing here
|
2015-05-04 06:15:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn do_vec_mut(x: &mut Vec<i64>) {
|
2015-08-21 16:28:17 +00:00
|
|
|
//Nothing here
|
|
|
|
}
|
|
|
|
|
2017-02-08 13:58:07 +00:00
|
|
|
fn do_str(x: &String) {
|
2015-08-11 18:22:20 +00:00
|
|
|
//Nothing here either
|
2015-05-04 06:15:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn do_str_mut(x: &mut String) {
|
2015-08-21 16:28:17 +00:00
|
|
|
//Nothing here either
|
|
|
|
}
|
|
|
|
|
2020-12-25 11:45:04 +00:00
|
|
|
fn do_path(x: &PathBuf) {
|
|
|
|
//Nothing here either
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_path_mut(x: &mut PathBuf) {
|
|
|
|
//Nothing here either
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn main() {}
|
2015-10-30 23:48:05 +00:00
|
|
|
|
|
|
|
trait Foo {
|
|
|
|
type Item;
|
2017-02-08 13:58:07 +00:00
|
|
|
fn do_vec(x: &Vec<i64>);
|
2015-10-30 23:48:05 +00:00
|
|
|
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>) {}
|
2017-09-16 07:10:26 +00:00
|
|
|
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;
|
2022-01-09 14:35:55 +00:00
|
|
|
let h = g.clone();
|
2017-09-16 07:10:26 +00:00
|
|
|
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 22:26:16 +00:00
|
|
|
let d = a.clone().clone().clone();
|
2017-09-16 07:10:26 +00:00
|
|
|
x.clone()
|
2015-10-30 23:48:05 +00:00
|
|
|
}
|
2017-09-20 21:59:23 +00:00
|
|
|
|
2020-12-25 11:45:04 +00:00
|
|
|
fn path_cloned(x: &PathBuf) -> PathBuf {
|
|
|
|
let a = x.clone();
|
|
|
|
let b = x.clone();
|
|
|
|
let c = b.clone();
|
|
|
|
let d = a.clone().clone().clone();
|
|
|
|
x.clone()
|
|
|
|
}
|
|
|
|
|
2017-09-20 21:59:23 +00:00
|
|
|
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 22:26:16 +00:00
|
|
|
if x.capacity() > 1024 {
|
|
|
|
panic!("Too large!");
|
|
|
|
}
|
2017-09-20 21:59:23 +00:00
|
|
|
x.clone()
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:59:35 +00:00
|
|
|
#[allow(dead_code)]
|
2018-12-09 22:26:16 +00:00
|
|
|
fn test_cow_with_ref(c: &Cow<[i32]>) {}
|
2018-04-05 15:59:35 +00:00
|
|
|
|
|
|
|
fn test_cow(c: Cow<[i32]>) {
|
|
|
|
let _c = c;
|
|
|
|
}
|
2018-09-05 12:59:07 +00:00
|
|
|
|
|
|
|
trait Foo2 {
|
|
|
|
fn do_string(&self);
|
|
|
|
}
|
|
|
|
|
|
|
|
// no error for &self references where self is of type String (#2293)
|
2018-12-09 22:26:16 +00:00
|
|
|
impl Foo2 for String {
|
|
|
|
fn do_string(&self) {}
|
|
|
|
}
|
2020-05-25 21:09:06 +00:00
|
|
|
|
|
|
|
// Check that the allow attribute on parameters is honored
|
|
|
|
mod issue_5644 {
|
|
|
|
use std::borrow::Cow;
|
2020-12-25 11:45:04 +00:00
|
|
|
use std::path::PathBuf;
|
2020-05-25 21:09:06 +00:00
|
|
|
|
|
|
|
fn allowed(
|
|
|
|
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,
|
|
|
|
#[allow(clippy::ptr_arg)] _s: &String,
|
2020-12-25 11:45:04 +00:00
|
|
|
#[allow(clippy::ptr_arg)] _p: &PathBuf,
|
2020-05-25 21:09:06 +00:00
|
|
|
#[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {}
|
|
|
|
impl S {
|
|
|
|
fn allowed(
|
|
|
|
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,
|
|
|
|
#[allow(clippy::ptr_arg)] _s: &String,
|
2020-12-25 11:45:04 +00:00
|
|
|
#[allow(clippy::ptr_arg)] _p: &PathBuf,
|
2020-05-25 21:09:06 +00:00
|
|
|
#[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trait T {
|
|
|
|
fn allowed(
|
|
|
|
#[allow(clippy::ptr_arg)] _v: &Vec<u32>,
|
|
|
|
#[allow(clippy::ptr_arg)] _s: &String,
|
2020-12-25 11:45:04 +00:00
|
|
|
#[allow(clippy::ptr_arg)] _p: &PathBuf,
|
2020-05-25 21:09:06 +00:00
|
|
|
#[allow(clippy::ptr_arg)] _c: &Cow<[i32]>,
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-27 22:09:04 +00:00
|
|
|
|
|
|
|
mod issue6509 {
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
fn foo_vec(vec: &Vec<u8>) {
|
|
|
|
let _ = vec.clone().pop();
|
|
|
|
let _ = vec.clone().clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo_path(path: &PathBuf) {
|
|
|
|
let _ = path.clone().pop();
|
|
|
|
let _ = path.clone().clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo_str(str: &PathBuf) {
|
|
|
|
let _ = str.clone().pop();
|
|
|
|
let _ = str.clone().clone();
|
|
|
|
}
|
|
|
|
}
|
2021-10-27 15:24:00 +00:00
|
|
|
|
2022-01-09 14:35:55 +00:00
|
|
|
fn mut_vec_slice_methods(v: &mut Vec<u32>) {
|
|
|
|
v.copy_within(1..5, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn mut_vec_vec_methods(v: &mut Vec<u32>) {
|
|
|
|
v.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn vec_contains(v: &Vec<u32>) -> bool {
|
|
|
|
[vec![], vec![0]].as_slice().contains(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fn_requires_vec(v: &Vec<u32>) -> bool {
|
|
|
|
vec_contains(v)
|
|
|
|
}
|
|
|
|
|
2022-01-21 14:43:41 +00:00
|
|
|
fn impl_fn_requires_vec(v: &Vec<u32>, f: impl Fn(&Vec<u32>)) {
|
|
|
|
f(v);
|
|
|
|
}
|
2022-01-09 14:35:55 +00:00
|
|
|
|
2022-01-21 14:43:41 +00:00
|
|
|
fn dyn_fn_requires_vec(v: &Vec<u32>, f: &dyn Fn(&Vec<u32>)) {
|
|
|
|
f(v);
|
|
|
|
}
|
2022-01-09 14:35:55 +00:00
|
|
|
|
2021-10-27 15:24:00 +00:00
|
|
|
// No error for types behind an alias (#7699)
|
|
|
|
type A = Vec<u8>;
|
|
|
|
fn aliased(a: &A) {}
|