2023-08-24 14:32:12 -05:00
|
|
|
//@aux-build: proc_macros.rs
|
|
|
|
//@no-rustfix: overlapping suggestions
|
2018-07-28 10:34:52 -05:00
|
|
|
#![warn(clippy::unit_arg)]
|
2022-10-06 02:44:38 -05:00
|
|
|
#![allow(unused_must_use, unused_variables)]
|
2020-09-10 10:47:07 -05:00
|
|
|
#![allow(
|
2022-10-06 02:44:38 -05:00
|
|
|
clippy::let_unit_value,
|
|
|
|
clippy::needless_question_mark,
|
|
|
|
clippy::never_loop,
|
2020-09-10 10:47:07 -05:00
|
|
|
clippy::no_effect,
|
2021-01-15 03:56:44 -06:00
|
|
|
clippy::or_fun_call,
|
2022-05-05 09:12:52 -05:00
|
|
|
clippy::self_named_constructors,
|
2022-10-06 02:44:38 -05:00
|
|
|
clippy::uninlined_format_args,
|
|
|
|
clippy::unnecessary_wraps,
|
|
|
|
clippy::unused_unit
|
2020-09-10 10:47:07 -05:00
|
|
|
)]
|
2018-01-18 16:02:18 -06:00
|
|
|
|
2023-03-24 08:04:35 -05:00
|
|
|
extern crate proc_macros;
|
2022-08-11 12:42:16 -05:00
|
|
|
|
2023-03-24 08:04:35 -05:00
|
|
|
use proc_macros::with_span;
|
2018-01-18 16:02:18 -06: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 08:30:50 -06:00
|
|
|
fn baz<T: Debug>(t: T) {
|
|
|
|
foo(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Tr {
|
|
|
|
type Args;
|
|
|
|
fn do_it(args: Self::Args);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A;
|
|
|
|
impl Tr for A {
|
|
|
|
type Args = ();
|
|
|
|
fn do_it(_: Self::Args) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct B;
|
|
|
|
impl Tr for B {
|
|
|
|
type Args = <A as Tr>::Args;
|
|
|
|
|
|
|
|
fn do_it(args: Self::Args) {
|
|
|
|
A::do_it(args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:02:18 -06:00
|
|
|
fn bad() {
|
2018-12-09 16:26:16 -06:00
|
|
|
foo({
|
|
|
|
1;
|
|
|
|
});
|
2018-01-18 16:02:18 -06:00
|
|
|
foo(foo(1));
|
|
|
|
foo({
|
|
|
|
foo(1);
|
|
|
|
foo(2);
|
|
|
|
});
|
|
|
|
let b = Bar;
|
2018-12-09 16:26:16 -06:00
|
|
|
b.bar({
|
|
|
|
1;
|
|
|
|
});
|
2020-06-09 09:36:01 -05:00
|
|
|
taking_multiple_units(foo(0), foo(1));
|
|
|
|
taking_multiple_units(foo(0), {
|
|
|
|
foo(1);
|
|
|
|
foo(2);
|
|
|
|
});
|
|
|
|
taking_multiple_units(
|
|
|
|
{
|
|
|
|
foo(0);
|
|
|
|
foo(1);
|
|
|
|
},
|
|
|
|
{
|
|
|
|
foo(2);
|
|
|
|
foo(3);
|
|
|
|
},
|
|
|
|
);
|
2020-09-10 10:47:07 -05: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(()) }
|
2021-03-12 08:30:50 -06:00
|
|
|
foo(foo(()));
|
2018-01-18 16:02:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn ok() {
|
|
|
|
foo(());
|
|
|
|
foo(1);
|
|
|
|
foo({ 1 });
|
|
|
|
foo3("a", 3, vec![3]);
|
|
|
|
let b = Bar;
|
|
|
|
b.bar({ 1 });
|
|
|
|
b.bar(());
|
|
|
|
question_mark();
|
2021-03-12 08:30:50 -06:00
|
|
|
let named_unit_arg = ();
|
|
|
|
foo(named_unit_arg);
|
|
|
|
baz(());
|
|
|
|
B::do_it(());
|
2018-01-18 16:02:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn question_mark() -> Result<(), ()> {
|
|
|
|
Ok(Ok(())?)?;
|
|
|
|
Ok(Ok(()))??;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-01-28 23:22:08 -06:00
|
|
|
#[allow(dead_code)]
|
|
|
|
mod issue_2945 {
|
|
|
|
fn unit_fn() -> Result<(), i32> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fallible() -> Result<(), i32> {
|
|
|
|
Ok(unit_fn()?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 09:36:01 -05:00
|
|
|
#[allow(dead_code)]
|
|
|
|
fn returning_expr() -> Option<()> {
|
|
|
|
Some(foo(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn taking_multiple_units(a: (), b: ()) {}
|
|
|
|
|
2022-08-11 12:42:16 -05:00
|
|
|
fn proc_macro() {
|
|
|
|
with_span!(span taking_multiple_units(unsafe { (); }, 'x: loop { break 'x (); }));
|
|
|
|
}
|
|
|
|
|
2018-01-18 16:02:18 -06:00
|
|
|
fn main() {
|
|
|
|
bad();
|
|
|
|
ok();
|
|
|
|
}
|