rust/tests/ui/lint/unused_braces.rs

58 lines
1.1 KiB
Rust
Raw Normal View History

2020-03-27 15:56:58 -05:00
// check-pass
2020-07-02 00:32:12 -05:00
// run-rustfix
2020-03-27 15:56:58 -05:00
#![warn(unused_braces, unused_parens)]
2020-07-02 00:32:12 -05:00
#![allow(unreachable_code, unused_unsafe)] // for rustfix
2020-03-27 15:56:58 -05:00
fn consume<T>(_: T) {}
2020-03-27 15:56:58 -05:00
fn main() {
let _ = (7);
//~^WARN unnecessary parentheses
// 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 15:56:58 -05:00
if { true } {
//~^ WARN unnecessary braces
}
while { false } {
2020-03-27 15:56:58 -05:00
//~^ WARN unnecessary braces
}
let _: [u8; { 3 }];
//~^ WARN unnecessary braces
consume({ 7 });
//~^ WARN unnecessary braces
// Do not emit lint for multiline blocks.
2020-03-27 15:56:58 -05:00
let _ = {
7
};
// Do not emit lint for unsafe blocks.
2020-03-27 15:56:58 -05:00
let _ = unsafe { 7 };
// Do not emit lint, as the `{` would then
2020-03-27 15:56:58 -05:00
// be parsed as part of the `return`.
if { return } {
}
// regression test for https://github.com/rust-lang/rust/issues/106899
return { println!("!") };
//~^ WARN unnecessary braces
2020-03-27 15:56:58 -05:00
}