parent
cdddcd3bea
commit
a53f280bfc
5 changed files with 30 additions and 4 deletions
|
@ -121,6 +121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
prior_arm_ty,
|
prior_arm_ty,
|
||||||
prior_arm_span,
|
prior_arm_span,
|
||||||
scrut_span: scrut.span,
|
scrut_span: scrut.span,
|
||||||
|
scrut_hir_id: scrut.hir_id,
|
||||||
source: match_src,
|
source: match_src,
|
||||||
prior_arms: other_arms.clone(),
|
prior_arms: other_arms.clone(),
|
||||||
opt_suggest_box_span,
|
opt_suggest_box_span,
|
||||||
|
|
|
@ -775,6 +775,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
ref prior_arms,
|
ref prior_arms,
|
||||||
opt_suggest_box_span,
|
opt_suggest_box_span,
|
||||||
scrut_span,
|
scrut_span,
|
||||||
|
scrut_hir_id,
|
||||||
..
|
..
|
||||||
}) => match source {
|
}) => match source {
|
||||||
hir::MatchSource::TryDesugar(scrut_hir_id) => {
|
hir::MatchSource::TryDesugar(scrut_hir_id) => {
|
||||||
|
@ -842,6 +843,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
) {
|
) {
|
||||||
err.subdiagnostic(subdiag);
|
err.subdiagnostic(subdiag);
|
||||||
}
|
}
|
||||||
|
if let Some(hir::Node::Expr(m)) = self.tcx.hir().find_parent(scrut_hir_id)
|
||||||
|
&& let Some(hir::Node::Stmt(stmt)) = self.tcx.hir().find_parent(m.hir_id)
|
||||||
|
&& let hir::StmtKind::Expr(_) = stmt.kind
|
||||||
|
{
|
||||||
|
err.span_suggestion_verbose(
|
||||||
|
stmt.span.shrink_to_hi(),
|
||||||
|
"consider using a semicolon here, but this will discard any values \
|
||||||
|
in the match arms",
|
||||||
|
";",
|
||||||
|
Applicability::MaybeIncorrect,
|
||||||
|
);
|
||||||
|
}
|
||||||
if let Some(ret_sp) = opt_suggest_box_span {
|
if let Some(ret_sp) = opt_suggest_box_span {
|
||||||
// Get return type span and point to it.
|
// Get return type span and point to it.
|
||||||
self.suggest_boxing_for_return_impl_trait(
|
self.suggest_boxing_for_return_impl_trait(
|
||||||
|
|
|
@ -541,6 +541,7 @@ pub struct MatchExpressionArmCause<'tcx> {
|
||||||
pub prior_arm_ty: Ty<'tcx>,
|
pub prior_arm_ty: Ty<'tcx>,
|
||||||
pub prior_arm_span: Span,
|
pub prior_arm_span: Span,
|
||||||
pub scrut_span: Span,
|
pub scrut_span: Span,
|
||||||
|
pub scrut_hir_id: hir::HirId,
|
||||||
pub source: hir::MatchSource,
|
pub source: hir::MatchSource,
|
||||||
pub prior_arms: Vec<Span>,
|
pub prior_arms: Vec<Span>,
|
||||||
pub opt_suggest_box_span: Option<Span>,
|
pub opt_suggest_box_span: Option<Span>,
|
||||||
|
|
|
@ -4,15 +4,22 @@ error[E0308]: `match` arms have incompatible types
|
||||||
LL | / match num {
|
LL | / match num {
|
||||||
LL | | 1 => {
|
LL | | 1 => {
|
||||||
LL | | cx.answer_str("hi");
|
LL | | cx.answer_str("hi");
|
||||||
| | --------------------
|
| | -------------------- this is found to be of type `()`
|
||||||
| | | |
|
|
||||||
| | | help: consider removing this semicolon
|
|
||||||
| | this is found to be of type `()`
|
|
||||||
LL | | }
|
LL | | }
|
||||||
LL | | _ => cx.answer_str("hi"),
|
LL | | _ => cx.answer_str("hi"),
|
||||||
| | ^^^^^^^^^^^^^^^^^^^ expected `()`, found future
|
| | ^^^^^^^^^^^^^^^^^^^ expected `()`, found future
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_____- `match` arms have incompatible types
|
| |_____- `match` arms have incompatible types
|
||||||
|
|
|
||||||
|
help: consider removing this semicolon
|
||||||
|
|
|
||||||
|
LL - cx.answer_str("hi");
|
||||||
|
LL + cx.answer_str("hi")
|
||||||
|
|
|
||||||
|
help: consider using a semicolon here, but this will discard any values in the match arms
|
||||||
|
|
|
||||||
|
LL | };
|
||||||
|
| +
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ LL | | }
|
||||||
|
|
|
|
||||||
= note: expected reference `&S`
|
= note: expected reference `&S`
|
||||||
found reference `&R`
|
found reference `&R`
|
||||||
|
help: consider using a semicolon here, but this will discard any values in the match arms
|
||||||
|
|
|
||||||
|
LL | };
|
||||||
|
| +
|
||||||
|
|
||||||
error[E0038]: the trait `Trait` cannot be made into an object
|
error[E0038]: the trait `Trait` cannot be made into an object
|
||||||
--> $DIR/wf-unsafe-trait-obj-match.rs:26:21
|
--> $DIR/wf-unsafe-trait-obj-match.rs:26:21
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue