2018-10-06 18:18:06 +02: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 12:16:22 +02:00
|
|
|
|
2017-09-18 12:47:33 +02:00
|
|
|
|
2018-07-28 17:34:52 +02:00
|
|
|
#[warn(clippy::string_add)]
|
|
|
|
#[allow(clippy::string_add_assign)]
|
2018-10-05 18:06:05 +02:00
|
|
|
fn add_only() {
|
|
|
|
// ignores assignment distinction
|
2017-02-07 21:05:30 +01:00
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 14:58:07 +01:00
|
|
|
x = x + ".";
|
2017-02-07 21:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
2017-02-08 14:58:07 +01:00
|
|
|
let z = y + "...";
|
2017-02-07 21:05:30 +01:00
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2018-07-28 17:34:52 +02:00
|
|
|
#[warn(clippy::string_add_assign)]
|
2017-02-07 21:05:30 +01:00
|
|
|
fn add_assign_only() {
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 14:58:07 +01:00
|
|
|
x = x + ".";
|
2017-02-07 21:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
|
|
|
let z = y + "...";
|
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
2018-07-28 17:34:52 +02:00
|
|
|
#[warn(clippy::string_add, clippy::string_add_assign)]
|
2017-02-07 21:05:30 +01:00
|
|
|
fn both() {
|
|
|
|
let mut x = "".to_owned();
|
|
|
|
|
|
|
|
for _ in 1..3 {
|
2017-02-08 14:58:07 +01:00
|
|
|
x = x + ".";
|
2017-02-07 21:05:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
let y = "".to_owned();
|
2017-02-08 14:58:07 +01:00
|
|
|
let z = y + "...";
|
2017-02-07 21:05:30 +01:00
|
|
|
|
|
|
|
assert_eq!(&x, &z);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code, unused_variables)]
|
2018-07-28 17:34:52 +02:00
|
|
|
#[warn(clippy::string_lit_as_bytes)]
|
2017-02-07 21:05:30 +01:00
|
|
|
fn str_lit_as_bytes() {
|
|
|
|
let bs = "hello there".as_bytes();
|
2017-02-08 14:58:07 +01:00
|
|
|
|
2018-10-24 17:49:39 +02:00
|
|
|
let bs = r###"raw string with three ### in it and some " ""###.as_bytes();
|
|
|
|
|
2017-02-07 21:05:30 +01:00
|
|
|
// no warning, because this cannot be written as a byte string literal:
|
|
|
|
let ubs = "☃".as_bytes();
|
|
|
|
|
|
|
|
let strify = stringify!(foobar).as_bytes();
|
2018-10-05 18:06:05 +02:00
|
|
|
|
|
|
|
let includestr = include_str!("entry.rs").as_bytes();
|
2017-02-07 21:05:30 +01:00
|
|
|
}
|
|
|
|
|
2018-10-24 17:49:39 +02:00
|
|
|
#[allow(clippy::assign_op_pattern)]
|
2017-02-07 21:05:30 +01:00
|
|
|
fn main() {
|
|
|
|
add_only();
|
|
|
|
add_assign_only();
|
|
|
|
both();
|
|
|
|
|
|
|
|
// the add is only caught for `String`
|
|
|
|
let mut x = 1;
|
2018-10-24 17:49:39 +02:00
|
|
|
x = x + 1;
|
2017-02-07 21:05:30 +01:00
|
|
|
assert_eq!(2, x);
|
|
|
|
}
|