-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,105 @@ | ||
#![feature(never_type)] | ||
#![feature(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 non-empty | ||
} | ||
x | ||
} | ||
fn friend_of_return_never_rpit(x: Void) { | ||
match return_never_rpit(x) {} | ||
} | ||
|
||
type T = impl Copy; | ||
//~^ERROR unconstrained | ||
fn return_never_tait(x: Void) -> T { | ||
if false { | ||
match return_never_tait(x) {} | ||
//~^ERROR non-empty | ||
} | ||
x | ||
} | ||
fn friend_of_return_never_tait(x: Void) { | ||
match return_never_tait(x) {} | ||
} | ||
|
||
fn option_never(x: Void) -> Option<impl Copy> { | ||
if true { | ||
match option_never(x) { | ||
None => {} | ||
Some(_) => {} | ||
} | ||
match option_never(x) { | ||
None => {} | ||
_ => {} | ||
} | ||
} | ||
Some(x) | ||
} | ||
|
||
fn option_never2(x: Void) -> impl Copy { | ||
if true { | ||
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; | ||
//~^ERROR unconstrained | ||
let y: T = x; | ||
match y {} | ||
//~^ERROR non-empty | ||
} | ||
|
||
// 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; | ||
//~^ERROR unconstrained | ||
fn unify_never(x: Void, u: U) -> U { | ||
if true { match u {} } else { x } | ||
//~^ERROR non-empty | ||
} | ||
|
||
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"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,115 @@ | ||
error[E0004]: non-exhaustive patterns: type `impl Copy` is non-empty | ||
--> $DIR/impl-trait.rs:16:15 | ||
| | ||
LL | match return_never_rpit(x) {} | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the matched value is of type `impl Copy` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match return_never_rpit(x) { | ||
LL _ => todo!(), | ||
LL } | ||
| | ||
|
||
error[E0004]: non-exhaustive patterns: type `T` is non-empty | ||
--> $DIR/impl-trait.rs:29:15 | ||
| | ||
LL | match return_never_tait(x) {} | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the matched value is of type `T` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match return_never_tait(x) { | ||
LL _ => todo!(), | ||
LL } | ||
| | ||
|
||
error: unconstrained opaque type | ||
--> $DIR/impl-trait.rs:25:10 | ||
| | ||
LL | type T = impl Copy; | ||
| ^^^^^^^^^ | ||
| | ||
= note: `T` must be used in combination with a concrete type within the same module | ||
|
||
error: unreachable pattern | ||
--> $DIR/impl-trait.rs:56:13 | ||
| | ||
LL | Some(_) => {} | ||
| ^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/impl-trait.rs:5:9 | ||
| | ||
LL | #![deny(unreachable_patterns)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unreachable pattern | ||
--> $DIR/impl-trait.rs:60:13 | ||
| | ||
LL | _ => {} | ||
| ^ | ||
|
||
error[E0004]: non-exhaustive patterns: type `inner_never::T` is non-empty | ||
--> $DIR/impl-trait.rs:73:11 | ||
| | ||
LL | match y {} | ||
| ^ | ||
| | ||
= note: the matched value is of type `inner_never::T` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ match y { | ||
LL _ => todo!(), | ||
LL } | ||
| | ||
|
||
error: unconstrained opaque type | ||
--> $DIR/impl-trait.rs:70:14 | ||
| | ||
LL | type T = impl Copy; | ||
| ^^^^^^^^^ | ||
| | ||
= note: `T` must be used in combination with a concrete type within the same item | ||
|
||
error: unreachable pattern | ||
--> $DIR/impl-trait.rs:83:9 | ||
| | ||
LL | _ => {} | ||
| - matches any value | ||
LL | Some((a, b)) => {} | ||
| ^^^^^^^^^^^^ unreachable pattern | ||
|
||
error[E0004]: non-exhaustive patterns: type `U` is non-empty | ||
--> $DIR/impl-trait.rs:90:21 | ||
| | ||
LL | if true { match u {} } else { x } | ||
| ^ | ||
| | ||
= note: the matched value is of type `U` | ||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown | ||
| | ||
LL ~ if true { match u { | ||
LL _ => todo!(), | ||
LL ~ } } else { x } | ||
| | ||
|
||
error: unconstrained opaque type | ||
--> $DIR/impl-trait.rs:87:10 | ||
| | ||
LL | type U = impl Copy; | ||
| ^^^^^^^^^ | ||
| | ||
= note: `U` must be used in combination with a concrete type within the same module | ||
|
||
error: unreachable pattern | ||
--> $DIR/impl-trait.rs:99:9 | ||
| | ||
LL | Some((mut x, mut y)) => { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 11 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0004`. |