Rollup merge of #87061 - FabianWolff:issue-87051, r=oli-obk
Do not suggest adding a semicolon after `?` Fixes #87051. I have only modified `report_return_mismatched_types()`, i.e. my changes only affect suggestions to add `;` for return type mismatches, but this never makes sense after `?`, because the function cannot return `()` if `?` is used (it has to return a `Result` or an `Option`), and a semicolon won't help if the expected and actual `Err` types differ, even if the expected one is `()`.
This commit is contained in:
commit
5fcefb1d61
3 changed files with 67 additions and 3 deletions
|
@ -1456,11 +1456,15 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||
expected.is_unit(),
|
||||
pointing_at_return_type,
|
||||
) {
|
||||
// If the block is from an external macro, then do not suggest
|
||||
// adding a semicolon, because there's nowhere to put it.
|
||||
// See issue #81943.
|
||||
// If the block is from an external macro or try (`?`) desugaring, then
|
||||
// do not suggest adding a semicolon, because there's nowhere to put it.
|
||||
// See issues #81943 and #87051.
|
||||
if cond_expr.span.desugaring_kind().is_none()
|
||||
&& !in_external_macro(fcx.tcx.sess, cond_expr.span)
|
||||
&& !matches!(
|
||||
cond_expr.kind,
|
||||
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar)
|
||||
)
|
||||
{
|
||||
err.span_label(cond_expr.span, "expected this to be `()`");
|
||||
if expr.can_have_side_effects() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue