2018-07-28 15:34:52 +00:00
|
|
|
#![warn(clippy::unit_arg)]
|
2020-08-26 23:40:02 +00:00
|
|
|
#![allow(
|
|
|
|
clippy::no_effect,
|
|
|
|
unused_must_use,
|
|
|
|
unused_variables,
|
|
|
|
clippy::unused_unit,
|
|
|
|
clippy::or_fun_call
|
|
|
|
)]
|
2018-01-18 22:02:18 +00:00
|
|
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
fn foo<T: Debug>(t: T) {
|
|
|
|
println!("{:?}", t);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo3<T1: Debug, T2: Debug, T3: Debug>(t1: T1, t2: T2, t3: T3) {
|
|
|
|
println!("{:?}, {:?}, {:?}", t1, t2, t3);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Bar;
|
|
|
|
|
|
|
|
impl Bar {
|
|
|
|
fn bar<T: Debug>(&self, t: T) {
|
|
|
|
println!("{:?}", t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bad() {
|
2018-12-09 22:26:16 +00:00
|
|
|
foo({
|
|
|
|
1;
|
|
|
|
});
|
2018-01-18 22:02:18 +00:00
|
|
|
foo(foo(1));
|
|
|
|
foo({
|
|
|
|
foo(1);
|
|
|
|
foo(2);
|
|
|
|
});
|
|
|
|
let b = Bar;
|
2018-12-09 22:26:16 +00:00
|
|
|
b.bar({
|
|
|
|
1;
|
|
|
|
});
|
2019-08-26 17:35:25 +00:00
|
|
|
taking_multiple_units(foo(0), foo(1));
|
2020-02-17 17:12:01 +00:00
|
|
|
taking_multiple_units(foo(0), {
|
|
|
|
foo(1);
|
|
|
|
foo(2);
|
|
|
|
});
|
|
|
|
taking_multiple_units(
|
|
|
|
{
|
|
|
|
foo(0);
|
|
|
|
foo(1);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
foo(2);
|
|
|
|
foo(3);
|
|
|
|
},
|
|
|
|
);
|
2020-08-20 22:07:56 +00:00
|
|
|
// here Some(foo(2)) isn't the top level statement expression, wrap the suggestion in a block
|
|
|
|
None.or(Some(foo(2)));
|
|
|
|
// in this case, the suggestion can be inlined, no need for a surrounding block
|
|
|
|
// foo(()); foo(()) instead of { foo(()); foo(()) }
|
|
|
|
foo(foo(()))
|
2018-01-18 22:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ok() {
|
|
|
|
foo(());
|
|
|
|
foo(1);
|
|
|
|
foo({ 1 });
|
|
|
|
foo3("a", 3, vec![3]);
|
|
|
|
let b = Bar;
|
|
|
|
b.bar({ 1 });
|
|
|
|
b.bar(());
|
|
|
|
question_mark();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn question_mark() -> Result<(), ()> {
|
|
|
|
Ok(Ok(())?)?;
|
|
|
|
Ok(Ok(()))??;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-01-29 05:22:08 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod issue_2945 {
|
|
|
|
fn unit_fn() -> Result<(), i32> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fallible() -> Result<(), i32> {
|
|
|
|
Ok(unit_fn()?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-26 17:35:25 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
fn returning_expr() -> Option<()> {
|
|
|
|
Some(foo(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn taking_multiple_units(a: (), b: ()) {}
|
|
|
|
|
2018-01-18 22:02:18 +00:00
|
|
|
fn main() {
|
|
|
|
bad();
|
|
|
|
ok();
|
|
|
|
}
|