2020-03-27 20:56:58 +00:00
|
|
|
// check-pass
|
2020-07-02 05:32:12 +00:00
|
|
|
// run-rustfix
|
|
|
|
|
2020-03-27 20:56:58 +00:00
|
|
|
#![warn(unused_braces, unused_parens)]
|
2020-07-02 05:32:12 +00:00
|
|
|
#![allow(unreachable_code, unused_unsafe)] // for rustfix
|
2020-03-27 20:56:58 +00:00
|
|
|
|
2020-04-04 20:40:31 +00:00
|
|
|
fn consume<T>(_: T) {}
|
|
|
|
|
2020-03-27 20:56:58 +00:00
|
|
|
fn main() {
|
|
|
|
let _ = (7);
|
|
|
|
//~^WARN unnecessary parentheses
|
|
|
|
|
2020-04-04 20:40:31 +00:00
|
|
|
// Do not emit a lint in these cases,
|
|
|
|
// as we have to be careful with
|
|
|
|
// `ref` patterns.
|
|
|
|
{
|
|
|
|
let _ = { 7 };
|
|
|
|
|
|
|
|
if let 7 = { 7 } { }
|
|
|
|
|
|
|
|
match { 7 } {
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2020-03-27 20:56:58 +00:00
|
|
|
|
2020-04-04 20:40:31 +00:00
|
|
|
if { true } {
|
|
|
|
//~^ WARN unnecessary braces
|
|
|
|
}
|
|
|
|
|
|
|
|
while { false } {
|
2020-03-27 20:56:58 +00:00
|
|
|
//~^ WARN unnecessary braces
|
|
|
|
}
|
|
|
|
|
|
|
|
let _: [u8; { 3 }];
|
|
|
|
//~^ WARN unnecessary braces
|
|
|
|
|
2020-04-04 20:40:31 +00:00
|
|
|
consume({ 7 });
|
|
|
|
//~^ WARN unnecessary braces
|
|
|
|
|
|
|
|
// Do not emit lint for multiline blocks.
|
2020-03-27 20:56:58 +00:00
|
|
|
let _ = {
|
|
|
|
7
|
|
|
|
};
|
|
|
|
|
2020-04-04 20:40:31 +00:00
|
|
|
// Do not emit lint for unsafe blocks.
|
2020-03-27 20:56:58 +00:00
|
|
|
let _ = unsafe { 7 };
|
|
|
|
|
2020-04-04 20:40:31 +00:00
|
|
|
// Do not emit lint, as the `{` would then
|
2020-03-27 20:56:58 +00:00
|
|
|
// be parsed as part of the `return`.
|
|
|
|
if { return } {
|
|
|
|
|
|
|
|
}
|
2023-01-15 05:06:33 +00:00
|
|
|
|
|
|
|
// regression test for https://github.com/rust-lang/rust/issues/106899
|
|
|
|
return { println!("!") };
|
|
|
|
//~^ WARN unnecessary braces
|
2020-03-27 20:56:58 +00:00
|
|
|
}
|