rust/src/test/ui/lint/unused_braces.rs

51 lines
873 B
Rust
Raw Normal View History

2020-03-27 20:56:58 +00:00
// check-pass
#![warn(unused_braces, unused_parens)]
fn consume<T>(_: T) {}
2020-03-27 20:56:58 +00: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 20:56:58 +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
consume({ 7 });
//~^ WARN unnecessary braces
// Do not emit lint for multiline blocks.
2020-03-27 20:56:58 +00:00
let _ = {
7
};
// Do not emit lint for unsafe blocks.
2020-03-27 20:56:58 +00:00
let _ = unsafe { 7 };
// 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 } {
}
}