Skip to content

Commit 429245b

Browse files
authored
Unrolled build for rust-lang#106601
Rollup merge of rust-lang#106601 - estebank:match-semi, r=cjgillot Suggest `;` after bare `match` expression E0308 Fix rust-lang#72634.
2 parents 786c94a + a53f280 commit 429245b

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

compiler/rustc_hir_typeck/src/_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
121121
prior_arm_ty,
122122
prior_arm_span,
123123
scrut_span: scrut.span,
124+
scrut_hir_id: scrut.hir_id,
124125
source: match_src,
125126
prior_arms: other_arms.clone(),
126127
opt_suggest_box_span,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
776776
ref prior_arms,
777777
opt_suggest_box_span,
778778
scrut_span,
779+
scrut_hir_id,
779780
..
780781
}) => match source {
781782
hir::MatchSource::TryDesugar(scrut_hir_id) => {
@@ -843,6 +844,18 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
843844
) {
844845
err.subdiagnostic(subdiag);
845846
}
847+
if let Some(hir::Node::Expr(m)) = self.tcx.hir().find_parent(scrut_hir_id)
848+
&& let Some(hir::Node::Stmt(stmt)) = self.tcx.hir().find_parent(m.hir_id)
849+
&& let hir::StmtKind::Expr(_) = stmt.kind
850+
{
851+
err.span_suggestion_verbose(
852+
stmt.span.shrink_to_hi(),
853+
"consider using a semicolon here, but this will discard any values \
854+
in the match arms",
855+
";",
856+
Applicability::MaybeIncorrect,
857+
);
858+
}
846859
if let Some(ret_sp) = opt_suggest_box_span {
847860
// Get return type span and point to it.
848861
self.suggest_boxing_for_return_impl_trait(

compiler/rustc_middle/src/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ pub struct MatchExpressionArmCause<'tcx> {
541541
pub prior_arm_ty: Ty<'tcx>,
542542
pub prior_arm_span: Span,
543543
pub scrut_span: Span,
544+
pub scrut_hir_id: hir::HirId,
544545
pub source: hir::MatchSource,
545546
pub prior_arms: Vec<Span>,
546547
pub opt_suggest_box_span: Option<Span>,

tests/ui/suggestions/issue-81839.stderr

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ error[E0308]: `match` arms have incompatible types
44
LL | / match num {
55
LL | | 1 => {
66
LL | | cx.answer_str("hi");
7-
| | --------------------
8-
| | | |
9-
| | | help: consider removing this semicolon
10-
| | this is found to be of type `()`
7+
| | -------------------- this is found to be of type `()`
118
LL | | }
129
LL | | _ => cx.answer_str("hi"),
1310
| | ^^^^^^^^^^^^^^^^^^^ expected `()`, found future
1411
LL | | }
1512
| |_____- `match` arms have incompatible types
13+
|
14+
help: consider removing this semicolon
15+
|
16+
LL - cx.answer_str("hi");
17+
LL + cx.answer_str("hi")
18+
|
19+
help: consider using a semicolon here, but this will discard any values in the match arms
20+
|
21+
LL | };
22+
| +
1623

1724
error: aborting due to previous error
1825

tests/ui/wf/wf-unsafe-trait-obj-match.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ LL | | }
1111
|
1212
= note: expected reference `&S`
1313
found reference `&R`
14+
help: consider using a semicolon here, but this will discard any values in the match arms
15+
|
16+
LL | };
17+
| +
1418

1519
error[E0038]: the trait `Trait` cannot be made into an object
1620
--> $DIR/wf-unsafe-trait-obj-match.rs:26:21

0 commit comments

Comments
 (0)