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