Rollup merge of #144331 - jplatte:matches-allow-non_exhaustive_omitted_patterns, r=Nadrieril

Disable non_exhaustive_omitted_patterns within matches! macro

Closes rust-lang/rust#117304.

I believe I can skip all of the bootstrap stuff mentioned in https://github.com/rust-lang/rust/issues/117304#issuecomment-1784414453 due to https://blog.rust-lang.org/inside-rust/2025/05/29/redesigning-the-initial-bootstrap-sequence/, right?

cc `@Jules-Bertholet`
This commit is contained in:
Matthias Krüger 2025-07-26 15:27:58 +02:00 committed by GitHub
commit c9541a2bf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 36 additions and 10 deletions

View file

@ -933,6 +933,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
fn check_gated_lint(&self, lint_id: LintId, span: Span, lint_from_cli: bool) -> bool {
let feature = if let Some(feature) = lint_id.lint.feature_gate
&& !self.features.enabled(feature)
&& !span.allows_unstable(feature)
{
// Lint is behind a feature that is not enabled; eventually return false.
feature

View file

@ -426,8 +426,10 @@ pub macro debug_assert_matches($($arg:tt)*) {
#[macro_export]
#[stable(feature = "matches_macro", since = "1.42.0")]
#[rustc_diagnostic_item = "matches_macro"]
#[allow_internal_unstable(non_exhaustive_omitted_patterns_lint, stmt_expr_attributes)]
macro_rules! matches {
($expression:expr, $pattern:pat $(if $guard:expr)? $(,)?) => {
#[allow(non_exhaustive_omitted_patterns)]
match $expression {
$pattern $(if $guard)? => true,
_ => false

View file

@ -76,6 +76,7 @@
#![feature(min_specialization)]
#![feature(never_type)]
#![feature(next_index)]
#![feature(non_exhaustive_omitted_patterns_lint)]
#![feature(numfmt)]
#![feature(pattern)]
#![feature(pointer_is_aligned_to)]

View file

@ -213,3 +213,9 @@ fn _expression() {
}
);
}
#[deny(non_exhaustive_omitted_patterns)]
fn _matches_does_not_trigger_non_exhaustive_omitted_patterns_lint(o: core::sync::atomic::Ordering) {
// Ordering is a #[non_exhaustive] enum from a separate crate
let _m = matches!(o, core::sync::atomic::Ordering::Relaxed);
}

View file

@ -8,12 +8,14 @@ fn num_to_digit(_1: char) -> u32 {
let _2: std::option::Option<u32>;
scope 2 (inlined Option::<u32>::is_some) {
let mut _3: isize;
scope 3 {
}
}
}
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
scope 4 (inlined #[track_caller] Option::<u32>::unwrap) {
let mut _5: isize;
let mut _6: !;
scope 4 {
scope 5 {
}
}

View file

@ -8,12 +8,14 @@ fn num_to_digit(_1: char) -> u32 {
let _2: std::option::Option<u32>;
scope 2 (inlined Option::<u32>::is_some) {
let mut _3: isize;
scope 3 {
}
}
}
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
scope 4 (inlined #[track_caller] Option::<u32>::unwrap) {
let mut _5: isize;
let mut _6: !;
scope 4 {
scope 5 {
}
}

View file

@ -8,12 +8,14 @@ fn num_to_digit(_1: char) -> u32 {
let _2: std::option::Option<u32>;
scope 2 (inlined Option::<u32>::is_some) {
let mut _3: isize;
scope 3 {
}
}
}
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
scope 4 (inlined #[track_caller] Option::<u32>::unwrap) {
let mut _5: isize;
let mut _6: !;
scope 4 {
scope 5 {
}
}

View file

@ -8,12 +8,14 @@ fn num_to_digit(_1: char) -> u32 {
let _2: std::option::Option<u32>;
scope 2 (inlined Option::<u32>::is_some) {
let mut _3: isize;
scope 3 {
}
}
}
scope 3 (inlined #[track_caller] Option::<u32>::unwrap) {
scope 4 (inlined #[track_caller] Option::<u32>::unwrap) {
let mut _5: isize;
let mut _6: !;
scope 4 {
scope 5 {
}
}

View file

@ -7,6 +7,8 @@
let mut _2: bool;
let mut _3: isize;
+ let mut _4: isize;
scope 1 {
}
bb0: {
StorageLive(_2);

View file

@ -25,9 +25,11 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
}
scope 8 (inlined Option::<u16>::is_none) {
scope 9 (inlined Option::<u16>::is_some) {
scope 10 {
}
}
}
scope 10 (inlined core::num::<impl u16>::wrapping_add) {
scope 11 (inlined core::num::<impl u16>::wrapping_add) {
}
}

View file

@ -25,9 +25,11 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
}
scope 8 (inlined Option::<u16>::is_none) {
scope 9 (inlined Option::<u16>::is_some) {
scope 10 {
}
}
}
scope 10 (inlined core::num::<impl u16>::wrapping_add) {
scope 11 (inlined core::num::<impl u16>::wrapping_add) {
}
}

View file

@ -4,6 +4,8 @@ fn issue_77355_opt(_1: Foo) -> u64 {
debug num => _1;
let mut _0: u64;
let mut _2: isize;
scope 1 {
}
bb0: {
_2 = discriminant(_1);