-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reasons for or remove some
//@no-rustfix
annotations
- Loading branch information
Showing
14 changed files
with
242 additions
and
38 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,132 @@ | ||
#![deny(clippy::borrowed_box)] | ||
#![allow(dead_code, unused_variables)] | ||
#![allow( | ||
clippy::uninlined_format_args, | ||
clippy::disallowed_names, | ||
clippy::needless_pass_by_ref_mut | ||
)] | ||
|
||
use std::fmt::Display; | ||
|
||
pub fn test1(foo: &mut Box<bool>) { | ||
// Although this function could be changed to "&mut bool", | ||
// avoiding the Box, mutable references to boxes are not | ||
// flagged by this lint. | ||
// | ||
// This omission is intentional: By passing a mutable Box, | ||
// the memory location of the pointed-to object could be | ||
// modified. By passing a mutable reference, the contents | ||
// could change, but not the location. | ||
println!("{:?}", foo) | ||
} | ||
|
||
pub fn test2() { | ||
let foo: &bool; | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
} | ||
|
||
struct Test3<'a> { | ||
foo: &'a bool, | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
} | ||
|
||
trait Test4 { | ||
fn test4(a: &bool); | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
} | ||
|
||
use std::any::Any; | ||
|
||
pub fn test5(foo: &mut Box<dyn Any>) { | ||
println!("{:?}", foo) | ||
} | ||
|
||
pub fn test6() { | ||
let foo: &Box<dyn Any>; | ||
} | ||
|
||
struct Test7<'a> { | ||
foo: &'a Box<dyn Any>, | ||
} | ||
|
||
trait Test8 { | ||
fn test8(a: &Box<dyn Any>); | ||
} | ||
|
||
impl<'a> Test8 for Test7<'a> { | ||
fn test8(a: &Box<dyn Any>) { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) { | ||
let _ = foo; | ||
} | ||
|
||
pub fn test10() { | ||
let foo: &Box<dyn Any + Send + 'static>; | ||
} | ||
|
||
struct Test11<'a> { | ||
foo: &'a Box<dyn Any + Send>, | ||
} | ||
|
||
trait Test12 { | ||
fn test4(a: &Box<dyn Any + 'static>); | ||
} | ||
|
||
impl<'a> Test12 for Test11<'a> { | ||
fn test4(a: &Box<dyn Any + 'static>) { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
pub fn test13(boxed_slice: &mut Box<[i32]>) { | ||
// Unconditionally replaces the box pointer. | ||
// | ||
// This cannot be accomplished if "&mut [i32]" is passed, | ||
// and provides a test case where passing a reference to | ||
// a Box is valid. | ||
let mut data = vec![12]; | ||
*boxed_slice = data.into_boxed_slice(); | ||
} | ||
|
||
// The suggestion should include proper parentheses to avoid a syntax error. | ||
pub fn test14(_display: &dyn Display) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
pub fn test15(_display: &(dyn Display + Send)) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
pub fn test16<'a>(_display: &'a (dyn Display + 'a)) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
|
||
pub fn test17(_display: &impl Display) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
pub fn test18(_display: &(impl Display + Send)) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
pub fn test19<'a>(_display: &'a (impl Display + 'a)) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
|
||
// This exists only to check what happens when parentheses are already present. | ||
// Even though the current implementation doesn't put extra parentheses, | ||
// it's fine that unnecessary parentheses appear in the future for some reason. | ||
pub fn test20(_display: &(dyn Display + Send)) {} | ||
//~^ ERROR: you seem to be trying to use `&Box<T>`. Consider using just `&T` | ||
|
||
#[allow(clippy::borrowed_box)] | ||
trait Trait { | ||
fn f(b: &Box<bool>); | ||
} | ||
|
||
// Trait impls are not linted | ||
impl Trait for () { | ||
fn f(_: &Box<bool>) {} | ||
} | ||
|
||
fn main() { | ||
test1(&mut Box::new(false)); | ||
test2(); | ||
test5(&mut (Box::new(false) as Box<dyn Any>)); | ||
test6(); | ||
test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>)); | ||
test10(); | ||
} |
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
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,4 +1,4 @@ | ||
//@no-rustfix | ||
//@no-rustfix: suggests external crate | ||
|
||
#![allow(clippy::needless_borrow, clippy::useless_vec)] | ||
|
||
|
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
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
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,35 @@ | ||
#![warn(clippy::unused_format_specs)] | ||
#![allow(unused)] | ||
|
||
macro_rules! format_args_from_macro { | ||
() => { | ||
format_args!("from macro") | ||
}; | ||
} | ||
|
||
fn main() { | ||
// prints `.`, not ` .` | ||
println!("{:5}.", format!("")); | ||
//~^ ERROR: format specifiers have no effect on `format_args!()` | ||
//~| NOTE: `-D clippy::unused-format-specs` implied by `-D warnings` | ||
//prints `abcde`, not `abc` | ||
println!("{:.3}", format!("abcde")); | ||
//~^ ERROR: format specifiers have no effect on `format_args!()` | ||
|
||
println!("{}.", format_args_from_macro!()); | ||
//~^ ERROR: format specifiers have no effect on `format_args!()` | ||
|
||
let args = format_args!(""); | ||
println!("{args}"); | ||
//~^ ERROR: format specifiers have no effect on `format_args!()` | ||
} | ||
|
||
fn should_not_lint() { | ||
println!("{}", format_args!("")); | ||
// Technically the same as `{}`, but the `format_args` docs specifically mention that you can use | ||
// debug formatting so allow it | ||
println!("{:?}", format_args!("")); | ||
|
||
let args = format_args!(""); | ||
println!("{args}"); | ||
} |
Oops, something went wrong.