diff options
| author | Esteban Kuber <esteban@kuber.com.ar> | 2021-12-16 02:14:17 +0000 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2022-03-08 00:18:24 +0000 |
| commit | 2383858f34989f7c6c87da857bd038f5ce0a66b0 (patch) | |
| tree | fae94544bea7a6888068b41bb51c1983aeceb813 /compiler | |
| parent | 02a3830f245d84672db133208c73756eb8778964 (diff) | |
| download | rust-2383858f34989f7c6c87da857bd038f5ce0a66b0.tar.gz rust-2383858f34989f7c6c87da857bd038f5ce0a66b0.zip | |
When finding a match expr with a single arm that requires more, suggest it
Given
```rust
match Some(42) {
Some(0) => {}
}
```
suggest
```rust
match Some(42) {
Some(0) => {}
None | Some(_) => todo!(),
}
```
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index cb057e428c4..f1c2ec08c3c 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -589,6 +589,21 @@ fn non_exhaustive_match<'p, 'tcx>( ), )); } + [only] => { + let pre_indentation = if let (Some(snippet), true) = ( + sm.indentation_before(only.span), + sm.is_multiline(sp.shrink_to_hi().with_hi(only.span.lo())), + ) { + format!("\n{}", snippet) + } else { + " ".to_string() + }; + let comma = if matches!(only.body.kind, hir::ExprKind::Block(..)) { "" } else { "," }; + suggestion = Some(( + only.span.shrink_to_hi(), + format!("{}{}{} => todo!()", comma, pre_indentation, pattern), + )); + } _ => {} } |
