From e3a74ed2b5185fbcf55ef815f3b7367d19289a5f Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 22 Nov 2019 14:24:38 +0100 Subject: [PATCH] Set mir_opt_level=0 This introduces some FNs. But a building Clippy is more important for now --- src/driver.rs | 2 + tests/ui/indexing_slicing.stderr | 22 +--------- .../ui/missing_const_for_fn/cant_be_const.rs | 3 ++ tests/ui/redundant_clone.fixed | 9 +++- tests/ui/redundant_clone.rs | 5 +++ tests/ui/redundant_clone.stderr | 42 ++++--------------- 6 files changed, 27 insertions(+), 56 deletions(-) diff --git a/src/driver.rs b/src/driver.rs index 9995c3fb1cec..bd19127b3ce8 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -75,6 +75,8 @@ impl rustc_driver::Callbacks for ClippyCallbacks { clippy_lints::register_pre_expansion_lints(&mut lint_store, &conf); clippy_lints::register_renamed(&mut lint_store); })); + + config.opts.debugging_opts.mir_opt_level = 0; } } diff --git a/tests/ui/indexing_slicing.stderr b/tests/ui/indexing_slicing.stderr index b2840f7b5ccc..0744676d1399 100644 --- a/tests/ui/indexing_slicing.stderr +++ b/tests/ui/indexing_slicing.stderr @@ -1,23 +1,3 @@ -error: index out of bounds: the len is 4 but the index is 4 - --> $DIR/indexing_slicing.rs:18:5 - | -LL | x[4]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^ - | - = note: `#[deny(const_err)]` on by default - -error: index out of bounds: the len is 4 but the index is 8 - --> $DIR/indexing_slicing.rs:19:5 - | -LL | x[1 << 3]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^^^^^^ - -error: index out of bounds: the len is 4 but the index is 15 - --> $DIR/indexing_slicing.rs:54:5 - | -LL | x[N]; // Ok, let rustc's `const_err` lint handle `usize` indexing on arrays. - | ^^^^ - error: indexing may panic. --> $DIR/indexing_slicing.rs:13:5 | @@ -209,5 +189,5 @@ LL | v[M]; | = help: Consider using `.get(n)` or `.get_mut(n)` instead -error: aborting due to 27 previous errors +error: aborting due to 24 previous errors diff --git a/tests/ui/missing_const_for_fn/cant_be_const.rs b/tests/ui/missing_const_for_fn/cant_be_const.rs index 43258be7a971..f367279906fd 100644 --- a/tests/ui/missing_const_for_fn/cant_be_const.rs +++ b/tests/ui/missing_const_for_fn/cant_be_const.rs @@ -32,8 +32,11 @@ fn random_caller() -> u32 { static Y: u32 = 0; +// We should not suggest to make this function `const` because const functions are not allowed to +// refer to a static variable fn get_y() -> u32 { Y + //~^ ERROR E0013 } // Don't lint entrypoint functions diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed index c2c2b2e2dec5..e5e706e8483e 100644 --- a/tests/ui/redundant_clone.fixed +++ b/tests/ui/redundant_clone.fixed @@ -18,11 +18,11 @@ fn main() { let _s = Path::new("/a/b/").join("c"); - let _s = Path::new("/a/b/").join("c"); + let _s = Path::new("/a/b/").join("c").to_path_buf(); let _s = OsString::new(); - let _s = OsString::new(); + let _s = OsString::new().to_os_string(); // Check that lint level works #[allow(clippy::redundant_clone)] @@ -47,6 +47,7 @@ fn main() { let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x` with_branch(Alpha, true); + cannot_double_move(Alpha); cannot_move_from_type_with_drop(); borrower_propagation(); } @@ -61,6 +62,10 @@ fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { } } +fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { + (a.clone(), a) +} + struct TypeWithDrop { x: String, } diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs index 07bd8465841f..9ea2de9a3daa 100644 --- a/tests/ui/redundant_clone.rs +++ b/tests/ui/redundant_clone.rs @@ -47,6 +47,7 @@ fn main() { let _ = Some(String::new()).unwrap_or_else(|| x.0.clone()); // ok; closure borrows `x` with_branch(Alpha, true); + cannot_double_move(Alpha); cannot_move_from_type_with_drop(); borrower_propagation(); } @@ -61,6 +62,10 @@ fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) { } } +fn cannot_double_move(a: Alpha) -> (Alpha, Alpha) { + (a.clone(), a) +} + struct TypeWithDrop { x: String, } diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr index f52d50dbf6bf..62f4ce7645ed 100644 --- a/tests/ui/redundant_clone.stderr +++ b/tests/ui/redundant_clone.stderr @@ -59,18 +59,6 @@ note: this value is dropped without further use LL | let _s = Path::new("/a/b/").join("c").to_owned(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: redundant clone - --> $DIR/redundant_clone.rs:21:42 - | -LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); - | ^^^^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:21:14 - | -LL | let _s = Path::new("/a/b/").join("c").to_path_buf(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error: redundant clone --> $DIR/redundant_clone.rs:23:29 | @@ -83,18 +71,6 @@ note: this value is dropped without further use LL | let _s = OsString::new().to_owned(); | ^^^^^^^^^^^^^^^ -error: redundant clone - --> $DIR/redundant_clone.rs:25:29 - | -LL | let _s = OsString::new().to_os_string(); - | ^^^^^^^^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:25:14 - | -LL | let _s = OsString::new().to_os_string(); - | ^^^^^^^^^^^^^^^ - error: redundant clone --> $DIR/redundant_clone.rs:32:19 | @@ -108,52 +84,52 @@ LL | let _t = tup.0.clone(); | ^^^^^ error: redundant clone - --> $DIR/redundant_clone.rs:58:22 + --> $DIR/redundant_clone.rs:59:22 | LL | (a.clone(), a.clone()) | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:58:21 + --> $DIR/redundant_clone.rs:59:21 | LL | (a.clone(), a.clone()) | ^ error: redundant clone - --> $DIR/redundant_clone.rs:114:15 + --> $DIR/redundant_clone.rs:119:15 | LL | let _s = s.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:114:14 + --> $DIR/redundant_clone.rs:119:14 | LL | let _s = s.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:115:15 + --> $DIR/redundant_clone.rs:120:15 | LL | let _t = t.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:115:14 + --> $DIR/redundant_clone.rs:120:14 | LL | let _t = t.clone(); | ^ error: redundant clone - --> $DIR/redundant_clone.rs:125:19 + --> $DIR/redundant_clone.rs:130:19 | LL | let _f = f.clone(); | ^^^^^^^^ help: remove this | note: this value is dropped without further use - --> $DIR/redundant_clone.rs:125:18 + --> $DIR/redundant_clone.rs:130:18 | LL | let _f = f.clone(); | ^ -error: aborting due to 13 previous errors +error: aborting due to 11 previous errors