Suggest semicolon removal and boxing when appropriate
This commit is contained in:
parent
c5485115dc
commit
f5d7443a6b
2 changed files with 43 additions and 17 deletions
|
@ -688,13 +688,27 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
let msg = "`match` arms have incompatible types";
|
||||
err.span_label(outer_error_span, msg);
|
||||
if let Some((sp, boxed)) = semi_span {
|
||||
if matches!(boxed, StatementAsExpression::NeedsBoxing) {
|
||||
err.span_suggestion_verbose(
|
||||
sp,
|
||||
"consider removing this semicolon and boxing the expression",
|
||||
String::new(),
|
||||
if let (StatementAsExpression::NeedsBoxing, [.., prior_arm]) =
|
||||
(boxed, &prior_arms[..])
|
||||
{
|
||||
err.multipart_suggestion(
|
||||
"consider removing this semicolon and boxing the expressions",
|
||||
vec![
|
||||
(prior_arm.shrink_to_lo(), "Box::new(".to_string()),
|
||||
(prior_arm.shrink_to_hi(), ")".to_string()),
|
||||
(arm_span.shrink_to_lo(), "Box::new(".to_string()),
|
||||
(arm_span.shrink_to_hi(), ")".to_string()),
|
||||
(sp, String::new()),
|
||||
],
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
} else if matches!(boxed, StatementAsExpression::NeedsBoxing) {
|
||||
err.span_suggestion_short(
|
||||
sp,
|
||||
"consider removing this semicolon and boxing the expressions",
|
||||
String::new(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else {
|
||||
err.span_suggestion_short(
|
||||
sp,
|
||||
|
@ -727,11 +741,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
if let Some((sp, boxed)) = semicolon {
|
||||
if matches!(boxed, StatementAsExpression::NeedsBoxing) {
|
||||
err.span_suggestion_verbose(
|
||||
sp,
|
||||
err.multipart_suggestion(
|
||||
"consider removing this semicolon and boxing the expression",
|
||||
String::new(),
|
||||
Applicability::HasPlaceholders,
|
||||
vec![
|
||||
(then.shrink_to_lo(), "Box::new(".to_string()),
|
||||
(then.shrink_to_hi(), ")".to_string()),
|
||||
(else_sp.shrink_to_lo(), "Box::new(".to_string()),
|
||||
(else_sp.shrink_to_hi(), ")".to_string()),
|
||||
(sp, String::new()),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else {
|
||||
err.span_suggestion_short(
|
||||
|
|
|
@ -24,10 +24,13 @@ help: consider `await`ing on the `Future`
|
|||
|
|
||||
LL | false => async_dummy().await,
|
||||
| ^^^^^^
|
||||
help: consider removing this semicolon and boxing the expression
|
||||
help: consider removing this semicolon and boxing the expressions
|
||||
|
|
||||
LL | Box::new(async_dummy())
|
||||
LL |
|
||||
LL | }
|
||||
LL | false => Box::new(async_dummy()),
|
||||
|
|
||||
LL | async_dummy()
|
||||
| --
|
||||
|
||||
error[E0308]: `match` arms have incompatible types
|
||||
--> $DIR/match-prev-arm-needing-semi.rs:39:18
|
||||
|
@ -55,10 +58,13 @@ help: consider `await`ing on the `Future`
|
|||
|
|
||||
LL | false => async_dummy2().await,
|
||||
| ^^^^^^
|
||||
help: consider removing this semicolon and boxing the expression
|
||||
help: consider removing this semicolon and boxing the expressions
|
||||
|
|
||||
LL | Box::new(async_dummy())
|
||||
LL |
|
||||
LL | }
|
||||
LL | false => Box::new(async_dummy2()),
|
||||
|
|
||||
LL | async_dummy()
|
||||
| --
|
||||
|
||||
error[E0308]: `match` arms have incompatible types
|
||||
--> $DIR/match-prev-arm-needing-semi.rs:50:18
|
||||
|
@ -70,10 +76,10 @@ LL | let _ = match true {
|
|||
| _____________-
|
||||
LL | | true => async_dummy(),
|
||||
| | ------------- this is found to be of type `impl Future`
|
||||
LL | |
|
||||
LL | | false => async_dummy2(),
|
||||
| | ^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | |
|
||||
LL | | };
|
||||
| |_____- `match` arms have incompatible types
|
||||
|
@ -84,6 +90,7 @@ LL | | };
|
|||
help: consider `await`ing on both `Future`s
|
||||
|
|
||||
LL | true => async_dummy().await,
|
||||
LL |
|
||||
LL | false => async_dummy2().await,
|
||||
|
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue