Add run-rustfix where it already passes

This commit is contained in:
Philipp Hansch 2019-01-04 11:22:38 +01:00
parent 756b32e1e2
commit 319f18e54d
No known key found for this signature in database
GPG Key ID: B6FA06A6E0E2665B
30 changed files with 467 additions and 76 deletions

View File

@ -0,0 +1,26 @@
// 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.
// run-rustfix
#[warn(clippy::cast_lossless)]
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
fn main() {
// Test clippy::cast_lossless with casts to floating-point types
f32::from(1i8);
f64::from(1i8);
f32::from(1u8);
f64::from(1u8);
f32::from(1i16);
f64::from(1i16);
f32::from(1u16);
f64::from(1u16);
f64::from(1i32);
f64::from(1u32);
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
#[warn(clippy::cast_lossless)]
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
fn main() {

View File

@ -1,5 +1,5 @@
error: casting i8 to f32 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:14:5
--> $DIR/cast_lossless_float.rs:16:5
|
LL | 1i8 as f32;
| ^^^^^^^^^^ help: try: `f32::from(1i8)`
@ -7,55 +7,55 @@ LL | 1i8 as f32;
= note: `-D clippy::cast-lossless` implied by `-D warnings`
error: casting i8 to f64 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:15:5
--> $DIR/cast_lossless_float.rs:17:5
|
LL | 1i8 as f64;
| ^^^^^^^^^^ help: try: `f64::from(1i8)`
error: casting u8 to f32 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:16:5
--> $DIR/cast_lossless_float.rs:18:5
|
LL | 1u8 as f32;
| ^^^^^^^^^^ help: try: `f32::from(1u8)`
error: casting u8 to f64 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:17:5
--> $DIR/cast_lossless_float.rs:19:5
|
LL | 1u8 as f64;
| ^^^^^^^^^^ help: try: `f64::from(1u8)`
error: casting i16 to f32 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:18:5
--> $DIR/cast_lossless_float.rs:20:5
|
LL | 1i16 as f32;
| ^^^^^^^^^^^ help: try: `f32::from(1i16)`
error: casting i16 to f64 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:19:5
--> $DIR/cast_lossless_float.rs:21:5
|
LL | 1i16 as f64;
| ^^^^^^^^^^^ help: try: `f64::from(1i16)`
error: casting u16 to f32 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:20:5
--> $DIR/cast_lossless_float.rs:22:5
|
LL | 1u16 as f32;
| ^^^^^^^^^^^ help: try: `f32::from(1u16)`
error: casting u16 to f64 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:21:5
--> $DIR/cast_lossless_float.rs:23:5
|
LL | 1u16 as f64;
| ^^^^^^^^^^^ help: try: `f64::from(1u16)`
error: casting i32 to f64 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:22:5
--> $DIR/cast_lossless_float.rs:24:5
|
LL | 1i32 as f64;
| ^^^^^^^^^^^ help: try: `f64::from(1i32)`
error: casting u32 to f64 may become silently lossy if types change
--> $DIR/cast_lossless_float.rs:23:5
--> $DIR/cast_lossless_float.rs:25:5
|
LL | 1u32 as f64;
| ^^^^^^^^^^^ help: try: `f64::from(1u32)`

View File

@ -0,0 +1,34 @@
// 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.
// run-rustfix
#[warn(clippy::cast_lossless)]
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
fn main() {
// Test clippy::cast_lossless with casts to integer types
i16::from(1i8);
i32::from(1i8);
i64::from(1i8);
i16::from(1u8);
i32::from(1u8);
i64::from(1u8);
u16::from(1u8);
u32::from(1u8);
u64::from(1u8);
i32::from(1i16);
i64::from(1i16);
i32::from(1u16);
i64::from(1u16);
u32::from(1u16);
u64::from(1u16);
i64::from(1i32);
i64::from(1u32);
u64::from(1u32);
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
#[warn(clippy::cast_lossless)]
#[allow(clippy::no_effect, clippy::unnecessary_operation)]
fn main() {

View File

@ -1,5 +1,5 @@
error: casting i8 to i16 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:14:5
--> $DIR/cast_lossless_integer.rs:16:5
|
LL | 1i8 as i16;
| ^^^^^^^^^^ help: try: `i16::from(1i8)`
@ -7,103 +7,103 @@ LL | 1i8 as i16;
= note: `-D clippy::cast-lossless` implied by `-D warnings`
error: casting i8 to i32 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:15:5
--> $DIR/cast_lossless_integer.rs:17:5
|
LL | 1i8 as i32;
| ^^^^^^^^^^ help: try: `i32::from(1i8)`
error: casting i8 to i64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:16:5
--> $DIR/cast_lossless_integer.rs:18:5
|
LL | 1i8 as i64;
| ^^^^^^^^^^ help: try: `i64::from(1i8)`
error: casting u8 to i16 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:17:5
--> $DIR/cast_lossless_integer.rs:19:5
|
LL | 1u8 as i16;
| ^^^^^^^^^^ help: try: `i16::from(1u8)`
error: casting u8 to i32 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:18:5
--> $DIR/cast_lossless_integer.rs:20:5
|
LL | 1u8 as i32;
| ^^^^^^^^^^ help: try: `i32::from(1u8)`
error: casting u8 to i64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:19:5
--> $DIR/cast_lossless_integer.rs:21:5
|
LL | 1u8 as i64;
| ^^^^^^^^^^ help: try: `i64::from(1u8)`
error: casting u8 to u16 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:20:5
--> $DIR/cast_lossless_integer.rs:22:5
|
LL | 1u8 as u16;
| ^^^^^^^^^^ help: try: `u16::from(1u8)`
error: casting u8 to u32 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:21:5
--> $DIR/cast_lossless_integer.rs:23:5
|
LL | 1u8 as u32;
| ^^^^^^^^^^ help: try: `u32::from(1u8)`
error: casting u8 to u64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:22:5
--> $DIR/cast_lossless_integer.rs:24:5
|
LL | 1u8 as u64;
| ^^^^^^^^^^ help: try: `u64::from(1u8)`
error: casting i16 to i32 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:23:5
--> $DIR/cast_lossless_integer.rs:25:5
|
LL | 1i16 as i32;
| ^^^^^^^^^^^ help: try: `i32::from(1i16)`
error: casting i16 to i64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:24:5
--> $DIR/cast_lossless_integer.rs:26:5
|
LL | 1i16 as i64;
| ^^^^^^^^^^^ help: try: `i64::from(1i16)`
error: casting u16 to i32 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:25:5
--> $DIR/cast_lossless_integer.rs:27:5
|
LL | 1u16 as i32;
| ^^^^^^^^^^^ help: try: `i32::from(1u16)`
error: casting u16 to i64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:26:5
--> $DIR/cast_lossless_integer.rs:28:5
|
LL | 1u16 as i64;
| ^^^^^^^^^^^ help: try: `i64::from(1u16)`
error: casting u16 to u32 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:27:5
--> $DIR/cast_lossless_integer.rs:29:5
|
LL | 1u16 as u32;
| ^^^^^^^^^^^ help: try: `u32::from(1u16)`
error: casting u16 to u64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:28:5
--> $DIR/cast_lossless_integer.rs:30:5
|
LL | 1u16 as u64;
| ^^^^^^^^^^^ help: try: `u64::from(1u16)`
error: casting i32 to i64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:29:5
--> $DIR/cast_lossless_integer.rs:31:5
|
LL | 1i32 as i64;
| ^^^^^^^^^^^ help: try: `i64::from(1i32)`
error: casting u32 to i64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:30:5
--> $DIR/cast_lossless_integer.rs:32:5
|
LL | 1u32 as i64;
| ^^^^^^^^^^^ help: try: `i64::from(1u32)`
error: casting u32 to u64 may become silently lossy if types change
--> $DIR/cast_lossless_integer.rs:31:5
--> $DIR/cast_lossless_integer.rs:33:5
|
LL | 1u32 as u64;
| ^^^^^^^^^^^ help: try: `u64::from(1u32)`

View File

@ -0,0 +1,39 @@
// 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.
// run-rustfix
fn main() {
let x = 1;
let y = 2;
if x <= y {
// do something
}
if x <= y {
// do something
}
if x >= y {
// do something
}
if x >= y {
// do something
}
if x != y {
// do something
}
if x != y {
// do something
}
if x == y {
// do something
}
if x == y {
// do something
}
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
fn main() {
let x = 1;
let y = 2;

View File

@ -1,5 +1,5 @@
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:13:8
--> $DIR/double_comparison.rs:15:8
|
LL | if x == y || x < y {
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
@ -7,43 +7,43 @@ LL | if x == y || x < y {
= note: `-D clippy::double-comparisons` implied by `-D warnings`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:16:8
--> $DIR/double_comparison.rs:18:8
|
LL | if x < y || x == y {
| ^^^^^^^^^^^^^^^ help: try: `x <= y`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:19:8
--> $DIR/double_comparison.rs:21:8
|
LL | if x == y || x > y {
| ^^^^^^^^^^^^^^^ help: try: `x >= y`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:22:8
--> $DIR/double_comparison.rs:24:8
|
LL | if x > y || x == y {
| ^^^^^^^^^^^^^^^ help: try: `x >= y`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:25:8
--> $DIR/double_comparison.rs:27:8
|
LL | if x < y || x > y {
| ^^^^^^^^^^^^^^ help: try: `x != y`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:28:8
--> $DIR/double_comparison.rs:30:8
|
LL | if x > y || x < y {
| ^^^^^^^^^^^^^^ help: try: `x != y`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:31:8
--> $DIR/double_comparison.rs:33:8
|
LL | if x <= y && x >= y {
| ^^^^^^^^^^^^^^^^ help: try: `x == y`
error: This binary expression can be simplified
--> $DIR/double_comparison.rs:34:8
--> $DIR/double_comparison.rs:36:8
|
LL | if x >= y && x <= y {
| ^^^^^^^^^^^^^^^^ help: try: `x == y`

View File

@ -0,0 +1,19 @@
// 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.
// run-rustfix
fn main() {
println!();
println!();
match "a" {
_ => println!(),
}
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
fn main() {
println!();
println!("");

View File

@ -1,5 +1,5 @@
error: using `println!("")`
--> $DIR/println_empty_string.rs:12:5
--> $DIR/println_empty_string.rs:14:5
|
LL | println!("");
| ^^^^^^^^^^^^ help: replace it with: `println!()`
@ -7,7 +7,7 @@ LL | println!("");
= note: `-D clippy::println-empty-string` implied by `-D warnings`
error: using `println!("")`
--> $DIR/println_empty_string.rs:15:14
--> $DIR/println_empty_string.rs:17:14
|
LL | _ => println!(""),
| ^^^^^^^^^^^^ help: replace it with: `println!()`

View File

@ -0,0 +1,29 @@
// 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.
// run-rustfix
fn main() {
let vec = vec![b'a', b'b', b'c'];
let ptr = vec.as_ptr();
let offset_u8 = 1_u8;
let offset_usize = 1_usize;
let offset_isize = 1_isize;
unsafe {
ptr.add(offset_usize);
ptr.offset(offset_isize as isize);
ptr.offset(offset_u8 as isize);
ptr.wrapping_add(offset_usize);
ptr.wrapping_offset(offset_isize as isize);
ptr.wrapping_offset(offset_u8 as isize);
}
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
fn main() {
let vec = vec![b'a', b'b', b'c'];
let ptr = vec.as_ptr();

View File

@ -1,5 +1,5 @@
error: use of `offset` with a `usize` casted to an `isize`
--> $DIR/ptr_offset_with_cast.rs:19:9
--> $DIR/ptr_offset_with_cast.rs:21:9
|
LL | ptr.offset(offset_usize as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.add(offset_usize)`
@ -7,7 +7,7 @@ LL | ptr.offset(offset_usize as isize);
= note: `-D clippy::ptr-offset-with-cast` implied by `-D warnings`
error: use of `wrapping_offset` with a `usize` casted to an `isize`
--> $DIR/ptr_offset_with_cast.rs:23:9
--> $DIR/ptr_offset_with_cast.rs:25:9
|
LL | ptr.wrapping_offset(offset_usize as isize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr.wrapping_add(offset_usize)`

View File

@ -0,0 +1,61 @@
// 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.
// run-rustfix
use std::collections::HashSet;
fn main() {
let x = "foo";
x.split('x');
x.split("xx");
x.split('x');
let y = "x";
x.split(y);
// Not yet testing for multi-byte characters
// Changing `r.len() == 1` to `r.chars().count() == 1` in `lint_clippy::single_char_pattern`
// should have done this but produced an ICE
//
// We may not want to suggest changing these anyway
// See: https://github.com/rust-lang/rust-clippy/issues/650#issuecomment-184328984
x.split("ß");
x.split("");
x.split("💣");
// Can't use this lint for unicode code points which don't fit in a char
x.split("❤️");
x.contains('x');
x.starts_with('x');
x.ends_with('x');
x.find('x');
x.rfind('x');
x.rsplit('x');
x.split_terminator('x');
x.rsplit_terminator('x');
x.splitn(0, 'x');
x.rsplitn(0, 'x');
x.matches('x');
x.rmatches('x');
x.match_indices('x');
x.rmatch_indices('x');
x.trim_start_matches('x');
x.trim_end_matches('x');
// Make sure we escape characters correctly.
x.split('\n');
let h = HashSet::<String>::new();
h.contains("X"); // should not warn
x.replace(";", ",").split(','); // issue #2978
x.starts_with('\x03'); // issue #2996
// Issue #3204
const S: &str = "#";
x.find(S);
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
use std::collections::HashSet;
fn main() {

View File

@ -1,5 +1,5 @@
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:14:13
--> $DIR/single_char_pattern.rs:16:13
|
LL | x.split("x");
| ^^^ help: try using a char instead: `'x'`
@ -7,115 +7,115 @@ LL | x.split("x");
= note: `-D clippy::single-char-pattern` implied by `-D warnings`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:31:16
--> $DIR/single_char_pattern.rs:33:16
|
LL | x.contains("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:32:19
--> $DIR/single_char_pattern.rs:34:19
|
LL | x.starts_with("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:33:17
--> $DIR/single_char_pattern.rs:35:17
|
LL | x.ends_with("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:34:12
--> $DIR/single_char_pattern.rs:36:12
|
LL | x.find("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:35:13
--> $DIR/single_char_pattern.rs:37:13
|
LL | x.rfind("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:36:14
--> $DIR/single_char_pattern.rs:38:14
|
LL | x.rsplit("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:37:24
--> $DIR/single_char_pattern.rs:39:24
|
LL | x.split_terminator("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:38:25
--> $DIR/single_char_pattern.rs:40:25
|
LL | x.rsplit_terminator("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:39:17
--> $DIR/single_char_pattern.rs:41:17
|
LL | x.splitn(0, "x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:40:18
--> $DIR/single_char_pattern.rs:42:18
|
LL | x.rsplitn(0, "x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:41:15
--> $DIR/single_char_pattern.rs:43:15
|
LL | x.matches("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:42:16
--> $DIR/single_char_pattern.rs:44:16
|
LL | x.rmatches("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:43:21
--> $DIR/single_char_pattern.rs:45:21
|
LL | x.match_indices("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:44:22
--> $DIR/single_char_pattern.rs:46:22
|
LL | x.rmatch_indices("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:45:26
--> $DIR/single_char_pattern.rs:47:26
|
LL | x.trim_start_matches("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:46:24
--> $DIR/single_char_pattern.rs:48:24
|
LL | x.trim_end_matches("x");
| ^^^ help: try using a char instead: `'x'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:48:13
--> $DIR/single_char_pattern.rs:50:13
|
LL | x.split("/n");
| ^^^^ help: try using a char instead: `'/n'`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:53:31
--> $DIR/single_char_pattern.rs:55:31
|
LL | x.replace(";", ",").split(","); // issue #2978
| ^^^ help: try using a char instead: `','`
error: single-character string constant used as pattern
--> $DIR/single_char_pattern.rs:54:19
--> $DIR/single_char_pattern.rs:56:19
|
LL | x.starts_with("/x03"); // issue #2996
| ^^^^^^ help: try using a char instead: `'/x03'`

View File

@ -0,0 +1,41 @@
// 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.
// run-rustfix
#[derive(Copy, Clone)]
struct HasChars;
impl HasChars {
fn chars(self) -> std::str::Chars<'static> {
"HasChars".chars()
}
}
fn main() {
let abc = "abc";
let def = String::from("def");
let mut s = String::new();
s.push_str(abc);
s.push_str(abc);
s.push_str("abc");
s.push_str("abc");
s.push_str(&def);
s.push_str(&def);
s.extend(abc.chars().skip(1));
s.extend("abc".chars().skip(1));
s.extend(['a', 'b', 'c'].iter());
let f = HasChars;
s.extend(f.chars());
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
#[derive(Copy, Clone)]
struct HasChars;

View File

@ -1,5 +1,5 @@
error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:25:5
--> $DIR/string_extend.rs:27:5
|
LL | s.extend(abc.chars());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(abc)`
@ -7,13 +7,13 @@ LL | s.extend(abc.chars());
= note: `-D clippy::string-extend-chars` implied by `-D warnings`
error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:28:5
--> $DIR/string_extend.rs:30:5
|
LL | s.extend("abc".chars());
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str("abc")`
error: calling `.extend(_.chars())`
--> $DIR/string_extend.rs:31:5
--> $DIR/string_extend.rs:33:5
|
LL | s.extend(def.chars());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `s.push_str(&def)`

View File

@ -0,0 +1,29 @@
// 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.
// run-rustfix
#[warn(clippy::unreadable_literal)]
#[allow(unused_variables)]
fn main() {
let good = (
0b1011_i64,
0o1_234_u32,
0x1_234_567,
65536,
1_2345_6789,
1234_f32,
1_234.12_f32,
1_234.123_f32,
1.123_4_f32,
);
let bad = (0b11_0110_i64, 0x0123_4567_8901_usize, 123_456_f32, 1.234_567_f32);
let good_sci = 1.1234e1;
let bad_sci = 1.123_456e1;
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
#[warn(clippy::unreadable_literal)]
#[allow(unused_variables)]
fn main() {

View File

@ -1,5 +1,5 @@
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:24:16
--> $DIR/unreadable_literal.rs:26:16
|
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^^^ help: consider: `0b11_0110_i64`
@ -7,25 +7,25 @@ LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32)
= note: `-D clippy::unreadable-literal` implied by `-D warnings`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:24:30
--> $DIR/unreadable_literal.rs:26:30
|
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^^^^^^^^^^ help: consider: `0x0123_4567_8901_usize`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:24:51
--> $DIR/unreadable_literal.rs:26:51
|
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^ help: consider: `123_456_f32`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:24:63
--> $DIR/unreadable_literal.rs:26:63
|
LL | let bad = (0b110110_i64, 0x12345678901_usize, 123456_f32, 1.234567_f32);
| ^^^^^^^^^^^^ help: consider: `1.234_567_f32`
error: long literal lacking separators
--> $DIR/unreadable_literal.rs:26:19
--> $DIR/unreadable_literal.rs:28:19
|
LL | let bad_sci = 1.123456e1;
| ^^^^^^^^^^ help: consider: `1.123_456e1`

64
tests/ui/vec.fixed Normal file
View File

@ -0,0 +1,64 @@
// 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.
// run-rustfix
#![warn(clippy::useless_vec)]
#[derive(Debug)]
struct NonCopy;
fn on_slice(_: &[u8]) {}
#[allow(clippy::ptr_arg)]
fn on_vec(_: &Vec<u8>) {}
struct Line {
length: usize,
}
impl Line {
fn length(&self) -> usize {
self.length
}
}
fn main() {
on_slice(&[]);
on_slice(&[]);
on_slice(&[1, 2]);
on_slice(&[1, 2]);
on_slice(&[1, 2]);
on_slice(&[1, 2]);
#[rustfmt::skip]
on_slice(&[1, 2]);
on_slice(&[1, 2]);
on_slice(&[1; 2]);
on_slice(&[1; 2]);
on_vec(&vec![]);
on_vec(&vec![1, 2]);
on_vec(&vec![1; 2]);
// Now with non-constant expressions
let line = Line { length: 2 };
on_slice(&vec![2; line.length]);
on_slice(&vec![2; line.length()]);
for a in &[1, 2, 3] {
println!("{:?}", a);
}
for a in vec![NonCopy, NonCopy] {
println!("{:?}", a);
}
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
#![warn(clippy::useless_vec)]
#[derive(Debug)]

View File

@ -1,5 +1,5 @@
error: useless use of `vec!`
--> $DIR/vec.rs:30:14
--> $DIR/vec.rs:32:14
|
LL | on_slice(&vec![]);
| ^^^^^^^ help: you can use a slice directly: `&[]`
@ -7,31 +7,31 @@ LL | on_slice(&vec![]);
= note: `-D clippy::useless-vec` implied by `-D warnings`
error: useless use of `vec!`
--> $DIR/vec.rs:33:14
--> $DIR/vec.rs:35:14
|
LL | on_slice(&vec![1, 2]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]`
error: useless use of `vec!`
--> $DIR/vec.rs:36:14
--> $DIR/vec.rs:38:14
|
LL | on_slice(&vec![1, 2]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]`
error: useless use of `vec!`
--> $DIR/vec.rs:39:14
--> $DIR/vec.rs:41:14
|
LL | on_slice(&vec!(1, 2));
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]`
error: useless use of `vec!`
--> $DIR/vec.rs:42:14
--> $DIR/vec.rs:44:14
|
LL | on_slice(&vec![1; 2]);
| ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]`
error: useless use of `vec!`
--> $DIR/vec.rs:55:14
--> $DIR/vec.rs:57:14
|
LL | for a in vec![1, 2, 3] {
| ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]`

View File

@ -0,0 +1,29 @@
// 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.
// run-rustfix
#![allow(unused_must_use)]
#![warn(clippy::writeln_empty_string)]
use std::io::Write;
fn main() {
let mut v = Vec::new();
// These should fail
writeln!(&mut v);
let mut suggestion = Vec::new();
writeln!(&mut suggestion);
// These should be fine
writeln!(&mut v);
writeln!(&mut v, " ");
write!(&mut v, "");
}

View File

@ -7,6 +7,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// run-rustfix
#![allow(unused_must_use)]
#![warn(clippy::writeln_empty_string)]
use std::io::Write;

View File

@ -1,5 +1,5 @@
error: using `writeln!(&mut v, "")`
--> $DIR/writeln_empty_string.rs:18:5
--> $DIR/writeln_empty_string.rs:20:5
|
LL | writeln!(&mut v, "");
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(&mut v)`
@ -7,7 +7,7 @@ LL | writeln!(&mut v, "");
= note: `-D clippy::writeln-empty-string` implied by `-D warnings`
error: using `writeln!(&mut suggestion, "")`
--> $DIR/writeln_empty_string.rs:21:5
--> $DIR/writeln_empty_string.rs:23:5
|
LL | writeln!(&mut suggestion, "");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(&mut suggestion)`