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";
|
let msg = "`match` arms have incompatible types";
|
||||||
err.span_label(outer_error_span, msg);
|
err.span_label(outer_error_span, msg);
|
||||||
if let Some((sp, boxed)) = semi_span {
|
if let Some((sp, boxed)) = semi_span {
|
||||||
if matches!(boxed, StatementAsExpression::NeedsBoxing) {
|
if let (StatementAsExpression::NeedsBoxing, [.., prior_arm]) =
|
||||||
err.span_suggestion_verbose(
|
(boxed, &prior_arms[..])
|
||||||
sp,
|
{
|
||||||
"consider removing this semicolon and boxing the expression",
|
err.multipart_suggestion(
|
||||||
String::new(),
|
"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,
|
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 {
|
} else {
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
sp,
|
sp,
|
||||||
|
@ -727,11 +741,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
if let Some((sp, boxed)) = semicolon {
|
if let Some((sp, boxed)) = semicolon {
|
||||||
if matches!(boxed, StatementAsExpression::NeedsBoxing) {
|
if matches!(boxed, StatementAsExpression::NeedsBoxing) {
|
||||||
err.span_suggestion_verbose(
|
err.multipart_suggestion(
|
||||||
sp,
|
|
||||||
"consider removing this semicolon and boxing the expression",
|
"consider removing this semicolon and boxing the expression",
|
||||||
String::new(),
|
vec![
|
||||||
Applicability::HasPlaceholders,
|
(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 {
|
} else {
|
||||||
err.span_suggestion_short(
|
err.span_suggestion_short(
|
||||||
|
|
|
@ -24,10 +24,13 @@ help: consider `await`ing on the `Future`
|
||||||
|
|
|
|
||||||
LL | false => async_dummy().await,
|
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
|
error[E0308]: `match` arms have incompatible types
|
||||||
--> $DIR/match-prev-arm-needing-semi.rs:39:18
|
--> $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,
|
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
|
error[E0308]: `match` arms have incompatible types
|
||||||
--> $DIR/match-prev-arm-needing-semi.rs:50:18
|
--> $DIR/match-prev-arm-needing-semi.rs:50:18
|
||||||
|
@ -70,10 +76,10 @@ LL | let _ = match true {
|
||||||
| _____________-
|
| _____________-
|
||||||
LL | | true => async_dummy(),
|
LL | | true => async_dummy(),
|
||||||
| | ------------- this is found to be of type `impl Future`
|
| | ------------- this is found to be of type `impl Future`
|
||||||
|
LL | |
|
||||||
LL | | false => async_dummy2(),
|
LL | | false => async_dummy2(),
|
||||||
| | ^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
|
| | ^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
|
||||||
LL | |
|
... |
|
||||||
LL | |
|
|
||||||
LL | |
|
LL | |
|
||||||
LL | | };
|
LL | | };
|
||||||
| |_____- `match` arms have incompatible types
|
| |_____- `match` arms have incompatible types
|
||||||
|
@ -84,6 +90,7 @@ LL | | };
|
||||||
help: consider `await`ing on both `Future`s
|
help: consider `await`ing on both `Future`s
|
||||||
|
|
|
|
||||||
LL | true => async_dummy().await,
|
LL | true => async_dummy().await,
|
||||||
|
LL |
|
||||||
LL | false => async_dummy2().await,
|
LL | false => async_dummy2().await,
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue