mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
84 lines
1.6 KiB
Rust
84 lines
1.6 KiB
Rust
// run-rustfix
|
|
// aux-build:macro_rules.rs
|
|
|
|
#![allow(unused_variables, dead_code, clippy::derive_partial_eq_without_eq)]
|
|
#![warn(clippy::equatable_if_let)]
|
|
|
|
#[macro_use]
|
|
extern crate macro_rules;
|
|
|
|
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,
|
|
}
|
|
|
|
enum NotPartialEq {
|
|
A,
|
|
B,
|
|
}
|
|
|
|
enum NotStructuralEq {
|
|
A,
|
|
B,
|
|
}
|
|
|
|
impl PartialEq for NotStructuralEq {
|
|
fn eq(&self, _: &NotStructuralEq) -> bool {
|
|
false
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
// 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 {}
|
|
if let NotPartialEq::A = f {}
|
|
if g == NotStructuralEq::A {}
|
|
if let Some(NotPartialEq::A) = Some(f) {}
|
|
if Some(g) == Some(NotStructuralEq::A) {}
|
|
|
|
macro_rules! m1 {
|
|
(x) => {
|
|
"abc"
|
|
};
|
|
}
|
|
if "abc" == m1!(x) {
|
|
println!("OK");
|
|
}
|
|
|
|
equatable_if_let!(a);
|
|
}
|