Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5021dde

Browse files
committed
Move scrutinee HirId into MatchSource::TryDesugar
1 parent 55f8c66 commit 5021dde

File tree

29 files changed

+41
-49
lines changed

29 files changed

+41
-49
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16481648
hir::ExprKind::Match(
16491649
scrutinee,
16501650
arena_vec![self; break_arm, continue_arm],
1651-
hir::MatchSource::TryDesugar,
1651+
hir::MatchSource::TryDesugar(scrutinee.hir_id),
16521652
)
16531653
}
16541654

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ pub enum MatchSource {
21482148
/// A desugared `for _ in _ { .. }` loop.
21492149
ForLoopDesugar,
21502150
/// A desugared `?` operator.
2151-
TryDesugar,
2151+
TryDesugar(HirId),
21522152
/// A desugared `<expr>.await`.
21532153
AwaitDesugar,
21542154
/// A desugared `format_args!()`.
@@ -2162,7 +2162,7 @@ impl MatchSource {
21622162
match self {
21632163
Normal => "match",
21642164
ForLoopDesugar => "for",
2165-
TryDesugar => "?",
2165+
TryDesugar(_) => "?",
21662166
AwaitDesugar => ".await",
21672167
FormatArgs => "format_args!()",
21682168
}

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
107107
let (span, code) = match prior_arm {
108108
// The reason for the first arm to fail is not that the match arms diverge,
109109
// but rather that there's a prior obligation that doesn't hold.
110-
None => (
111-
arm_span,
112-
ObligationCauseCode::BlockTailExpression(
113-
arm.body.hir_id,
114-
scrut.hir_id,
115-
match_src,
116-
),
117-
),
110+
None => {
111+
(arm_span, ObligationCauseCode::BlockTailExpression(arm.body.hir_id, match_src))
112+
}
118113
Some((prior_arm_block_id, prior_arm_ty, prior_arm_span)) => (
119114
expr.span,
120115
ObligationCauseCode::MatchExpressionArm(Box::new(MatchExpressionArmCause {
@@ -127,7 +122,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
127122
scrut_span: scrut.span,
128123
source: match_src,
129124
prior_arms: other_arms.clone(),
130-
scrut_hir_id: scrut.hir_id,
131125
opt_suggest_box_span,
132126
})),
133127
),

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
17511751
) && !in_external_macro(fcx.tcx.sess, cond_expr.span)
17521752
&& !matches!(
17531753
cond_expr.kind,
1754-
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar)
1754+
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))
17551755
)
17561756
{
17571757
err.span_label(cond_expr.span, "expected this to be `()`");

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,11 +1582,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15821582
let span = self.get_expr_coercion_span(tail_expr);
15831583
let cause = self.cause(
15841584
span,
1585-
ObligationCauseCode::BlockTailExpression(
1586-
blk.hir_id,
1587-
blk.hir_id,
1588-
hir::MatchSource::Normal,
1589-
),
1585+
ObligationCauseCode::BlockTailExpression(blk.hir_id, hir::MatchSource::Normal),
15901586
);
15911587
let ty_for_diagnostic = coerce.merged_ty();
15921588
// We use coerce_inner here because we want to augment the error

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
745745
}
746746
ObligationCauseCode::BlockTailExpression(
747747
_,
748-
scrut_hir_id,
749-
hir::MatchSource::TryDesugar,
748+
hir::MatchSource::TryDesugar(scrut_hir_id),
750749
) => {
751750
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
752751
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
@@ -782,12 +781,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
782781
prior_arm_ty,
783782
source,
784783
ref prior_arms,
785-
scrut_hir_id,
786784
opt_suggest_box_span,
787785
scrut_span,
788786
..
789787
}) => match source {
790-
hir::MatchSource::TryDesugar => {
788+
hir::MatchSource::TryDesugar(scrut_hir_id) => {
791789
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
792790
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
793791
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
@@ -2077,7 +2075,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20772075
if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. })
20782076
| BlockTailExpression(.., source)
20792077
) = code
2080-
&& let hir::MatchSource::TryDesugar = source
2078+
&& let hir::MatchSource::TryDesugar(_) = source
20812079
&& let Some((expected_ty, found_ty, _, _)) = self.values_str(trace.values)
20822080
{
20832081
suggestions.push(TypeErrorAdditionalDiags::TryCannotConvert {
@@ -2954,11 +2952,11 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
29542952
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
29552953
ObligationCauseFailureCode::ConstCompat { span, subdiags }
29562954
}
2957-
BlockTailExpression(.., hir::MatchSource::TryDesugar) => {
2955+
BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
29582956
ObligationCauseFailureCode::TryCompat { span, subdiags }
29592957
}
29602958
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
2961-
hir::MatchSource::TryDesugar => {
2959+
hir::MatchSource::TryDesugar(_) => {
29622960
ObligationCauseFailureCode::TryCompat { span, subdiags }
29632961
}
29642962
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },

compiler/rustc_middle/src/thir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ pub enum ExprKind<'tcx> {
346346
/// A `match` expression.
347347
Match {
348348
scrutinee: ExprId,
349+
scrutinee_hir_id: hir::HirId,
349350
arms: Box<[ArmId]>,
350351
},
351352
/// A block.

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
7070
visitor.visit_expr(&visitor.thir()[expr]);
7171
}
7272
Loop { body } => visitor.visit_expr(&visitor.thir()[body]),
73-
Match { scrutinee, ref arms } => {
73+
Match { scrutinee, ref arms, .. } => {
7474
visitor.visit_expr(&visitor.thir()[scrutinee]);
7575
for &arm in &**arms {
7676
visitor.visit_arm(&visitor.thir()[arm]);

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub enum ObligationCauseCode<'tcx> {
402402
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),
403403

404404
/// Block implicit return
405-
BlockTailExpression(hir::HirId, hir::HirId, hir::MatchSource),
405+
BlockTailExpression(hir::HirId, hir::MatchSource),
406406

407407
/// #[feature(trivial_bounds)] is not enabled
408408
TrivialBound,
@@ -543,7 +543,6 @@ pub struct MatchExpressionArmCause<'tcx> {
543543
pub scrut_span: Span,
544544
pub source: hir::MatchSource,
545545
pub prior_arms: Vec<Span>,
546-
pub scrut_hir_id: hir::HirId,
547546
pub opt_suggest_box_span: Option<Span>,
548547
}
549548

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
6565
let target = self.parse_block(args[1])?;
6666
self.parse_call(args[2], destination, target)
6767
},
68-
ExprKind::Match { scrutinee, arms } => {
68+
ExprKind::Match { scrutinee, arms, .. } => {
6969
let discr = self.parse_operand(*scrutinee)?;
7070
self.parse_match(arms, expr.span).map(|t| TerminatorKind::SwitchInt { discr, targets: t })
7171
},

0 commit comments

Comments
 (0)