mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Auto merge of #13167 - iDawer:exhaustive_patterns, r=Veykril
feat: Implement `feature(exhaustive_patterns)` from unstable Rust Closes #12753 Recognize Rust's unstable `#![feature(exhaustive_patterns)]` (RFC 1872). Allow omitting visibly uninhabited variants from `match` expressions when the feature is on. This adjusts match checking to the current implementation of the postponed RFC 1872 in rustc.
This commit is contained in:
commit
4f8153e4a5
9 changed files with 272 additions and 21 deletions
|
@ -947,6 +947,50 @@ fn f() {
|
|||
);
|
||||
}
|
||||
|
||||
mod rust_unstable {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn rfc_1872_exhaustive_patterns() {
|
||||
check_diagnostics_no_bails(
|
||||
r"
|
||||
//- minicore: option, result
|
||||
#![feature(exhaustive_patterns)]
|
||||
enum Void {}
|
||||
fn test() {
|
||||
match None::<!> { None => () }
|
||||
match Result::<u8, !>::Ok(2) { Ok(_) => () }
|
||||
match Result::<u8, Void>::Ok(2) { Ok(_) => () }
|
||||
match (2, loop {}) {}
|
||||
match Result::<!, !>::Ok(loop {}) {}
|
||||
match (&loop {}) {} // https://github.com/rust-lang/rust/issues/50642#issuecomment-388234919
|
||||
// ^^^^^^^^^^ error: missing match arm: type `&!` is non-empty
|
||||
}",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rfc_1872_private_uninhabitedness() {
|
||||
check_diagnostics_no_bails(
|
||||
r"
|
||||
//- minicore: option
|
||||
//- /lib.rs crate:lib
|
||||
#![feature(exhaustive_patterns)]
|
||||
pub struct PrivatelyUninhabited { private_field: Void }
|
||||
enum Void {}
|
||||
fn test_local(x: Option<PrivatelyUninhabited>) {
|
||||
match x {}
|
||||
} // ^ error: missing match arm: `None` not covered
|
||||
//- /main.rs crate:main deps:lib
|
||||
#![feature(exhaustive_patterns)]
|
||||
fn test(x: Option<lib::PrivatelyUninhabited>) {
|
||||
match x {}
|
||||
// ^ error: missing match arm: `None` and `Some(_)` not covered
|
||||
}",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod false_negatives {
|
||||
//! The implementation of match checking here is a work in progress. As we roll this out, we
|
||||
//! prefer false negatives to false positives (ideally there would be no false positives). This
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue