2023-08-24 19:32:12 +00:00
|
|
|
//@aux-build:proc_macros.rs
|
2023-07-02 12:35:19 +00:00
|
|
|
|
|
|
|
#![allow(
|
|
|
|
unused_variables,
|
|
|
|
dead_code,
|
|
|
|
clippy::derive_partial_eq_without_eq,
|
|
|
|
clippy::needless_if
|
|
|
|
)]
|
2021-10-07 09:21:30 +00:00
|
|
|
#![warn(clippy::equatable_if_let)]
|
|
|
|
|
2023-03-24 13:04:35 +00:00
|
|
|
extern crate proc_macros;
|
|
|
|
use proc_macros::{external, inline_macros};
|
2022-07-18 07:39:37 +00:00
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum Enum {
|
|
|
|
TupleVariant(i32, u64),
|
|
|
|
RecordVariant { a: i64, b: u32 },
|
|
|
|
UnitVariant,
|
|
|
|
Recursive(Struct),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Struct {
|
|
|
|
a: i32,
|
|
|
|
b: bool,
|
|
|
|
}
|
|
|
|
|
2022-11-21 19:34:47 +00:00
|
|
|
struct NoPartialEqStruct {
|
|
|
|
a: i32,
|
|
|
|
b: bool,
|
|
|
|
}
|
|
|
|
|
2021-10-07 09:21:30 +00:00
|
|
|
enum NotPartialEq {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum NotStructuralEq {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialEq for NotStructuralEq {
|
|
|
|
fn eq(&self, _: &NotStructuralEq) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-24 13:04:35 +00:00
|
|
|
#[inline_macros]
|
2021-10-07 09:21:30 +00:00
|
|
|
fn main() {
|
|
|
|
let a = 2;
|
|
|
|
let b = 3;
|
|
|
|
let c = Some(2);
|
|
|
|
let d = Struct { a: 2, b: false };
|
|
|
|
let e = Enum::UnitVariant;
|
|
|
|
let f = NotPartialEq::A;
|
|
|
|
let g = NotStructuralEq::A;
|
2022-11-21 19:34:47 +00:00
|
|
|
let h = NoPartialEqStruct { a: 2, b: false };
|
2021-10-07 09:21:30 +00:00
|
|
|
|
|
|
|
// true
|
|
|
|
|
|
|
|
if a == 2 {}
|
|
|
|
if a.cmp(&b) == Ordering::Greater {}
|
|
|
|
if c == Some(2) {}
|
|
|
|
if d == (Struct { a: 2, b: false }) {}
|
|
|
|
if e == Enum::TupleVariant(32, 64) {}
|
|
|
|
if e == (Enum::RecordVariant { a: 64, b: 32 }) {}
|
|
|
|
if e == Enum::UnitVariant {}
|
|
|
|
if (e, &d) == (Enum::UnitVariant, &Struct { a: 2, b: false }) {}
|
|
|
|
|
|
|
|
// false
|
|
|
|
|
|
|
|
if let 2 | 3 = a {}
|
|
|
|
if let x @ 2 = a {}
|
|
|
|
if let Some(3 | 4) = c {}
|
|
|
|
if let Struct { a, b: false } = d {}
|
|
|
|
if let Struct { a: 2, b: x } = d {}
|
2022-11-21 19:34:47 +00:00
|
|
|
if matches!(f, NotPartialEq::A) {}
|
2021-10-07 09:21:30 +00:00
|
|
|
if g == NotStructuralEq::A {}
|
2022-11-21 19:34:47 +00:00
|
|
|
if matches!(Some(f), Some(NotPartialEq::A)) {}
|
2021-10-07 09:21:30 +00:00
|
|
|
if Some(g) == Some(NotStructuralEq::A) {}
|
2022-11-21 19:34:47 +00:00
|
|
|
if matches!(h, NoPartialEqStruct { a: 2, b: false }) {}
|
2021-10-21 11:11:36 +00:00
|
|
|
|
2023-03-24 13:04:35 +00:00
|
|
|
if "abc" == inline!("abc") {
|
2021-10-21 11:11:36 +00:00
|
|
|
println!("OK");
|
|
|
|
}
|
2022-07-18 07:39:37 +00:00
|
|
|
|
2023-03-24 13:04:35 +00:00
|
|
|
external!({ if let 2 = $a {} });
|
2021-10-07 09:21:30 +00:00
|
|
|
}
|