2023-04-23 06:03:09 -05:00
|
|
|
//@run-rustfix
|
2022-08-11 12:42:16 -05:00
|
|
|
#![warn(clippy::partialeq_to_none)]
|
|
|
|
|
|
|
|
struct Foobar;
|
|
|
|
|
|
|
|
impl PartialEq<Option<()>> for Foobar {
|
|
|
|
fn eq(&self, _: &Option<()>) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
fn foo(f: Option<u32>) -> &'static str {
|
|
|
|
if f.is_some() { "yay" } else { "nay" }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foobar() -> Option<()> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar() -> Result<(), ()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn optref() -> &'static &'static Option<()> {
|
|
|
|
&&None
|
|
|
|
}
|
|
|
|
|
2022-08-31 08:24:45 -05:00
|
|
|
pub fn macro_expansion() {
|
|
|
|
macro_rules! foo {
|
|
|
|
() => {
|
|
|
|
None::<()>
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let _ = foobar() == foo!();
|
|
|
|
let _ = foo!() == foobar();
|
|
|
|
let _ = foo!() == foo!();
|
|
|
|
}
|
|
|
|
|
2022-08-11 12:42:16 -05:00
|
|
|
fn main() {
|
|
|
|
let x = Some(0);
|
|
|
|
|
|
|
|
let _ = x.is_none();
|
|
|
|
let _ = x.is_some();
|
|
|
|
let _ = x.is_none();
|
|
|
|
let _ = x.is_some();
|
|
|
|
|
|
|
|
if foobar().is_none() {}
|
|
|
|
|
|
|
|
if bar().ok().is_some() {}
|
|
|
|
|
|
|
|
let _ = Some(1 + 2).is_some();
|
|
|
|
|
|
|
|
let _ = { Some(0) }.is_none();
|
|
|
|
|
|
|
|
let _ = {
|
|
|
|
/*
|
|
|
|
This comment runs long
|
|
|
|
*/
|
|
|
|
Some(1)
|
|
|
|
}.is_some();
|
|
|
|
|
|
|
|
// Should not trigger, as `Foobar` is not an `Option` and has no `is_none`
|
|
|
|
let _ = Foobar == None;
|
|
|
|
|
|
|
|
let _ = optref().is_none();
|
|
|
|
let _ = optref().is_some();
|
|
|
|
let _ = optref().is_none();
|
|
|
|
let _ = optref().is_some();
|
|
|
|
|
|
|
|
let x = Box::new(Option::<()>::None);
|
|
|
|
let _ = (*x).is_some();
|
|
|
|
}
|