|
1 | 1 | use crate::coercion::{AsCoercionSite, CoerceMany}; |
2 | 2 | use crate::{Diverges, Expectation, FnCtxt, Needs}; |
3 | | -use rustc_errors::{Applicability, Diagnostic, MultiSpan}; |
| 3 | +use rustc_errors::Diagnostic; |
4 | 4 | use rustc_hir::{self as hir, ExprKind}; |
5 | 5 | use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; |
6 | 6 | use rustc_infer::traits::Obligation; |
@@ -225,24 +225,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
225 | 225 | return; |
226 | 226 | } |
227 | 227 |
|
228 | | - let semi_span = expr.span.shrink_to_hi().with_hi(semi_span.hi()); |
229 | | - let mut ret_span: MultiSpan = semi_span.into(); |
230 | | - ret_span.push_span_label( |
231 | | - expr.span, |
232 | | - "this could be implicitly returned but it is a statement, not a tail expression", |
233 | | - ); |
234 | | - ret_span.push_span_label(ret, "the `match` arms can conform to this return type"); |
235 | | - ret_span.push_span_label( |
236 | | - semi_span, |
237 | | - "the `match` is a statement because of this semicolon, consider removing it", |
238 | | - ); |
239 | | - diag.span_note(ret_span, "you might have meant to return the `match` expression"); |
240 | | - diag.tool_only_span_suggestion( |
241 | | - semi_span, |
242 | | - "remove this semicolon", |
243 | | - "", |
244 | | - Applicability::MaybeIncorrect, |
245 | | - ); |
| 228 | + let semi = expr.span.shrink_to_hi().with_hi(semi_span.hi()); |
| 229 | + let sugg = crate::errors::RemoveSemiForCoerce { expr: expr.span, ret, semi }; |
| 230 | + diag.subdiagnostic(sugg); |
246 | 231 | } |
247 | 232 |
|
248 | 233 | /// When the previously checked expression (the scrutinee) diverges, |
|
0 commit comments