replace_if_let_with_match: don't assume sad pattern

This commit is contained in:
Dániel Buga 2021-01-22 23:29:51 +01:00
parent f301da3c3d
commit 24f0cd8293
2 changed files with 103 additions and 2 deletions

View file

@ -49,6 +49,21 @@ impl TryEnum {
}
}
pub fn happy_pattern(self) -> ast::Pat {
match self {
TryEnum::Result => make::tuple_struct_pat(
make::path_unqualified(make::path_segment(make::name_ref("Ok"))),
iter::once(make::wildcard_pat().into()),
)
.into(),
TryEnum::Option => make::tuple_struct_pat(
make::path_unqualified(make::path_segment(make::name_ref("Some"))),
iter::once(make::wildcard_pat().into()),
)
.into(),
}
}
fn type_name(self) -> &'static str {
match self {
TryEnum::Result => "Result",