2018-10-21 03:46:13 +00:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
#![deny(clippy::mem_discriminant_non_enum)]
|
|
|
|
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
enum Foo {
|
|
|
|
One(usize),
|
|
|
|
Two(u8),
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A(Foo);
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// bad
|
|
|
|
mem::discriminant(&"hello");
|
|
|
|
mem::discriminant(&&Some(2));
|
|
|
|
mem::discriminant(&&None::<u8>);
|
|
|
|
mem::discriminant(&&Foo::One(5));
|
|
|
|
mem::discriminant(&&Foo::Two(5));
|
|
|
|
mem::discriminant(&A(Foo::One(0)));
|
|
|
|
|
|
|
|
let ro = &Some(3);
|
|
|
|
let rro = &ro;
|
|
|
|
mem::discriminant(&ro);
|
|
|
|
mem::discriminant(rro);
|
|
|
|
mem::discriminant(&rro);
|
|
|
|
|
2018-10-21 19:23:51 +00:00
|
|
|
macro_rules! mem_discriminant_but_in_a_macro {
|
2018-12-09 22:26:16 +00:00
|
|
|
($param:expr) => {
|
|
|
|
mem::discriminant($param)
|
|
|
|
};
|
2018-10-21 19:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mem_discriminant_but_in_a_macro!(&rro);
|
2018-10-21 03:46:13 +00:00
|
|
|
|
2018-10-25 02:27:47 +00:00
|
|
|
let rrrrro = &&&rro;
|
|
|
|
mem::discriminant(&rrrrro);
|
|
|
|
mem::discriminant(*rrrrro);
|
|
|
|
|
2018-10-21 03:46:13 +00:00
|
|
|
// ok
|
|
|
|
mem::discriminant(&Some(2));
|
|
|
|
mem::discriminant(&None::<u8>);
|
|
|
|
mem::discriminant(&Foo::One(5));
|
|
|
|
mem::discriminant(&Foo::Two(5));
|
|
|
|
mem::discriminant(ro);
|
2018-10-25 02:27:47 +00:00
|
|
|
mem::discriminant(*rro);
|
|
|
|
mem::discriminant(****rrrrro);
|
2018-10-21 03:46:13 +00:00
|
|
|
}
|