2019-12-14 13:40:43 +00:00
|
|
|
#![feature(exhaustive_patterns, never_type)]
|
2019-01-13 11:49:54 +00:00
|
|
|
#![allow(dead_code, unreachable_code, unused_variables)]
|
2023-11-26 19:24:09 +00:00
|
|
|
#![allow(clippy::let_and_return, clippy::uninhabited_references)]
|
2018-04-19 19:34:31 +00:00
|
|
|
|
|
|
|
enum SingleVariantEnum {
|
|
|
|
Variant(i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TupleStruct(i32);
|
|
|
|
|
2022-11-15 04:57:56 +00:00
|
|
|
struct NonCopy;
|
|
|
|
struct TupleStructWithNonCopy(NonCopy);
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
enum EmptyEnum {}
|
|
|
|
|
2020-03-27 19:36:00 +00:00
|
|
|
macro_rules! match_enum {
|
|
|
|
($param:expr) => {
|
|
|
|
let data = match $param {
|
|
|
|
SingleVariantEnum::Variant(i) => i,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
fn infallible_destructuring_match_enum() {
|
|
|
|
let wrapper = SingleVariantEnum::Variant(0);
|
|
|
|
|
|
|
|
// This should lint!
|
|
|
|
let data = match wrapper {
|
|
|
|
SingleVariantEnum::Variant(i) => i,
|
|
|
|
};
|
|
|
|
|
2020-03-27 19:36:00 +00:00
|
|
|
// This shouldn't (inside macro)
|
|
|
|
match_enum!(wrapper);
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
// This shouldn't!
|
|
|
|
let data = match wrapper {
|
|
|
|
SingleVariantEnum::Variant(_) => -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Neither should this!
|
|
|
|
let data = match wrapper {
|
|
|
|
SingleVariantEnum::Variant(i) => -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
let SingleVariantEnum::Variant(data) = wrapper;
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:36:00 +00:00
|
|
|
macro_rules! match_struct {
|
|
|
|
($param:expr) => {
|
|
|
|
let data = match $param {
|
|
|
|
TupleStruct(i) => i,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
fn infallible_destructuring_match_struct() {
|
|
|
|
let wrapper = TupleStruct(0);
|
|
|
|
|
|
|
|
// This should lint!
|
|
|
|
let data = match wrapper {
|
|
|
|
TupleStruct(i) => i,
|
|
|
|
};
|
|
|
|
|
2020-03-27 19:36:00 +00:00
|
|
|
// This shouldn't (inside macro)
|
|
|
|
match_struct!(wrapper);
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
// This shouldn't!
|
|
|
|
let data = match wrapper {
|
|
|
|
TupleStruct(_) => -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Neither should this!
|
|
|
|
let data = match wrapper {
|
|
|
|
TupleStruct(i) => -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
let TupleStruct(data) = wrapper;
|
|
|
|
}
|
|
|
|
|
2022-11-15 04:57:56 +00:00
|
|
|
fn infallible_destructuring_match_struct_with_noncopy() {
|
|
|
|
let wrapper = TupleStructWithNonCopy(NonCopy);
|
|
|
|
|
|
|
|
// This should lint! (keeping `ref` in the suggestion)
|
|
|
|
let data = match wrapper {
|
|
|
|
TupleStructWithNonCopy(ref n) => n,
|
|
|
|
};
|
|
|
|
|
|
|
|
let TupleStructWithNonCopy(ref data) = wrapper;
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:36:00 +00:00
|
|
|
macro_rules! match_never_enum {
|
|
|
|
($param:expr) => {
|
|
|
|
let data = match $param {
|
|
|
|
Ok(i) => i,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
fn never_enum() {
|
|
|
|
let wrapper: Result<i32, !> = Ok(23);
|
|
|
|
|
|
|
|
// This should lint!
|
|
|
|
let data = match wrapper {
|
|
|
|
Ok(i) => i,
|
|
|
|
};
|
|
|
|
|
2020-03-27 19:36:00 +00:00
|
|
|
// This shouldn't (inside macro)
|
|
|
|
match_never_enum!(wrapper);
|
|
|
|
|
2018-04-19 19:34:31 +00:00
|
|
|
// This shouldn't!
|
|
|
|
let data = match wrapper {
|
|
|
|
Ok(_) => -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Neither should this!
|
|
|
|
let data = match wrapper {
|
|
|
|
Ok(i) => -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
let Ok(data) = wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EmptyEnum {
|
|
|
|
fn match_on(&self) -> ! {
|
|
|
|
// The lint shouldn't pick this up, as `let` won't work here!
|
|
|
|
let data = match *self {};
|
|
|
|
data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|