2023-02-27 13:07:44 +00:00
|
|
|
#![feature(fn_traits, unboxed_closures)]
|
2021-10-21 11:11:36 +00:00
|
|
|
#![warn(clippy::no_effect_underscore_binding)]
|
2022-10-06 07:44:38 +00:00
|
|
|
#![allow(dead_code, path_statements)]
|
2023-03-24 13:04:35 +00:00
|
|
|
#![allow(
|
|
|
|
clippy::deref_addrof,
|
|
|
|
clippy::redundant_field_names,
|
|
|
|
clippy::uninlined_format_args,
|
2023-07-02 12:35:19 +00:00
|
|
|
clippy::unnecessary_struct_initialization,
|
|
|
|
clippy::useless_vec
|
2023-03-24 13:04:35 +00:00
|
|
|
)]
|
2022-06-30 14:17:49 +00:00
|
|
|
|
2015-10-28 16:50:00 +00:00
|
|
|
struct Unit;
|
|
|
|
struct Tuple(i32);
|
|
|
|
struct Struct {
|
2018-12-09 22:26:16 +00:00
|
|
|
field: i32,
|
2015-10-28 16:50:00 +00:00
|
|
|
}
|
|
|
|
enum Enum {
|
2016-02-01 11:51:33 +00:00
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
2015-10-28 16:50:00 +00:00
|
|
|
}
|
2017-09-18 19:07:33 +00:00
|
|
|
struct DropUnit;
|
|
|
|
impl Drop for DropUnit {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
struct DropStruct {
|
2018-12-09 22:26:16 +00:00
|
|
|
field: i32,
|
2017-09-18 19:07:33 +00: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 22:32:09 +00:00
|
|
|
struct FooString {
|
|
|
|
s: String,
|
|
|
|
}
|
2016-08-28 17:43:55 +00:00
|
|
|
union Union {
|
|
|
|
a: u8,
|
|
|
|
b: f64,
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn get_number() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
fn get_struct() -> Struct {
|
|
|
|
Struct { field: 0 }
|
|
|
|
}
|
|
|
|
fn get_drop_struct() -> DropStruct {
|
|
|
|
DropStruct { field: 0 }
|
|
|
|
}
|
2015-10-28 16:50:00 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
unsafe fn unsafe_fn() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
2016-05-25 16:51:35 +00:00
|
|
|
|
2021-12-06 11:33:31 +00: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 17:39:59 +00:00
|
|
|
struct GreetStruct3;
|
2021-12-06 11:33:31 +00: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 16:50:00 +00:00
|
|
|
fn main() {
|
|
|
|
let s = get_struct();
|
2016-02-11 12:50:41 +00:00
|
|
|
let s2 = get_struct();
|
2015-10-28 16:50:00 +00:00
|
|
|
|
2017-02-08 13:58:07 +00:00
|
|
|
0;
|
|
|
|
s2;
|
|
|
|
Unit;
|
|
|
|
Tuple(0);
|
|
|
|
Struct { field: 0 };
|
|
|
|
Struct { ..s };
|
|
|
|
Union { a: 0 };
|
|
|
|
Enum::Tuple(0);
|
|
|
|
Enum::Struct { field: 0 };
|
|
|
|
5 + 6;
|
|
|
|
*&42;
|
|
|
|
&6;
|
|
|
|
(5, 6, 7);
|
|
|
|
..;
|
|
|
|
5..;
|
|
|
|
..5;
|
|
|
|
5..6;
|
2017-09-28 17:40:19 +00:00
|
|
|
5..=6;
|
2017-02-08 13:58:07 +00:00
|
|
|
[42, 55];
|
|
|
|
[42, 55][1];
|
|
|
|
(42, 55).1;
|
|
|
|
[42; 55];
|
|
|
|
[42; 55][13];
|
2016-02-11 12:50:41 +00:00
|
|
|
let mut x = 0;
|
2017-02-08 13:58:07 +00:00
|
|
|
|| x += 5;
|
2017-10-07 22:32:09 +00:00
|
|
|
let s: String = "foo".into();
|
|
|
|
FooString { s: s };
|
2021-10-21 11:11:36 +00:00
|
|
|
let _unused = 1;
|
|
|
|
let _penguin = || println!("Some helpful closure");
|
|
|
|
let _duck = Struct { field: 0 };
|
|
|
|
let _cat = [2, 4, 6, 8][2];
|
2015-10-28 16:50:00 +00:00
|
|
|
|
2021-06-03 06:41:37 +00:00
|
|
|
#[allow(clippy::no_effect)]
|
|
|
|
0;
|
|
|
|
|
2015-10-28 16:50:00 +00:00
|
|
|
// Do not warn
|
|
|
|
get_number();
|
2016-05-25 16:51:35 +00:00
|
|
|
unsafe { unsafe_fn() };
|
2021-10-21 11:11:36 +00:00
|
|
|
let _used = get_struct();
|
|
|
|
let _x = vec![1];
|
2017-09-18 19:07:33 +00:00
|
|
|
DropUnit;
|
|
|
|
DropStruct { field: 0 };
|
|
|
|
DropTuple(0);
|
|
|
|
DropEnum::Tuple(0);
|
|
|
|
DropEnum::Struct { field: 0 };
|
2021-12-06 11:33:31 +00:00
|
|
|
GreetStruct1("world");
|
|
|
|
GreetStruct2()("world");
|
|
|
|
GreetStruct3 {}("world");
|
2015-10-28 16:50:00 +00:00
|
|
|
}
|