diff --git a/tests/ui/single_match.rs b/tests/ui/single_match.rs index d0c9b7b56..d474088aa 100644 --- a/tests/ui/single_match.rs +++ b/tests/ui/single_match.rs @@ -1,5 +1,5 @@ #![warn(clippy::single_match)] -#![allow(clippy::uninlined_format_args)] +#![allow(unused, clippy::uninlined_format_args)] fn dummy() {} @@ -244,3 +244,24 @@ fn main() { _ => 0, }; } + +fn issue_10808(bar: Option) { + match bar { + Some(v) => unsafe { + let r = &v as *const i32; + println!("{}", *r); + }, + _ => {}, + } + + match bar { + Some(v) => { + // this comment prevents rustfmt from collapsing the block + unsafe { + let r = &v as *const i32; + println!("{}", *r); + } + }, + _ => {}, + } +} diff --git a/tests/ui/single_match_else.rs b/tests/ui/single_match_else.rs index c8ac768b6..768316eda 100644 --- a/tests/ui/single_match_else.rs +++ b/tests/ui/single_match_else.rs @@ -1,6 +1,6 @@ //@aux-build: proc_macros.rs #![warn(clippy::single_match_else)] -#![allow(clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] +#![allow(unused, clippy::needless_return, clippy::no_effect, clippy::uninlined_format_args)] extern crate proc_macros; use proc_macros::with_span; @@ -115,3 +115,87 @@ fn main() { } } } + +fn issue_10808(bar: Option) { + match bar { + Some(v) => unsafe { + let r = &v as *const i32; + println!("{}", *r); + }, + None => { + println!("None1"); + println!("None2"); + }, + } + + match bar { + Some(v) => { + println!("Some"); + println!("{v}"); + }, + None => unsafe { + let v = 0; + let r = &v as *const i32; + println!("{}", *r); + }, + } + + match bar { + Some(v) => unsafe { + let r = &v as *const i32; + println!("{}", *r); + }, + None => unsafe { + let v = 0; + let r = &v as *const i32; + println!("{}", *r); + }, + } + + match bar { + Some(v) => { + // this comment prevents rustfmt from collapsing the block + unsafe { + let r = &v as *const i32; + println!("{}", *r); + } + }, + None => { + println!("None"); + println!("None"); + }, + } + + match bar { + Some(v) => { + println!("Some"); + println!("{v}"); + }, + None => { + // this comment prevents rustfmt from collapsing the block + unsafe { + let v = 0; + let r = &v as *const i32; + println!("{}", *r); + } + }, + } + + match bar { + Some(v) => { + // this comment prevents rustfmt from collapsing the block + unsafe { + let r = &v as *const i32; + println!("{}", *r); + } + }, + None => { + // this comment prevents rustfmt from collapsing the block + unsafe { + let v = 0; + let r = &v as *const i32; + println!("{}", *r); + } + }, + } +}