1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#![feature(never_type)]
#![feature(min_exhaustive_patterns)]
#![feature(type_alias_impl_trait)]
#![feature(non_exhaustive_omitted_patterns_lint)]
#![deny(unreachable_patterns)]
// Test that the lint traversal handles opaques correctly
#![deny(non_exhaustive_omitted_patterns)]
fn main() {}
#[derive(Copy, Clone)]
enum Void {}
fn return_never_rpit(x: Void) -> impl Copy {
if false {
match return_never_rpit(x) {
_ => {} //~ ERROR unreachable
}
}
x
}
fn friend_of_return_never_rpit(x: Void) {
match return_never_rpit(x) {}
//~^ ERROR non-empty
}
type T = impl Copy;
fn return_never_tait(x: Void) -> T {
if false {
match return_never_tait(x) {
_ => {} //~ ERROR unreachable
}
}
x
}
fn friend_of_return_never_tait(x: Void) {
match return_never_tait(x) {}
//~^ ERROR non-empty
}
fn option_never(x: Void) -> Option<impl Copy> {
if false {
match option_never(x) {
None => {}
Some(_) => {} //~ ERROR unreachable
}
match option_never(x) {
None => {}
_ => {} //~ ERROR unreachable
}
}
Some(x)
}
fn option_never2(x: Void) -> impl Copy {
if false {
match option_never2(x) {
None => {}
Some(_) => {} //~ ERROR unreachable
}
match option_never2(x) {
None => {}
_ => {} //~ ERROR unreachable
}
match option_never2(x) {
None => {}
}
}
Some(x)
}
fn inner_never(x: Void) {
type T = impl Copy;
let y: T = x;
match y {
_ => {} //~ ERROR unreachable
}
}
// This one caused ICE https://github.com/rust-lang/rust/issues/117100.
fn inner_tuple() {
type T = impl Copy;
let foo: T = Some((1u32, 2u32));
match foo {
_ => {}
Some((a, b)) => {} //~ ERROR unreachable
}
}
type U = impl Copy;
fn unify_never(x: Void, u: U) -> U {
if false {
match u {
_ => {} //~ ERROR unreachable
}
}
x
}
type V = impl Copy;
fn infer_in_match(x: Option<V>) {
match x {
None => {}
Some((a, b)) => {}
Some((mut x, mut y)) => {
//~^ ERROR unreachable
x = 42;
y = "foo";
}
}
}
type W = impl Copy;
#[derive(Copy, Clone)]
struct Rec<'a> {
n: u32,
w: Option<&'a W>,
}
fn recursive_opaque() -> W {
if false {
match recursive_opaque() {
// Check for the ol' ICE when the type is recursively opaque.
_ => {}
Rec { n: 0, w: Some(Rec { n: 0, w: _ }) } => {} //~ ERROR unreachable
}
}
let w: Option<&'static W> = None;
Rec { n: 0, w }
}
type X = impl Copy;
struct SecretelyVoid(X);
fn nested_empty_opaque(x: Void) -> X {
if false {
let opaque_void = nested_empty_opaque(x);
let secretely_void = SecretelyVoid(opaque_void);
match secretely_void {
_ => {} //~ ERROR unreachable
}
}
x
}
type Y = (impl Copy, impl Copy);
struct SecretelyDoubleVoid(Y);
fn super_nested_empty_opaque(x: Void) -> Y {
if false {
let opaque_void = super_nested_empty_opaque(x);
let secretely_void = SecretelyDoubleVoid(opaque_void);
match secretely_void {
_ => {} //~ ERROR unreachable
}
}
(x, x)
}
|