2018-10-06 16:18:06 +00:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
2018-10-11 10:16:22 +00:00
|
|
|
|
2018-07-28 15:34:52 +00:00
|
|
|
|
|
|
|
#![allow(unused, clippy::many_single_char_names)]
|
|
|
|
#![warn(clippy::ptr_arg)]
|
2015-05-04 06:15:24 +00:00
|
|
|
|
2018-04-05 15:59:35 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-21 16:28:17 +00:00
|
|
|
fn do_vec_mut(x: &mut Vec<i64>) { // no error here
|
|
|
|
//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
|
|
|
}
|
|
|
|
|
2015-08-21 16:28:17 +00:00
|
|
|
fn do_str_mut(x: &mut String) { // no error here
|
|
|
|
//Nothing here either
|
|
|
|
}
|
|
|
|
|
2015-05-04 06:15:24 +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;
|
|
|
|
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();
|
|
|
|
let d = a.clone()
|
|
|
|
.clone()
|
|
|
|
.clone();
|
|
|
|
x.clone()
|
2015-10-30 23:48:05 +00:00
|
|
|
}
|
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 {
|
|
|
|
if x.capacity() > 1024 { panic!("Too large!"); }
|
|
|
|
x.clone()
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:59:35 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
fn test_cow_with_ref(c: &Cow<[i32]>) {
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
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)
|
|
|
|
impl Foo2 for String { fn do_string(&self) {} }
|