Skip to content

Commit c80dde4

Browse files
committedJul 13, 2022
Auto merge of #99210 - Dylan-DPC:rollup-879cp1t, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #98574 (Lower let-else in MIR) - #99011 (`UnsafeCell` blocks niches inside its nested type from being available outside) - #99030 (diagnostics: error messages when struct literals fail to parse) - #99155 (Keep unstable target features for asm feature checking) - #99199 (Refactor: remove an unnecessary `span_to_snippet`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 42bd138 + 3933b2b commit c80dde4

File tree

72 files changed

+830
-830
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+830
-830
lines changed
 
Lines changed: 22 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext};
2-
use rustc_ast::{AttrVec, Block, BlockCheckMode, Expr, Local, LocalKind, Stmt, StmtKind};
2+
use rustc_ast::{Block, BlockCheckMode, Local, LocalKind, Stmt, StmtKind};
33
use rustc_hir as hir;
44
use rustc_session::parse::feature_err;
5-
use rustc_span::{sym, DesugaringKind};
5+
use rustc_span::sym;
66

77
use smallvec::SmallVec;
88

@@ -36,21 +36,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3636
match s.kind {
3737
StmtKind::Local(ref local) => {
3838
let hir_id = self.lower_node_id(s.id);
39-
match &local.kind {
40-
LocalKind::InitElse(init, els) => {
41-
let e = self.lower_let_else(hir_id, local, init, els, tail);
42-
expr = Some(e);
43-
// remaining statements are in let-else expression
44-
break;
45-
}
46-
_ => {
47-
let local = self.lower_local(local);
48-
self.alias_attrs(hir_id, local.hir_id);
49-
let kind = hir::StmtKind::Local(local);
50-
let span = self.lower_span(s.span);
51-
stmts.push(hir::Stmt { hir_id, kind, span });
52-
}
53-
}
39+
let local = self.lower_local(local);
40+
self.alias_attrs(hir_id, local.hir_id);
41+
let kind = hir::StmtKind::Local(local);
42+
let span = self.lower_span(s.span);
43+
stmts.push(hir::Stmt { hir_id, kind, span });
5444
}
5545
StmtKind::Item(ref it) => {
5646
stmts.extend(self.lower_item_ref(it).into_iter().enumerate().map(
@@ -101,10 +91,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10191
let init = l.kind.init().map(|init| self.lower_expr(init));
10292
let hir_id = self.lower_node_id(l.id);
10393
let pat = self.lower_pat(&l.pat);
94+
let els = if let LocalKind::InitElse(_, els) = &l.kind {
95+
if !self.tcx.features().let_else {
96+
feature_err(
97+
&self.tcx.sess.parse_sess,
98+
sym::let_else,
99+
l.span,
100+
"`let...else` statements are unstable",
101+
)
102+
.emit();
103+
}
104+
Some(self.lower_block(els, false))
105+
} else {
106+
None
107+
};
104108
let span = self.lower_span(l.span);
105109
let source = hir::LocalSource::Normal;
106110
self.lower_attrs(hir_id, &l.attrs);
107-
self.arena.alloc(hir::Local { hir_id, ty, pat, init, span, source })
111+
self.arena.alloc(hir::Local { hir_id, ty, pat, init, els, span, source })
108112
}
109113

110114
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
@@ -115,59 +119,4 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
115119
}
116120
}
117121
}
118-
119-
fn lower_let_else(
120-
&mut self,
121-
stmt_hir_id: hir::HirId,
122-
local: &Local,
123-
init: &Expr,
124-
els: &Block,
125-
tail: &[Stmt],
126-
) -> &'hir hir::Expr<'hir> {
127-
let ty = local
128-
.ty
129-
.as_ref()
130-
.map(|t| self.lower_ty(t, ImplTraitContext::Disallowed(ImplTraitPosition::Variable)));
131-
let span = self.lower_span(local.span);
132-
let span = self.mark_span_with_reason(DesugaringKind::LetElse, span, None);
133-
let init = self.lower_expr(init);
134-
let local_hir_id = self.lower_node_id(local.id);
135-
self.lower_attrs(local_hir_id, &local.attrs);
136-
let let_expr = {
137-
let lex = self.arena.alloc(hir::Let {
138-
hir_id: local_hir_id,
139-
pat: self.lower_pat(&local.pat),
140-
ty,
141-
init,
142-
span,
143-
});
144-
self.arena.alloc(self.expr(span, hir::ExprKind::Let(lex), AttrVec::new()))
145-
};
146-
let then_expr = {
147-
let (stmts, expr) = self.lower_stmts(tail);
148-
let block = self.block_all(span, stmts, expr);
149-
self.arena.alloc(self.expr_block(block, AttrVec::new()))
150-
};
151-
let else_expr = {
152-
let block = self.lower_block(els, false);
153-
self.arena.alloc(self.expr_block(block, AttrVec::new()))
154-
};
155-
self.alias_attrs(let_expr.hir_id, local_hir_id);
156-
self.alias_attrs(else_expr.hir_id, local_hir_id);
157-
let if_expr = self.arena.alloc(hir::Expr {
158-
hir_id: stmt_hir_id,
159-
span,
160-
kind: hir::ExprKind::If(let_expr, then_expr, Some(else_expr)),
161-
});
162-
if !self.tcx.features().let_else {
163-
feature_err(
164-
&self.tcx.sess.parse_sess,
165-
sym::let_else,
166-
local.span,
167-
"`let...else` statements are unstable",
168-
)
169-
.emit();
170-
}
171-
if_expr
172-
}
173122
}

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21462146
debug_assert!(!a.is_empty());
21472147
self.attrs.insert(hir_id.local_id, a);
21482148
}
2149-
let local = hir::Local { hir_id, init, pat, source, span: self.lower_span(span), ty: None };
2149+
let local = hir::Local {
2150+
hir_id,
2151+
init,
2152+
pat,
2153+
els: None,
2154+
source,
2155+
span: self.lower_span(span),
2156+
ty: None,
2157+
};
21502158
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
21512159
}
21522160

0 commit comments

Comments
 (0)
Please sign in to comment.