rust-clippy/tests/ui/unused_unit.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

2019-03-07 06:21:41 +00:00
// run-rustfix
2018-09-27 17:10:20 +00:00
// The output for humans should just highlight the whole span without showing
// the suggested replacement, but we also want to test that suggested
// replacement only removes one set of parentheses, rather than naïvely
// stripping away any starting or ending parenthesis characters—hence this
// test of the JSON error format.
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
2018-09-27 17:10:20 +00:00
2019-03-07 06:21:41 +00:00
#![deny(clippy::unused_unit)]
2018-09-27 17:10:20 +00:00
struct Unitter;
impl Unitter {
// try to disorient the lint with multiple unit returns and newlines
2019-03-07 06:21:41 +00:00
#[allow(clippy::no_effect)]
2018-09-27 17:10:20 +00:00
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
()
where G: Fn() -> () {
let _y: &Fn() -> () = &f;
(); // this should not lint, as it's not in return type position
}
}
impl Into<()> for Unitter {
#[rustfmt::skip]
2018-09-27 17:10:20 +00:00
fn into(self) -> () {
()
}
}
fn return_unit() -> () { () }
2019-03-07 06:21:41 +00:00
#[allow(clippy::needless_return)]
#[allow(clippy::never_loop)]
2018-09-27 17:10:20 +00:00
fn main() {
let u = Unitter;
assert_eq!(u.get_unit(|| {}, return_unit), u.into());
return_unit();
loop {
break();
}
return();
}