Move scrutinee HirId
into MatchSource::TryDesugar
This commit is contained in:
parent
55f8c66a60
commit
5021dde1a0
@ -1648,7 +1648,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
hir::ExprKind::Match(
|
hir::ExprKind::Match(
|
||||||
scrutinee,
|
scrutinee,
|
||||||
arena_vec![self; break_arm, continue_arm],
|
arena_vec![self; break_arm, continue_arm],
|
||||||
hir::MatchSource::TryDesugar,
|
hir::MatchSource::TryDesugar(scrutinee.hir_id),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2148,7 +2148,7 @@ pub enum MatchSource {
|
|||||||
/// A desugared `for _ in _ { .. }` loop.
|
/// A desugared `for _ in _ { .. }` loop.
|
||||||
ForLoopDesugar,
|
ForLoopDesugar,
|
||||||
/// A desugared `?` operator.
|
/// A desugared `?` operator.
|
||||||
TryDesugar,
|
TryDesugar(HirId),
|
||||||
/// A desugared `<expr>.await`.
|
/// A desugared `<expr>.await`.
|
||||||
AwaitDesugar,
|
AwaitDesugar,
|
||||||
/// A desugared `format_args!()`.
|
/// A desugared `format_args!()`.
|
||||||
@ -2162,7 +2162,7 @@ impl MatchSource {
|
|||||||
match self {
|
match self {
|
||||||
Normal => "match",
|
Normal => "match",
|
||||||
ForLoopDesugar => "for",
|
ForLoopDesugar => "for",
|
||||||
TryDesugar => "?",
|
TryDesugar(_) => "?",
|
||||||
AwaitDesugar => ".await",
|
AwaitDesugar => ".await",
|
||||||
FormatArgs => "format_args!()",
|
FormatArgs => "format_args!()",
|
||||||
}
|
}
|
||||||
|
@ -107,14 +107,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let (span, code) = match prior_arm {
|
let (span, code) = match prior_arm {
|
||||||
// The reason for the first arm to fail is not that the match arms diverge,
|
// The reason for the first arm to fail is not that the match arms diverge,
|
||||||
// but rather that there's a prior obligation that doesn't hold.
|
// but rather that there's a prior obligation that doesn't hold.
|
||||||
None => (
|
None => {
|
||||||
arm_span,
|
(arm_span, ObligationCauseCode::BlockTailExpression(arm.body.hir_id, match_src))
|
||||||
ObligationCauseCode::BlockTailExpression(
|
}
|
||||||
arm.body.hir_id,
|
|
||||||
scrut.hir_id,
|
|
||||||
match_src,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Some((prior_arm_block_id, prior_arm_ty, prior_arm_span)) => (
|
Some((prior_arm_block_id, prior_arm_ty, prior_arm_span)) => (
|
||||||
expr.span,
|
expr.span,
|
||||||
ObligationCauseCode::MatchExpressionArm(Box::new(MatchExpressionArmCause {
|
ObligationCauseCode::MatchExpressionArm(Box::new(MatchExpressionArmCause {
|
||||||
@ -127,7 +122,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
scrut_span: scrut.span,
|
scrut_span: scrut.span,
|
||||||
source: match_src,
|
source: match_src,
|
||||||
prior_arms: other_arms.clone(),
|
prior_arms: other_arms.clone(),
|
||||||
scrut_hir_id: scrut.hir_id,
|
|
||||||
opt_suggest_box_span,
|
opt_suggest_box_span,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
|
@ -1751,7 +1751,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||||||
) && !in_external_macro(fcx.tcx.sess, cond_expr.span)
|
) && !in_external_macro(fcx.tcx.sess, cond_expr.span)
|
||||||
&& !matches!(
|
&& !matches!(
|
||||||
cond_expr.kind,
|
cond_expr.kind,
|
||||||
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar)
|
hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
err.span_label(cond_expr.span, "expected this to be `()`");
|
err.span_label(cond_expr.span, "expected this to be `()`");
|
||||||
|
@ -1582,11 +1582,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let span = self.get_expr_coercion_span(tail_expr);
|
let span = self.get_expr_coercion_span(tail_expr);
|
||||||
let cause = self.cause(
|
let cause = self.cause(
|
||||||
span,
|
span,
|
||||||
ObligationCauseCode::BlockTailExpression(
|
ObligationCauseCode::BlockTailExpression(blk.hir_id, hir::MatchSource::Normal),
|
||||||
blk.hir_id,
|
|
||||||
blk.hir_id,
|
|
||||||
hir::MatchSource::Normal,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
let ty_for_diagnostic = coerce.merged_ty();
|
let ty_for_diagnostic = coerce.merged_ty();
|
||||||
// We use coerce_inner here because we want to augment the error
|
// We use coerce_inner here because we want to augment the error
|
||||||
|
@ -745,8 +745,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
ObligationCauseCode::BlockTailExpression(
|
ObligationCauseCode::BlockTailExpression(
|
||||||
_,
|
_,
|
||||||
scrut_hir_id,
|
hir::MatchSource::TryDesugar(scrut_hir_id),
|
||||||
hir::MatchSource::TryDesugar,
|
|
||||||
) => {
|
) => {
|
||||||
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
|
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
|
||||||
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
|
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
|
||||||
@ -782,12 +781,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
prior_arm_ty,
|
prior_arm_ty,
|
||||||
source,
|
source,
|
||||||
ref prior_arms,
|
ref prior_arms,
|
||||||
scrut_hir_id,
|
|
||||||
opt_suggest_box_span,
|
opt_suggest_box_span,
|
||||||
scrut_span,
|
scrut_span,
|
||||||
..
|
..
|
||||||
}) => match source {
|
}) => match source {
|
||||||
hir::MatchSource::TryDesugar => {
|
hir::MatchSource::TryDesugar(scrut_hir_id) => {
|
||||||
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
|
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
|
||||||
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
|
let scrut_expr = self.tcx.hir().expect_expr(scrut_hir_id);
|
||||||
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
|
let scrut_ty = if let hir::ExprKind::Call(_, args) = &scrut_expr.kind {
|
||||||
@ -2077,7 +2075,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. })
|
if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. })
|
||||||
| BlockTailExpression(.., source)
|
| BlockTailExpression(.., source)
|
||||||
) = code
|
) = code
|
||||||
&& let hir::MatchSource::TryDesugar = source
|
&& let hir::MatchSource::TryDesugar(_) = source
|
||||||
&& let Some((expected_ty, found_ty, _, _)) = self.values_str(trace.values)
|
&& let Some((expected_ty, found_ty, _, _)) = self.values_str(trace.values)
|
||||||
{
|
{
|
||||||
suggestions.push(TypeErrorAdditionalDiags::TryCannotConvert {
|
suggestions.push(TypeErrorAdditionalDiags::TryCannotConvert {
|
||||||
@ -2954,11 +2952,11 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
|
|||||||
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
|
CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => {
|
||||||
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
BlockTailExpression(.., hir::MatchSource::TryDesugar) => {
|
BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
|
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => match source {
|
||||||
hir::MatchSource::TryDesugar => {
|
hir::MatchSource::TryDesugar(_) => {
|
||||||
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
ObligationCauseFailureCode::TryCompat { span, subdiags }
|
||||||
}
|
}
|
||||||
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },
|
_ => ObligationCauseFailureCode::MatchCompat { span, subdiags },
|
||||||
|
@ -346,6 +346,7 @@ pub enum ExprKind<'tcx> {
|
|||||||
/// A `match` expression.
|
/// A `match` expression.
|
||||||
Match {
|
Match {
|
||||||
scrutinee: ExprId,
|
scrutinee: ExprId,
|
||||||
|
scrutinee_hir_id: hir::HirId,
|
||||||
arms: Box<[ArmId]>,
|
arms: Box<[ArmId]>,
|
||||||
},
|
},
|
||||||
/// A block.
|
/// A block.
|
||||||
|
@ -70,7 +70,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
|
|||||||
visitor.visit_expr(&visitor.thir()[expr]);
|
visitor.visit_expr(&visitor.thir()[expr]);
|
||||||
}
|
}
|
||||||
Loop { body } => visitor.visit_expr(&visitor.thir()[body]),
|
Loop { body } => visitor.visit_expr(&visitor.thir()[body]),
|
||||||
Match { scrutinee, ref arms } => {
|
Match { scrutinee, ref arms, .. } => {
|
||||||
visitor.visit_expr(&visitor.thir()[scrutinee]);
|
visitor.visit_expr(&visitor.thir()[scrutinee]);
|
||||||
for &arm in &**arms {
|
for &arm in &**arms {
|
||||||
visitor.visit_arm(&visitor.thir()[arm]);
|
visitor.visit_arm(&visitor.thir()[arm]);
|
||||||
|
@ -402,7 +402,7 @@ pub enum ObligationCauseCode<'tcx> {
|
|||||||
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),
|
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),
|
||||||
|
|
||||||
/// Block implicit return
|
/// Block implicit return
|
||||||
BlockTailExpression(hir::HirId, hir::HirId, hir::MatchSource),
|
BlockTailExpression(hir::HirId, hir::MatchSource),
|
||||||
|
|
||||||
/// #[feature(trivial_bounds)] is not enabled
|
/// #[feature(trivial_bounds)] is not enabled
|
||||||
TrivialBound,
|
TrivialBound,
|
||||||
@ -543,7 +543,6 @@ pub struct MatchExpressionArmCause<'tcx> {
|
|||||||
pub scrut_span: Span,
|
pub scrut_span: Span,
|
||||||
pub source: hir::MatchSource,
|
pub source: hir::MatchSource,
|
||||||
pub prior_arms: Vec<Span>,
|
pub prior_arms: Vec<Span>,
|
||||||
pub scrut_hir_id: hir::HirId,
|
|
||||||
pub opt_suggest_box_span: Option<Span>,
|
pub opt_suggest_box_span: Option<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
|||||||
let target = self.parse_block(args[1])?;
|
let target = self.parse_block(args[1])?;
|
||||||
self.parse_call(args[2], destination, target)
|
self.parse_call(args[2], destination, target)
|
||||||
},
|
},
|
||||||
ExprKind::Match { scrutinee, arms } => {
|
ExprKind::Match { scrutinee, arms, .. } => {
|
||||||
let discr = self.parse_operand(*scrutinee)?;
|
let discr = self.parse_operand(*scrutinee)?;
|
||||||
self.parse_match(arms, expr.span).map(|t| TerminatorKind::SwitchInt { discr, targets: t })
|
self.parse_match(arms, expr.span).map(|t| TerminatorKind::SwitchInt { discr, targets: t })
|
||||||
},
|
},
|
||||||
|
@ -47,7 +47,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
ExprKind::Block { block: ast_block } => {
|
ExprKind::Block { block: ast_block } => {
|
||||||
this.ast_block(destination, block, ast_block, source_info)
|
this.ast_block(destination, block, ast_block, source_info)
|
||||||
}
|
}
|
||||||
ExprKind::Match { scrutinee, ref arms } => {
|
ExprKind::Match { scrutinee, ref arms, .. } => {
|
||||||
this.match_expr(destination, expr_span, block, &this.thir[scrutinee], arms)
|
this.match_expr(destination, expr_span, block, &this.thir[scrutinee], arms)
|
||||||
}
|
}
|
||||||
ExprKind::If { cond, then, else_opt, if_then_scope } => {
|
ExprKind::If { cond, then, else_opt, if_then_scope } => {
|
||||||
|
@ -733,6 +733,7 @@ impl<'tcx> Cx<'tcx> {
|
|||||||
},
|
},
|
||||||
hir::ExprKind::Match(ref discr, ref arms, _) => ExprKind::Match {
|
hir::ExprKind::Match(ref discr, ref arms, _) => ExprKind::Match {
|
||||||
scrutinee: self.mirror_expr(discr),
|
scrutinee: self.mirror_expr(discr),
|
||||||
|
scrutinee_hir_id: discr.hir_id,
|
||||||
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
|
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
|
||||||
},
|
},
|
||||||
hir::ExprKind::Loop(ref body, ..) => {
|
hir::ExprKind::Loop(ref body, ..) => {
|
||||||
|
@ -135,10 +135,12 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for MatchVisitor<'a, '_, 'tcx> {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ExprKind::Match { scrutinee, box ref arms } => {
|
ExprKind::Match { scrutinee, scrutinee_hir_id, box ref arms } => {
|
||||||
let source = match ex.span.desugaring_kind() {
|
let source = match ex.span.desugaring_kind() {
|
||||||
Some(DesugaringKind::ForLoop) => hir::MatchSource::ForLoopDesugar,
|
Some(DesugaringKind::ForLoop) => hir::MatchSource::ForLoopDesugar,
|
||||||
Some(DesugaringKind::QuestionMark) => hir::MatchSource::TryDesugar,
|
Some(DesugaringKind::QuestionMark) => {
|
||||||
|
hir::MatchSource::TryDesugar(scrutinee_hir_id)
|
||||||
|
}
|
||||||
Some(DesugaringKind::Await) => hir::MatchSource::AwaitDesugar,
|
Some(DesugaringKind::Await) => hir::MatchSource::AwaitDesugar,
|
||||||
_ => hir::MatchSource::Normal,
|
_ => hir::MatchSource::Normal,
|
||||||
};
|
};
|
||||||
@ -277,7 +279,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
|
|||||||
| hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report),
|
| hir::MatchSource::FormatArgs => report_arm_reachability(&cx, &report),
|
||||||
// Unreachable patterns in try and await expressions occur when one of
|
// Unreachable patterns in try and await expressions occur when one of
|
||||||
// the arms are an uninhabited type. Which is OK.
|
// the arms are an uninhabited type. Which is OK.
|
||||||
hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar => {}
|
hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the match is exhaustive.
|
// Check if the match is exhaustive.
|
||||||
|
@ -321,7 +321,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
|
|||||||
print_indented!(self, format!("pat: {:?}", pat), depth_lvl + 1);
|
print_indented!(self, format!("pat: {:?}", pat), depth_lvl + 1);
|
||||||
print_indented!(self, "}", depth_lvl);
|
print_indented!(self, "}", depth_lvl);
|
||||||
}
|
}
|
||||||
Match { scrutinee, arms } => {
|
Match { scrutinee, arms, .. } => {
|
||||||
print_indented!(self, "Match {", depth_lvl);
|
print_indented!(self, "Match {", depth_lvl);
|
||||||
print_indented!(self, "scrutinee:", depth_lvl + 1);
|
print_indented!(self, "scrutinee:", depth_lvl + 1);
|
||||||
self.print_expr(*scrutinee, depth_lvl + 2);
|
self.print_expr(*scrutinee, depth_lvl + 2);
|
||||||
|
@ -45,7 +45,7 @@ impl NonConstExpr {
|
|||||||
|
|
||||||
Self::Loop(ForLoop) | Self::Match(ForLoopDesugar) => &[sym::const_for],
|
Self::Loop(ForLoop) | Self::Match(ForLoopDesugar) => &[sym::const_for],
|
||||||
|
|
||||||
Self::Match(TryDesugar) => &[sym::const_try],
|
Self::Match(TryDesugar(_)) => &[sym::const_try],
|
||||||
|
|
||||||
// All other expressions are allowed.
|
// All other expressions are allowed.
|
||||||
Self::Loop(Loop | While) | Self::Match(Normal | FormatArgs) => &[],
|
Self::Loop(Loop | While) | Self::Match(Normal | FormatArgs) => &[],
|
||||||
|
@ -802,7 +802,8 @@ fn in_postfix_position<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> boo
|
|||||||
match parent.kind {
|
match parent.kind {
|
||||||
ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _)
|
ExprKind::Call(child, _) | ExprKind::MethodCall(_, child, _, _) | ExprKind::Index(child, _, _)
|
||||||
if child.hir_id == e.hir_id => true,
|
if child.hir_id == e.hir_id => true,
|
||||||
ExprKind::Field(_, _) | ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar) => true,
|
ExprKind::Match(.., MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar)
|
||||||
|
| ExprKind::Field(_, _) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1038,7 +1038,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
|
|||||||
wild_in_or_pats::check(cx, arms);
|
wild_in_or_pats::check(cx, arms);
|
||||||
}
|
}
|
||||||
|
|
||||||
if source == MatchSource::TryDesugar {
|
if let MatchSource::TryDesugar(_) = source {
|
||||||
try_err::check(cx, expr, ex);
|
try_err::check(cx, expr, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
|
|||||||
|
|
||||||
/// Finds function return type by examining return expressions in match arms.
|
/// Finds function return type by examining return expressions in match arms.
|
||||||
fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option<Ty<'tcx>> {
|
fn find_return_type<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx ExprKind<'_>) -> Option<Ty<'tcx>> {
|
||||||
if let ExprKind::Match(_, arms, MatchSource::TryDesugar) = expr {
|
if let ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) = expr {
|
||||||
for arm in *arms {
|
for arm in *arms {
|
||||||
if let ExprKind::Ret(Some(ret)) = arm.body.kind {
|
if let ExprKind::Ret(Some(ret)) = arm.body.kind {
|
||||||
return Some(cx.typeck_results().expr_ty(ret));
|
return Some(cx.typeck_results().expr_ty(ret));
|
||||||
|
@ -64,7 +64,7 @@ pub(super) fn check(
|
|||||||
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _))
|
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, _, _))
|
||||||
),
|
),
|
||||||
ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true,
|
ExprKind::MethodCall(_, self_arg, ..) if expr.hir_id == self_arg.hir_id => true,
|
||||||
ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)
|
ExprKind::Match(_, _, MatchSource::TryDesugar(_) | MatchSource::AwaitDesugar)
|
||||||
| ExprKind::Field(..)
|
| ExprKind::Field(..)
|
||||||
| ExprKind::Index(..) => true,
|
| ExprKind::Index(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -236,7 +236,7 @@ fn indirect_usage<'tcx>(
|
|||||||
!matches!(
|
!matches!(
|
||||||
node,
|
node,
|
||||||
Node::Expr(Expr {
|
Node::Expr(Expr {
|
||||||
kind: ExprKind::Match(.., MatchSource::TryDesugar),
|
kind: ExprKind::Match(.., MatchSource::TryDesugar(_)),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -122,7 +122,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind;
|
if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar(_)) = &arg.kind;
|
||||||
if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind;
|
if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind;
|
||||||
if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind;
|
if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, ..)) = &called.kind;
|
||||||
if expr.span.ctxt() == inner_expr.span.ctxt();
|
if expr.span.ctxt() == inner_expr.span.ctxt();
|
||||||
|
@ -34,7 +34,7 @@ declare_lint_pass!(QuestionMarkUsed => [QUESTION_MARK_USED]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for QuestionMarkUsed {
|
impl<'tcx> LateLintPass<'tcx> for QuestionMarkUsed {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
if let ExprKind::Match(_, _, MatchSource::TryDesugar) = expr.kind {
|
if let ExprKind::Match(_, _, MatchSource::TryDesugar(_)) = expr.kind {
|
||||||
if !span_is_local(expr.span) {
|
if !span_is_local(expr.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ impl ReturnVisitor {
|
|||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for ReturnVisitor {
|
impl<'tcx> Visitor<'tcx> for ReturnVisitor {
|
||||||
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
|
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar) = ex.kind {
|
if let hir::ExprKind::Ret(_) | hir::ExprKind::Match(.., hir::MatchSource::TryDesugar(_)) = ex.kind {
|
||||||
self.found_return = true;
|
self.found_return = true;
|
||||||
} else {
|
} else {
|
||||||
hir_visit::walk_expr(self, ex);
|
hir_visit::walk_expr(self, ex);
|
||||||
|
@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for Return {
|
|||||||
if !in_external_macro(cx.sess(), stmt.span)
|
if !in_external_macro(cx.sess(), stmt.span)
|
||||||
&& let StmtKind::Semi(expr) = stmt.kind
|
&& let StmtKind::Semi(expr) = stmt.kind
|
||||||
&& let ExprKind::Ret(Some(ret)) = expr.kind
|
&& let ExprKind::Ret(Some(ret)) = expr.kind
|
||||||
&& let ExprKind::Match(.., MatchSource::TryDesugar) = ret.kind
|
&& let ExprKind::Match(.., MatchSource::TryDesugar(_)) = ret.kind
|
||||||
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
|
// Ensure this is not the final stmt, otherwise removing it would cause a compile error
|
||||||
&& let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id))
|
&& let OwnerNode::Item(item) = cx.tcx.hir().owner(cx.tcx.hir().get_parent_item(expr.hir_id))
|
||||||
&& let ItemKind::Fn(_, _, body) = item.kind
|
&& let ItemKind::Fn(_, _, body) = item.kind
|
||||||
|
@ -42,7 +42,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
|||||||
if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) {
|
if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) {
|
||||||
!matches!(
|
!matches!(
|
||||||
&arg.kind,
|
&arg.kind,
|
||||||
ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..)
|
ExprKind::Match(.., MatchSource::TryDesugar(_)) | ExprKind::Path(..)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match e.kind {
|
match e.kind {
|
||||||
ExprKind::Match(_, arms, MatchSource::TryDesugar) => {
|
ExprKind::Match(_, arms, MatchSource::TryDesugar(_)) => {
|
||||||
let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else {
|
let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -149,7 +149,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
|
|||||||
(Pat::Str("for"), Pat::Str("}"))
|
(Pat::Str("for"), Pat::Str("}"))
|
||||||
},
|
},
|
||||||
ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")),
|
ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")),
|
||||||
ExprKind::Match(e, _, MatchSource::TryDesugar) => (expr_search_pat(tcx, e).0, Pat::Str("?")),
|
ExprKind::Match(e, _, MatchSource::TryDesugar(_)) => (expr_search_pat(tcx, e).0, Pat::Str("?")),
|
||||||
ExprKind::Match(e, _, MatchSource::AwaitDesugar) | ExprKind::Yield(e, YieldSource::Await { .. }) => {
|
ExprKind::Match(e, _, MatchSource::AwaitDesugar) | ExprKind::Yield(e, YieldSource::Await { .. }) => {
|
||||||
(expr_search_pat(tcx, e).0, Pat::Str("await"))
|
(expr_search_pat(tcx, e).0, Pat::Str("await"))
|
||||||
},
|
},
|
||||||
|
@ -1765,7 +1765,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc
|
|||||||
|
|
||||||
if let ExprKind::Match(_, arms, ref source) = expr.kind {
|
if let ExprKind::Match(_, arms, ref source) = expr.kind {
|
||||||
// desugared from a `?` operator
|
// desugared from a `?` operator
|
||||||
if *source == MatchSource::TryDesugar {
|
if let MatchSource::TryDesugar(_) = *source {
|
||||||
return Some(expr);
|
return Some(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ pub fn for_each_expr_with_closures<'tcx, B, C: Continue>(
|
|||||||
/// returns `true` if expr contains match expr desugared from try
|
/// returns `true` if expr contains match expr desugared from try
|
||||||
fn contains_try(expr: &hir::Expr<'_>) -> bool {
|
fn contains_try(expr: &hir::Expr<'_>) -> bool {
|
||||||
for_each_expr(expr, |e| {
|
for_each_expr(expr, |e| {
|
||||||
if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar)) {
|
if matches!(e.kind, hir::ExprKind::Match(_, _, hir::MatchSource::TryDesugar(_))) {
|
||||||
ControlFlow::Break(())
|
ControlFlow::Break(())
|
||||||
} else {
|
} else {
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user