diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-08-09 17:34:57 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-09 17:34:57 +0530 |
| commit | 467e7aae0f09ec4a42e6c3ea45aa897637265d49 (patch) | |
| tree | ed05b84e2085c0e90a9e02e195f5cbc0c3450ecb /compiler | |
| parent | d7f414d540f3e4ccc9926bff7c4d87420da8decc (diff) | |
| parent | 56ec5bec1ee9ecf6cbacb2378dbc75238a9fc8fe (diff) | |
| download | rust-467e7aae0f09ec4a42e6c3ea45aa897637265d49.tar.gz rust-467e7aae0f09ec4a42e6c3ea45aa897637265d49.zip | |
Rollup merge of #100305 - TaKO8Ki:suggest-adding-appropriate-missing-pattern-excluding-comments, r=compiler-errors
Suggest adding an appropriate missing pattern excluding comments fixes #100272
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 28 |
1 files changed, 14 insertions, 14 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 063c076474e..69a8c98b27a 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -849,22 +849,22 @@ fn non_exhaustive_match<'p, 'tcx>( )); } [.., prev, last] if prev.span.eq_ctxt(last.span) => { - if let Ok(snippet) = sm.span_to_snippet(prev.span.between(last.span)) { - let comma = if matches!(last.body.kind, hir::ExprKind::Block(..)) - && last.span.eq_ctxt(last.body.span) - { - "" - } else { - "," - }; + let comma = if matches!(last.body.kind, hir::ExprKind::Block(..)) + && last.span.eq_ctxt(last.body.span) + { + "" + } else { + "," + }; + let spacing = if sm.is_multiline(prev.span.between(last.span)) { + sm.indentation_before(last.span).map(|indent| format!("\n{indent}")) + } else { + Some(" ".to_string()) + }; + if let Some(spacing) = spacing { suggestion = Some(( last.span.shrink_to_hi(), - format!( - "{}{}{} => todo!()", - comma, - snippet.strip_prefix(',').unwrap_or(&snippet), - pattern - ), + format!("{}{}{} => todo!()", comma, spacing, pattern), )); } } |
