Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add run-rustfix to infallible_destructuring_match
- Loading branch information
Showing
3 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// run-rustfix | ||
#![feature(exhaustive_patterns, never_type)] | ||
#![allow(dead_code, unreachable_code, unused_variables)] | ||
#![allow(clippy::let_and_return)] | ||
|
||
enum SingleVariantEnum { | ||
Variant(i32), | ||
} | ||
|
||
struct TupleStruct(i32); | ||
|
||
enum EmptyEnum {} | ||
|
||
fn infallible_destructuring_match_enum() { | ||
let wrapper = SingleVariantEnum::Variant(0); | ||
|
||
// This should lint! | ||
let SingleVariantEnum::Variant(data) = wrapper; | ||
|
||
// This shouldn't! | ||
let data = match wrapper { | ||
SingleVariantEnum::Variant(_) => -1, | ||
}; | ||
|
||
// Neither should this! | ||
let data = match wrapper { | ||
SingleVariantEnum::Variant(i) => -1, | ||
}; | ||
|
||
let SingleVariantEnum::Variant(data) = wrapper; | ||
} | ||
|
||
fn infallible_destructuring_match_struct() { | ||
let wrapper = TupleStruct(0); | ||
|
||
// This should lint! | ||
let TupleStruct(data) = wrapper; | ||
|
||
// This shouldn't! | ||
let data = match wrapper { | ||
TupleStruct(_) => -1, | ||
}; | ||
|
||
// Neither should this! | ||
let data = match wrapper { | ||
TupleStruct(i) => -1, | ||
}; | ||
|
||
let TupleStruct(data) = wrapper; | ||
} | ||
|
||
fn never_enum() { | ||
let wrapper: Result<i32, !> = Ok(23); | ||
|
||
// This should lint! | ||
let Ok(data) = wrapper; | ||
|
||
// This shouldn't! | ||
let data = match wrapper { | ||
Ok(_) => -1, | ||
}; | ||
|
||
// Neither should this! | ||
let data = match wrapper { | ||
Ok(i) => -1, | ||
}; | ||
|
||
let Ok(data) = wrapper; | ||
} | ||
|
||
impl EmptyEnum { | ||
fn match_on(&self) -> ! { | ||
// The lint shouldn't pick this up, as `let` won't work here! | ||
let data = match *self {}; | ||
data | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters