Skip to content

Disable non_exhaustive_omitted_patterns within matches! macro #144331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 6 additions & 0 deletions library/coretests/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
let mut _2: bool;
let mut _3: isize;
+ let mut _4: isize;
scope 1 {
}

bb0: {
StorageLive(_2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading