Skip to content

Commit 9e1af3f

Browse files
authoredJul 13, 2022
Rollup merge of rust-lang#98574 - dingxiangfei2009:let-else-thir, r=oli-obk
Lower let-else in MIR This MR will switch to lower let-else statements in MIR building instead. To lower let-else in MIR, we build a mini-switch two branches. One branch leads to the matching case, and the other leads to the `else` block. This arrangement will allow temporary lifetime analysis running as-is so that the temporaries are properly extended according to the same rule applied to regular `let` statements. cc rust-lang#87335 Fix rust-lang#98672
2 parents 9e2f689 + af3ba22 commit 9e1af3f

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed
 

‎clippy_lints/src/loops/while_let_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_lint::LateContext;
1111
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'tcx Block<'_>) {
1212
let (init, has_trailing_exprs) = match (loop_block.stmts, loop_block.expr) {
1313
([stmt, stmts @ ..], expr) => {
14-
if let StmtKind::Local(&Local { init: Some(e), .. }) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind {
14+
if let StmtKind::Local(&Local { init: Some(e), els: None, .. }) | StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind {
1515
(e, !stmts.is_empty() || expr.is_some())
1616
} else {
1717
return;

‎clippy_lints/src/matches/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,8 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
10411041
}
10421042

10431043
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
1044-
self.infallible_destructuring_match_linted |= infallible_destructuring_match::check(cx, local);
1044+
self.infallible_destructuring_match_linted |=
1045+
local.els.is_none() && infallible_destructuring_match::check(cx, local);
10451046
}
10461047

10471048
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {

‎clippy_lints/src/no_effect.rs

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fn check_no_effect(cx: &LateContext<'_>, stmt: &Stmt<'_>) -> bool {
9292
if_chain! {
9393
if !is_lint_allowed(cx, NO_EFFECT_UNDERSCORE_BINDING, local.hir_id);
9494
if let Some(init) = local.init;
95+
if local.els.is_none();
9596
if !local.pat.span.from_expansion();
9697
if has_no_effect(cx, init);
9798
if let PatKind::Binding(_, _, ident, _) = local.pat.kind;

‎clippy_lints/src/returns.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
1010
use rustc_middle::lint::in_external_macro;
1111
use rustc_middle::ty::subst::GenericArgKind;
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
13-
use rustc_span::hygiene::DesugaringKind;
1413
use rustc_span::source_map::Span;
1514
use rustc_span::sym;
1615

@@ -203,9 +202,7 @@ fn check_final_expr<'tcx>(
203202
check_block_return(cx, ifblock);
204203
}
205204
if let Some(else_clause) = else_clause_opt {
206-
if expr.span.desugaring_kind() != Some(DesugaringKind::LetElse) {
207-
check_final_expr(cx, else_clause, None, RetReplacement::Empty);
208-
}
205+
check_final_expr(cx, else_clause, None, RetReplacement::Empty);
209206
}
210207
},
211208
// a match expr, check all arms

‎clippy_utils/src/hir_utils.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub struct HirEqInterExpr<'a, 'b, 'tcx> {
102102
impl HirEqInterExpr<'_, '_, '_> {
103103
pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool {
104104
match (&left.kind, &right.kind) {
105-
(&StmtKind::Local(l), &StmtKind::Local(r)) => {
105+
(&StmtKind::Local(l, ), &StmtKind::Local(r, )) => {
106106
// This additional check ensures that the type of the locals are equivalent even if the init
107107
// expression or type have some inferred parts.
108108
if let Some((typeck_lhs, typeck_rhs)) = self.inner.maybe_typeck_results {
@@ -117,6 +117,7 @@ impl HirEqInterExpr<'_, '_, '_> {
117117
// these only get added if the init and type is equal.
118118
both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
119119
&& both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r))
120+
&& both(&l.els, &r.els, |l, r| self.eq_block(l, r))
120121
&& self.eq_pat(l.pat, r.pat)
121122
},
122123
(&StmtKind::Expr(l), &StmtKind::Expr(r)) | (&StmtKind::Semi(l), &StmtKind::Semi(r)) => self.eq_expr(l, r),
@@ -921,11 +922,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
921922
std::mem::discriminant(&b.kind).hash(&mut self.s);
922923

923924
match &b.kind {
924-
StmtKind::Local(local) => {
925+
StmtKind::Local(local, ) => {
925926
self.hash_pat(local.pat);
926927
if let Some(init) = local.init {
927928
self.hash_expr(init);
928929
}
930+
if let Some(els) = local.els {
931+
self.hash_block(els);
932+
}
929933
},
930934
StmtKind::Item(..) => {},
931935
StmtKind::Expr(expr) | StmtKind::Semi(expr) => {

0 commit comments

Comments
 (0)
Please sign in to comment.