-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #8844 - smoelius:fixed-paths, r=Alexendoo
Check `.fixed` paths' existence in `run_ui` This PR adds a test to check that there exists a `.fixed` file for every `.stderr` file in `tests/ui` that mentions a `MachineApplicable` lint. The test leverages `compiletest-rs`'s `rustfix_coverage` option. I tried to add `.fixed` files where they appeared to be missing. However, 38 exceptional `.rs` files remain. Several of those include comments indicating that they are exceptions, though not all do. Apologies, as I have not tried to associate the 38 files with GH issues. (I think that would be a lot of work, and I worry about linking the wrong issue.) changelog: none
- Loading branch information
Showing
46 changed files
with
1,772 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// run-rustfix | ||
#![deny(clippy::bind_instead_of_map)] | ||
#![allow(clippy::blocks_in_if_conditions)] | ||
|
||
pub fn main() { | ||
let _ = Some("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); | ||
let _ = Some("42").and_then(|s| if s.len() < 42 { None } else { Some(s.len()) }); | ||
|
||
let _ = Ok::<_, ()>("42").map(|s| if s.len() < 42 { 0 } else { s.len() }); | ||
let _ = Ok::<_, ()>("42").and_then(|s| if s.len() < 42 { Err(()) } else { Ok(s.len()) }); | ||
|
||
let _ = Err::<(), _>("42").map_err(|s| if s.len() < 42 { s.len() + 20 } else { s.len() }); | ||
let _ = Err::<(), _>("42").or_else(|s| if s.len() < 42 { Ok(()) } else { Err(s.len()) }); | ||
|
||
hard_example(); | ||
macro_example(); | ||
} | ||
|
||
fn hard_example() { | ||
Some("42").map(|s| { | ||
if { | ||
if s == "43" { | ||
return 43; | ||
} | ||
s == "42" | ||
} { | ||
return 45; | ||
} | ||
match s.len() { | ||
10 => 2, | ||
20 => { | ||
if foo() { | ||
return { | ||
if foo() { | ||
return 20; | ||
} | ||
println!("foo"); | ||
3 | ||
}; | ||
} | ||
20 | ||
}, | ||
40 => 30, | ||
_ => 1, | ||
} | ||
}); | ||
} | ||
|
||
fn foo() -> bool { | ||
true | ||
} | ||
|
||
macro_rules! m { | ||
() => { | ||
Some(10) | ||
}; | ||
} | ||
|
||
fn macro_example() { | ||
let _ = Some("").and_then(|s| if s.len() == 20 { m!() } else { Some(20) }); | ||
let _ = Some("").map(|s| if s.len() == 20 { m!() } else { Some(20) }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// run-rustfix | ||
#![deny(clippy::bind_instead_of_map)] | ||
#![allow(clippy::blocks_in_if_conditions)] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// run-rustfix | ||
#![warn(clippy::implicit_clone)] | ||
#![allow(clippy::clone_on_copy, clippy::redundant_clone)] | ||
use std::borrow::Borrow; | ||
use std::ffi::{OsStr, OsString}; | ||
use std::path::PathBuf; | ||
|
||
fn return_owned_from_slice(slice: &[u32]) -> Vec<u32> { | ||
slice.to_owned() | ||
} | ||
|
||
pub fn own_same<T>(v: T) -> T | ||
where | ||
T: ToOwned<Owned = T>, | ||
{ | ||
v.to_owned() | ||
} | ||
|
||
pub fn own_same_from_ref<T>(v: &T) -> T | ||
where | ||
T: ToOwned<Owned = T>, | ||
{ | ||
v.to_owned() | ||
} | ||
|
||
pub fn own_different<T, U>(v: T) -> U | ||
where | ||
T: ToOwned<Owned = U>, | ||
{ | ||
v.to_owned() | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
struct Kitten; | ||
impl Kitten { | ||
// badly named method | ||
fn to_vec(self) -> Kitten { | ||
Kitten {} | ||
} | ||
} | ||
impl Borrow<BorrowedKitten> for Kitten { | ||
fn borrow(&self) -> &BorrowedKitten { | ||
static VALUE: BorrowedKitten = BorrowedKitten {}; | ||
&VALUE | ||
} | ||
} | ||
|
||
struct BorrowedKitten; | ||
impl ToOwned for BorrowedKitten { | ||
type Owned = Kitten; | ||
fn to_owned(&self) -> Kitten { | ||
Kitten {} | ||
} | ||
} | ||
|
||
mod weird { | ||
#[allow(clippy::ptr_arg)] | ||
pub fn to_vec(v: &Vec<u32>) -> Vec<u32> { | ||
v.clone() | ||
} | ||
} | ||
|
||
fn main() { | ||
let vec = vec![5]; | ||
let _ = return_owned_from_slice(&vec); | ||
let _ = vec.clone(); | ||
let _ = vec.clone(); | ||
|
||
let vec_ref = &vec; | ||
let _ = return_owned_from_slice(vec_ref); | ||
let _ = vec_ref.clone(); | ||
let _ = vec_ref.clone(); | ||
|
||
// we expect no lint for this | ||
let _ = weird::to_vec(&vec); | ||
|
||
// we expect no lints for this | ||
let slice: &[u32] = &[1, 2, 3, 4, 5]; | ||
let _ = return_owned_from_slice(slice); | ||
let _ = slice.to_owned(); | ||
let _ = slice.to_vec(); | ||
|
||
let str = "hello world".to_string(); | ||
let _ = str.clone(); | ||
|
||
// testing w/ an arbitrary type | ||
let kitten = Kitten {}; | ||
let _ = kitten.clone(); | ||
let _ = own_same_from_ref(&kitten); | ||
// this shouln't lint | ||
let _ = kitten.to_vec(); | ||
|
||
// we expect no lints for this | ||
let borrowed = BorrowedKitten {}; | ||
let _ = borrowed.to_owned(); | ||
|
||
let pathbuf = PathBuf::new(); | ||
let _ = pathbuf.clone(); | ||
let _ = pathbuf.clone(); | ||
|
||
let os_string = OsString::from("foo"); | ||
let _ = os_string.clone(); | ||
let _ = os_string.clone(); | ||
|
||
// we expect no lints for this | ||
let os_str = OsStr::new("foo"); | ||
let _ = os_str.to_owned(); | ||
let _ = os_str.to_os_string(); | ||
|
||
// issue #8227 | ||
let pathbuf_ref = &pathbuf; | ||
let pathbuf_ref = &pathbuf_ref; | ||
let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&PathBuf` | ||
let _ = (*pathbuf_ref).clone(); | ||
let pathbuf_ref = &pathbuf_ref; | ||
let _ = pathbuf_ref.to_owned(); // Don't lint. Returns `&&PathBuf` | ||
let _ = (**pathbuf_ref).clone(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.