2023-02-27 07:07:44 -06:00
|
|
|
#![feature(fn_traits, unboxed_closures)]
|
2021-10-21 06:11:36 -05:00
|
|
|
#![warn(clippy::no_effect_underscore_binding)]
|
2023-03-11 05:44:18 -06:00
|
|
|
#![allow(
|
|
|
|
clippy::deref_addrof,
|
|
|
|
clippy::redundant_field_names,
|
|
|
|
clippy::uninlined_format_args,
|
2023-06-06 15:56:57 -05:00
|
|
|
clippy::unnecessary_struct_initialization,
|
|
|
|
clippy::useless_vec
|
2023-03-11 05:44:18 -06:00
|
|
|
)]
|
2022-06-30 09:17:49 -05:00
|
|
|
|
2023-12-04 01:57:27 -06:00
|
|
|
use std::fmt::Display;
|
2023-12-05 22:17:48 -06:00
|
|
|
use std::ops::{Neg, Shl};
|
2023-12-04 01:57:27 -06:00
|
|
|
|
|
|
|
struct Cout;
|
|
|
|
|
|
|
|
impl<T> Shl<T> for Cout
|
|
|
|
where
|
|
|
|
T: Display,
|
|
|
|
{
|
|
|
|
type Output = Self;
|
|
|
|
fn shl(self, rhs: T) -> Self::Output {
|
|
|
|
println!("{}", rhs);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-05 22:17:48 -06:00
|
|
|
impl Neg for Cout {
|
|
|
|
type Output = Self;
|
|
|
|
fn neg(self) -> Self::Output {
|
|
|
|
println!("hello world");
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 11:50:00 -05:00
|
|
|
struct Tuple(i32);
|
|
|
|
struct Struct {
|
2018-12-09 16:26:16 -06:00
|
|
|
field: i32,
|
2015-10-28 11:50:00 -05:00
|
|
|
}
|
|
|
|
enum Enum {
|
2016-02-01 05:51:33 -06:00
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
2015-10-28 11:50:00 -05:00
|
|
|
}
|
2017-09-18 14:07:33 -05:00
|
|
|
struct DropStruct {
|
2018-12-09 16:26:16 -06:00
|
|
|
field: i32,
|
2017-09-18 14:07:33 -05:00
|
|
|
}
|
|
|
|
impl Drop for DropStruct {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
struct DropTuple(i32);
|
|
|
|
impl Drop for DropTuple {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
enum DropEnum {
|
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
|
|
|
}
|
|
|
|
impl Drop for DropEnum {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
2017-10-07 17:32:09 -05:00
|
|
|
struct FooString {
|
|
|
|
s: String,
|
|
|
|
}
|
2016-08-28 12:43:55 -05:00
|
|
|
union Union {
|
|
|
|
a: u8,
|
|
|
|
b: f64,
|
|
|
|
}
|
|
|
|
|
2018-12-09 16:26:16 -06:00
|
|
|
fn get_number() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
fn get_struct() -> Struct {
|
|
|
|
Struct { field: 0 }
|
|
|
|
}
|
|
|
|
fn get_drop_struct() -> DropStruct {
|
|
|
|
DropStruct { field: 0 }
|
|
|
|
}
|
2015-10-28 11:50:00 -05:00
|
|
|
|
2018-12-09 16:26:16 -06:00
|
|
|
unsafe fn unsafe_fn() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
2016-05-25 11:51:35 -05:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
struct GreetStruct1;
|
|
|
|
|
|
|
|
impl FnOnce<(&str,)> for GreetStruct1 {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
|
|
|
|
println!("hello {}", who);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GreetStruct2();
|
|
|
|
|
|
|
|
impl FnOnce<(&str,)> for GreetStruct2 {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
|
|
|
|
println!("hello {}", who);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:39:59 -05:00
|
|
|
struct GreetStruct3;
|
2021-12-06 05:33:31 -06:00
|
|
|
|
|
|
|
impl FnOnce<(&str,)> for GreetStruct3 {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
extern "rust-call" fn call_once(self, (who,): (&str,)) -> Self::Output {
|
|
|
|
println!("hello {}", who);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-28 11:50:00 -05:00
|
|
|
fn main() {
|
|
|
|
let s = get_struct();
|
|
|
|
|
2017-02-08 07:58:07 -06:00
|
|
|
0;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
Tuple(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
Struct { field: 0 };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
Struct { ..s };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
Union { a: 0 };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
Enum::Tuple(0);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
Enum::Struct { field: 0 };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
5 + 6;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
*&42;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
&6;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
(5, 6, 7);
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
..;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
5..;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
..5;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
5..6;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-09-28 12:40:19 -05:00
|
|
|
5..=6;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
[42, 55];
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
[42, 55][1];
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
(42, 55).1;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
[42; 55];
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-02-08 07:58:07 -06:00
|
|
|
[42; 55][13];
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2016-02-11 06:50:41 -06:00
|
|
|
let mut x = 0;
|
2017-02-08 07:58:07 -06:00
|
|
|
|| x += 5;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2017-10-07 17:32:09 -05:00
|
|
|
let s: String = "foo".into();
|
|
|
|
FooString { s: s };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: statement with no effect
|
2021-10-21 06:11:36 -05:00
|
|
|
let _unused = 1;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
|
|
|
//~| NOTE: `-D clippy::no-effect-underscore-binding` implied by `-D warnings`
|
2021-10-21 06:11:36 -05:00
|
|
|
let _penguin = || println!("Some helpful closure");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
2021-10-21 06:11:36 -05:00
|
|
|
let _duck = Struct { field: 0 };
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
2021-10-21 06:11:36 -05:00
|
|
|
let _cat = [2, 4, 6, 8][2];
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: binding to `_` prefixed variable with no side-effect
|
2024-01-19 16:25:36 -06:00
|
|
|
let _issue_12166 = 42;
|
|
|
|
let underscore_variable_above_can_be_used_dont_lint = _issue_12166;
|
2015-10-28 11:50:00 -05:00
|
|
|
|
2021-06-03 01:41:37 -05:00
|
|
|
#[allow(clippy::no_effect)]
|
|
|
|
0;
|
|
|
|
|
2015-10-28 11:50:00 -05:00
|
|
|
// Do not warn
|
|
|
|
get_number();
|
2016-05-25 11:51:35 -05:00
|
|
|
unsafe { unsafe_fn() };
|
2021-10-21 06:11:36 -05:00
|
|
|
let _used = get_struct();
|
|
|
|
let _x = vec![1];
|
2017-09-18 14:07:33 -05:00
|
|
|
DropStruct { field: 0 };
|
|
|
|
DropTuple(0);
|
|
|
|
DropEnum::Tuple(0);
|
|
|
|
DropEnum::Struct { field: 0 };
|
2021-12-06 05:33:31 -06:00
|
|
|
GreetStruct1("world");
|
|
|
|
GreetStruct2()("world");
|
|
|
|
GreetStruct3 {}("world");
|
2023-12-04 01:57:27 -06:00
|
|
|
|
|
|
|
fn n() -> i32 {
|
|
|
|
42
|
|
|
|
}
|
|
|
|
|
|
|
|
Cout << 142;
|
2023-12-05 22:17:48 -06:00
|
|
|
-Cout;
|
2015-10-28 11:50:00 -05:00
|
|
|
}
|