Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit afbd004

Browse files
committedJan 17, 2019
Remove hir::StmtKind::Decl.
It's a level of indirection that hurts far more than it helps. The code is simpler without it. (This commit cuts more than 120 lines of code.) In particular, this commit removes some unnecessary `Span`s within `DeclKind` that were always identical to those in the enclosing `Stmt`, and some unnecessary allocations via `P`.
1 parent b2ce5a9 commit afbd004

File tree

16 files changed

+150
-272
lines changed

16 files changed

+150
-272
lines changed
 

‎src/librustc/cfg/construct.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,20 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
100100

101101
fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex {
102102
let hir_id = self.tcx.hir().node_to_hir_id(stmt.id);
103-
match stmt.node {
104-
hir::StmtKind::Decl(ref decl) => {
105-
let exit = self.decl(&decl, pred);
106-
self.add_ast_node(hir_id.local_id, &[exit])
103+
let exit = match stmt.node {
104+
hir::StmtKind::Local(ref local) => {
105+
let init_exit = self.opt_expr(&local.init, pred);
106+
self.pat(&local.pat, init_exit)
107+
}
108+
hir::StmtKind::Item(_) => {
109+
pred
107110
}
108-
109111
hir::StmtKind::Expr(ref expr) |
110112
hir::StmtKind::Semi(ref expr) => {
111-
let exit = self.expr(&expr, pred);
112-
self.add_ast_node(hir_id.local_id, &[exit])
113+
self.expr(&expr, pred)
113114
}
114-
}
115-
}
116-
117-
fn decl(&mut self, decl: &hir::Decl, pred: CFGIndex) -> CFGIndex {
118-
match decl.node {
119-
hir::DeclKind::Local(ref local) => {
120-
let init_exit = self.opt_expr(&local.init, pred);
121-
self.pat(&local.pat, init_exit)
122-
}
123-
124-
hir::DeclKind::Item(_) => pred,
125-
}
115+
};
116+
self.add_ast_node(hir_id.local_id, &[exit])
126117
}
127118

128119
fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {

‎src/librustc/hir/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
298298

299299
fn check_stmt_attributes(&self, stmt: &hir::Stmt) {
300300
// When checking statements ignore expressions, they will be checked later
301-
if let hir::StmtKind::Decl(..) = stmt.node {
302-
for attr in stmt.node.attrs() {
301+
if let hir::StmtKind::Local(ref l) = stmt.node {
302+
for attr in l.attrs.iter() {
303303
if attr.check_name("inline") {
304304
self.check_inline(attr, &stmt.span, Target::Statement);
305305
}

‎src/librustc/hir/intravisit.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ pub trait Visitor<'v> : Sized {
260260
fn visit_pat(&mut self, p: &'v Pat) {
261261
walk_pat(self, p)
262262
}
263-
fn visit_decl(&mut self, d: &'v Decl) {
264-
walk_decl(self, d)
265-
}
266263
fn visit_anon_const(&mut self, c: &'v AnonConst) {
267264
walk_anon_const(self, c)
268265
}
@@ -955,23 +952,15 @@ pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
955952
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
956953
visitor.visit_id(statement.id);
957954
match statement.node {
958-
StmtKind::Decl(ref declaration) => {
959-
visitor.visit_decl(declaration)
960-
}
955+
StmtKind::Local(ref local) => visitor.visit_local(local),
956+
StmtKind::Item(ref item) => visitor.visit_nested_item(**item),
961957
StmtKind::Expr(ref expression) |
962958
StmtKind::Semi(ref expression) => {
963959
visitor.visit_expr(expression)
964960
}
965961
}
966962
}
967963

968-
pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) {
969-
match declaration.node {
970-
DeclKind::Local(ref local) => visitor.visit_local(local),
971-
DeclKind::Item(item) => visitor.visit_nested_item(item),
972-
}
973-
}
974-
975964
pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
976965
visitor.visit_id(constant.id);
977966
visitor.visit_nested_body(constant.body);

‎src/librustc/hir/lowering.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ impl<'a> LoweringContext<'a> {
19571957
)
19581958
}
19591959

1960-
fn lower_local(&mut self, l: &Local) -> (P<hir::Local>, SmallVec<[hir::ItemId; 1]>) {
1960+
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[hir::ItemId; 1]>) {
19611961
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(l.id);
19621962
let mut ids = SmallVec::<[hir::ItemId; 1]>::new();
19631963
if self.sess.features_untracked().impl_trait_in_bindings {
@@ -1967,7 +1967,7 @@ impl<'a> LoweringContext<'a> {
19671967
}
19681968
}
19691969
let parent_def_id = DefId::local(self.current_hir_id_owner.last().unwrap().0);
1970-
(P(hir::Local {
1970+
(hir::Local {
19711971
id: node_id,
19721972
hir_id,
19731973
ty: l.ty
@@ -1984,7 +1984,7 @@ impl<'a> LoweringContext<'a> {
19841984
span: l.span,
19851985
attrs: l.attrs.clone(),
19861986
source: hir::LocalSource::Normal,
1987-
}), ids)
1987+
}, ids)
19881988
}
19891989

19901990
fn lower_mutability(&mut self, m: Mutability) -> hir::Mutability {
@@ -4537,23 +4537,13 @@ impl<'a> LoweringContext<'a> {
45374537
.into_iter()
45384538
.map(|item_id| hir::Stmt {
45394539
id: self.next_id().node_id,
4540-
node: hir::StmtKind::Decl(
4541-
P(Spanned {
4542-
node: hir::DeclKind::Item(item_id),
4543-
span: s.span,
4544-
}),
4545-
),
4540+
node: hir::StmtKind::Item(P(item_id)),
45464541
span: s.span,
45474542
})
45484543
.collect();
45494544
ids.push(hir::Stmt {
45504545
id: self.lower_node_id(s.id).node_id,
4551-
node: hir::StmtKind::Decl(
4552-
P(Spanned {
4553-
node: hir::DeclKind::Local(l),
4554-
span: s.span,
4555-
}),
4556-
),
4546+
node: hir::StmtKind::Local(P(l)),
45574547
span: s.span,
45584548
});
45594549
return ids;
@@ -4567,12 +4557,7 @@ impl<'a> LoweringContext<'a> {
45674557
id: id.take()
45684558
.map(|id| self.lower_node_id(id).node_id)
45694559
.unwrap_or_else(|| self.next_id().node_id),
4570-
node: hir::StmtKind::Decl(
4571-
P(Spanned {
4572-
node: hir::DeclKind::Item(item_id),
4573-
span: s.span,
4574-
}),
4575-
),
4560+
node: hir::StmtKind::Item(P(item_id)),
45764561
span: s.span,
45774562
})
45784563
.collect();
@@ -4799,7 +4784,7 @@ impl<'a> LoweringContext<'a> {
47994784
) -> hir::Stmt {
48004785
let LoweredNodeId { node_id, hir_id } = self.next_id();
48014786

4802-
let local = P(hir::Local {
4787+
let local = hir::Local {
48034788
pat,
48044789
ty: None,
48054790
init: ex,
@@ -4808,11 +4793,10 @@ impl<'a> LoweringContext<'a> {
48084793
span: sp,
48094794
attrs: ThinVec::new(),
48104795
source,
4811-
});
4812-
let decl = respan(sp, hir::DeclKind::Local(local));
4796+
};
48134797
hir::Stmt {
48144798
id: self.next_id().node_id,
4815-
node: hir::StmtKind::Decl(P(decl)),
4799+
node: hir::StmtKind::Local(P(local)),
48164800
span: sp
48174801
}
48184802
}

‎src/librustc/hir/mod.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,10 @@ impl fmt::Debug for Stmt {
11601160

11611161
#[derive(Clone, RustcEncodable, RustcDecodable)]
11621162
pub enum StmtKind {
1163-
/// Could be an item or a local (let) binding:
1164-
Decl(P<Decl>),
1163+
/// A local (let) binding:
1164+
Local(P<Local>),
1165+
/// An item binding:
1166+
Item(P<ItemId>),
11651167

11661168
/// Expr without trailing semi-colon (must have unit type):
11671169
Expr(P<Expr>),
@@ -1173,7 +1175,8 @@ pub enum StmtKind {
11731175
impl StmtKind {
11741176
pub fn attrs(&self) -> &[Attribute] {
11751177
match *self {
1176-
StmtKind::Decl(ref d) => d.node.attrs(),
1178+
StmtKind::Local(ref l) => &l.attrs,
1179+
StmtKind::Item(_) => &[],
11771180
StmtKind::Expr(ref e) |
11781181
StmtKind::Semi(ref e) => &e.attrs,
11791182
}
@@ -1194,32 +1197,6 @@ pub struct Local {
11941197
pub source: LocalSource,
11951198
}
11961199

1197-
pub type Decl = Spanned<DeclKind>;
1198-
1199-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
1200-
pub enum DeclKind {
1201-
/// A local (let) binding:
1202-
Local(P<Local>),
1203-
/// An item binding:
1204-
Item(ItemId),
1205-
}
1206-
1207-
impl DeclKind {
1208-
pub fn attrs(&self) -> &[Attribute] {
1209-
match *self {
1210-
DeclKind::Local(ref l) => &l.attrs,
1211-
DeclKind::Item(_) => &[]
1212-
}
1213-
}
1214-
1215-
pub fn is_local(&self) -> bool {
1216-
match *self {
1217-
DeclKind::Local(_) => true,
1218-
_ => false,
1219-
}
1220-
}
1221-
}
1222-
12231200
/// represents one arm of a 'match'
12241201
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
12251202
pub struct Arm {

‎src/librustc/hir/print.rs

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,23 @@ impl<'a> State<'a> {
992992
pub fn print_stmt(&mut self, st: &hir::Stmt) -> io::Result<()> {
993993
self.maybe_print_comment(st.span.lo())?;
994994
match st.node {
995-
hir::StmtKind::Decl(ref decl) => {
996-
self.print_decl(&decl)?;
995+
hir::StmtKind::Local(ref loc) => {
996+
self.space_if_not_bol()?;
997+
self.ibox(indent_unit)?;
998+
self.word_nbsp("let")?;
999+
1000+
self.ibox(indent_unit)?;
1001+
self.print_local_decl(&loc)?;
1002+
self.end()?;
1003+
if let Some(ref init) = loc.init {
1004+
self.nbsp()?;
1005+
self.word_space("=")?;
1006+
self.print_expr(&init)?;
1007+
}
1008+
self.end()?
1009+
}
1010+
hir::StmtKind::Item(ref item) => {
1011+
self.ann.nested(self, Nested::Item(**item))?
9971012
}
9981013
hir::StmtKind::Expr(ref expr) => {
9991014
self.space_if_not_bol()?;
@@ -1562,30 +1577,6 @@ impl<'a> State<'a> {
15621577
Ok(())
15631578
}
15641579

1565-
pub fn print_decl(&mut self, decl: &hir::Decl) -> io::Result<()> {
1566-
self.maybe_print_comment(decl.span.lo())?;
1567-
match decl.node {
1568-
hir::DeclKind::Local(ref loc) => {
1569-
self.space_if_not_bol()?;
1570-
self.ibox(indent_unit)?;
1571-
self.word_nbsp("let")?;
1572-
1573-
self.ibox(indent_unit)?;
1574-
self.print_local_decl(&loc)?;
1575-
self.end()?;
1576-
if let Some(ref init) = loc.init {
1577-
self.nbsp()?;
1578-
self.word_space("=")?;
1579-
self.print_expr(&init)?;
1580-
}
1581-
self.end()
1582-
}
1583-
hir::DeclKind::Item(item) => {
1584-
self.ann.nested(self, Nested::Item(item))
1585-
}
1586-
}
1587-
}
1588-
15891580
pub fn print_usize(&mut self, i: usize) -> io::Result<()> {
15901581
self.s.word(i.to_string())
15911582
}
@@ -2401,18 +2392,10 @@ fn expr_requires_semi_to_be_stmt(e: &hir::Expr) -> bool {
24012392
/// seen the semicolon, and thus don't need another.
24022393
fn stmt_ends_with_semi(stmt: &hir::StmtKind) -> bool {
24032394
match *stmt {
2404-
hir::StmtKind::Decl(ref d) => {
2405-
match d.node {
2406-
hir::DeclKind::Local(_) => true,
2407-
hir::DeclKind::Item(_) => false,
2408-
}
2409-
}
2410-
hir::StmtKind::Expr(ref e) => {
2411-
expr_requires_semi_to_be_stmt(&e)
2412-
}
2413-
hir::StmtKind::Semi(..) => {
2414-
false
2415-
}
2395+
hir::StmtKind::Local(_) => true,
2396+
hir::StmtKind::Item(_) => false,
2397+
hir::StmtKind::Expr(ref e) => expr_requires_semi_to_be_stmt(&e),
2398+
hir::StmtKind::Semi(..) => false,
24162399
}
24172400
}
24182401

‎src/librustc/ich/impls_hir.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,6 @@ impl_stable_hash_for!(struct hir::Local {
501501
source
502502
});
503503

504-
impl_stable_hash_for_spanned!(hir::DeclKind);
505-
impl_stable_hash_for!(enum hir::DeclKind {
506-
Local(local),
507-
Item(item_id)
508-
});
509-
510504
impl_stable_hash_for!(struct hir::Arm {
511505
attrs,
512506
pats,
@@ -946,7 +940,8 @@ impl_stable_hash_for!(enum hir::ForeignItemKind {
946940
});
947941

948942
impl_stable_hash_for!(enum hir::StmtKind {
949-
Decl(decl),
943+
Local(local),
944+
Item(item_id),
950945
Expr(expr),
951946
Semi(expr)
952947
});

‎src/librustc/lint/context.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,6 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> {
941941
hir_visit::walk_arm(self, a);
942942
}
943943

944-
fn visit_decl(&mut self, d: &'tcx hir::Decl) {
945-
run_lints!(self, check_decl, d);
946-
hir_visit::walk_decl(self, d);
947-
}
948-
949944
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam) {
950945
run_lints!(self, check_generic_param, p);
951946
hir_visit::walk_generic_param(self, p);

‎src/librustc/lint/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ macro_rules! late_lint_methods {
191191
fn check_stmt(a: &$hir hir::Stmt);
192192
fn check_arm(a: &$hir hir::Arm);
193193
fn check_pat(a: &$hir hir::Pat);
194-
fn check_decl(a: &$hir hir::Decl);
195194
fn check_expr(a: &$hir hir::Expr);
196195
fn check_expr_post(a: &$hir hir::Expr);
197196
fn check_ty(a: &$hir hir::Ty);

‎src/librustc/middle/expr_use_visitor.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -589,17 +589,13 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
589589

590590
fn walk_stmt(&mut self, stmt: &hir::Stmt) {
591591
match stmt.node {
592-
hir::StmtKind::Decl(ref decl) => {
593-
match decl.node {
594-
hir::DeclKind::Local(ref local) => {
595-
self.walk_local(&local);
596-
}
592+
hir::StmtKind::Local(ref local) => {
593+
self.walk_local(&local);
594+
}
597595

598-
hir::DeclKind::Item(_) => {
599-
// we don't visit nested items in this visitor,
600-
// only the fn body we were given.
601-
}
602-
}
596+
hir::StmtKind::Item(_) => {
597+
// we don't visit nested items in this visitor,
598+
// only the fn body we were given.
603599
}
604600

605601
hir::StmtKind::Expr(ref expr) |

‎src/librustc/middle/liveness.rs

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -956,46 +956,31 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
956956
fn propagate_through_stmt(&mut self, stmt: &hir::Stmt, succ: LiveNode)
957957
-> LiveNode {
958958
match stmt.node {
959-
hir::StmtKind::Decl(ref decl) => {
960-
self.propagate_through_decl(&decl, succ)
961-
}
959+
hir::StmtKind::Local(ref local) => {
960+
// Note: we mark the variable as defined regardless of whether
961+
// there is an initializer. Initially I had thought to only mark
962+
// the live variable as defined if it was initialized, and then we
963+
// could check for uninit variables just by scanning what is live
964+
// at the start of the function. But that doesn't work so well for
965+
// immutable variables defined in a loop:
966+
// loop { let x; x = 5; }
967+
// because the "assignment" loops back around and generates an error.
968+
//
969+
// So now we just check that variables defined w/o an
970+
// initializer are not live at the point of their
971+
// initialization, which is mildly more complex than checking
972+
// once at the func header but otherwise equivalent.
962973

974+
let succ = self.propagate_through_opt_expr(local.init.as_ref().map(|e| &**e), succ);
975+
self.define_bindings_in_pat(&local.pat, succ)
976+
}
977+
hir::StmtKind::Item(..) => succ,
963978
hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => {
964979
self.propagate_through_expr(&expr, succ)
965980
}
966981
}
967982
}
968983

969-
fn propagate_through_decl(&mut self, decl: &hir::Decl, succ: LiveNode)
970-
-> LiveNode {
971-
match decl.node {
972-
hir::DeclKind::Local(ref local) => {
973-
self.propagate_through_local(&local, succ)
974-
}
975-
hir::DeclKind::Item(_) => succ,
976-
}
977-
}
978-
979-
fn propagate_through_local(&mut self, local: &hir::Local, succ: LiveNode)
980-
-> LiveNode {
981-
// Note: we mark the variable as defined regardless of whether
982-
// there is an initializer. Initially I had thought to only mark
983-
// the live variable as defined if it was initialized, and then we
984-
// could check for uninit variables just by scanning what is live
985-
// at the start of the function. But that doesn't work so well for
986-
// immutable variables defined in a loop:
987-
// loop { let x; x = 5; }
988-
// because the "assignment" loops back around and generates an error.
989-
//
990-
// So now we just check that variables defined w/o an
991-
// initializer are not live at the point of their
992-
// initialization, which is mildly more complex than checking
993-
// once at the func header but otherwise equivalent.
994-
995-
let succ = self.propagate_through_opt_expr(local.init.as_ref().map(|e| &**e), succ);
996-
self.define_bindings_in_pat(&local.pat, succ)
997-
}
998-
999984
fn propagate_through_exprs(&mut self, exprs: &[Expr], succ: LiveNode)
1000985
-> LiveNode {
1001986
exprs.iter().rev().fold(succ, |succ, expr| {

‎src/librustc/middle/region.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -784,20 +784,25 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk:
784784
// index information.)
785785

786786
for (i, statement) in blk.stmts.iter().enumerate() {
787-
if let hir::StmtKind::Decl(..) = statement.node {
788-
// Each StmtKind::Decl introduces a subscope for bindings
789-
// introduced by the declaration; this subscope covers
790-
// a suffix of the block . Each subscope in a block
791-
// has the previous subscope in the block as a parent,
792-
// except for the first such subscope, which has the
793-
// block itself as a parent.
794-
visitor.enter_scope(
795-
Scope {
796-
id: blk.hir_id.local_id,
797-
data: ScopeData::Remainder(FirstStatementIndex::new(i))
798-
}
799-
);
800-
visitor.cx.var_parent = visitor.cx.parent;
787+
match statement.node {
788+
hir::StmtKind::Local(..) |
789+
hir::StmtKind::Item(..) => {
790+
// Each declaration introduces a subscope for bindings
791+
// introduced by the declaration; this subscope covers a
792+
// suffix of the block. Each subscope in a block has the
793+
// previous subscope in the block as a parent, except for
794+
// the first such subscope, which has the block itself as a
795+
// parent.
796+
visitor.enter_scope(
797+
Scope {
798+
id: blk.hir_id.local_id,
799+
data: ScopeData::Remainder(FirstStatementIndex::new(i))
800+
}
801+
);
802+
visitor.cx.var_parent = visitor.cx.parent;
803+
}
804+
hir::StmtKind::Expr(..) |
805+
hir::StmtKind::Semi(..) => {}
801806
}
802807
visitor.visit_stmt(statement)
803808
}

‎src/librustc_mir/hair/cx/block.rs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,52 +64,48 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
6464
span: stmt_span,
6565
})))
6666
}
67-
hir::StmtKind::Decl(ref decl) => {
68-
match decl.node {
69-
hir::DeclKind::Item(..) => {
70-
// ignore for purposes of the MIR
71-
}
72-
hir::DeclKind::Local(ref local) => {
73-
let remainder_scope = region::Scope {
74-
id: block_id,
75-
data: region::ScopeData::Remainder(
76-
region::FirstStatementIndex::new(index)),
77-
};
78-
79-
let mut pattern = cx.pattern_from_hir(&local.pat);
67+
hir::StmtKind::Item(..) => {
68+
// ignore for purposes of the MIR
69+
}
70+
hir::StmtKind::Local(ref local) => {
71+
let remainder_scope = region::Scope {
72+
id: block_id,
73+
data: region::ScopeData::Remainder(
74+
region::FirstStatementIndex::new(index)),
75+
};
8076

81-
if let Some(ty) = &local.ty {
82-
if let Some(&user_ty) = cx.tables.user_provided_types().get(ty.hir_id) {
83-
debug!("mirror_stmts: user_ty={:?}", user_ty);
84-
pattern = Pattern {
85-
ty: pattern.ty,
86-
span: pattern.span,
87-
kind: Box::new(PatternKind::AscribeUserType {
88-
user_ty: PatternTypeProjection::from_user_type(user_ty),
89-
user_ty_span: ty.span,
90-
subpattern: pattern,
91-
variance: ty::Variance::Covariant,
92-
})
93-
};
94-
}
95-
}
77+
let mut pattern = cx.pattern_from_hir(&local.pat);
9678

97-
result.push(StmtRef::Mirror(Box::new(Stmt {
98-
kind: StmtKind::Let {
99-
remainder_scope: remainder_scope,
100-
init_scope: region::Scope {
101-
id: hir_id.local_id,
102-
data: region::ScopeData::Node
103-
},
104-
pattern,
105-
initializer: local.init.to_ref(),
106-
lint_level: cx.lint_level_of(local.id),
107-
},
108-
opt_destruction_scope: opt_dxn_ext,
109-
span: stmt_span,
110-
})));
79+
if let Some(ty) = &local.ty {
80+
if let Some(&user_ty) = cx.tables.user_provided_types().get(ty.hir_id) {
81+
debug!("mirror_stmts: user_ty={:?}", user_ty);
82+
pattern = Pattern {
83+
ty: pattern.ty,
84+
span: pattern.span,
85+
kind: Box::new(PatternKind::AscribeUserType {
86+
user_ty: PatternTypeProjection::from_user_type(user_ty),
87+
user_ty_span: ty.span,
88+
subpattern: pattern,
89+
variance: ty::Variance::Covariant,
90+
})
91+
};
11192
}
11293
}
94+
95+
result.push(StmtRef::Mirror(Box::new(Stmt {
96+
kind: StmtKind::Let {
97+
remainder_scope: remainder_scope,
98+
init_scope: region::Scope {
99+
id: hir_id.local_id,
100+
data: region::ScopeData::Node
101+
},
102+
pattern,
103+
initializer: local.init.to_ref(),
104+
lint_level: cx.lint_level_of(local.id),
105+
},
106+
opt_destruction_scope: opt_dxn_ext,
107+
span: stmt_span,
108+
})));
113109
}
114110
}
115111
}

‎src/librustc_passes/hir_stats.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
158158
hir_visit::walk_pat(self, p)
159159
}
160160

161-
fn visit_decl(&mut self, d: &'v hir::Decl) {
162-
self.record("Decl", Id::None, d);
163-
hir_visit::walk_decl(self, d)
164-
}
165-
166161
fn visit_expr(&mut self, ex: &'v hir::Expr) {
167162
self.record("Expr", Id::Node(ex.id), ex);
168163
hir_visit::walk_expr(self, ex)

‎src/librustc_passes/rvalue_promotion.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,20 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
220220

221221
fn check_stmt(&mut self, stmt: &'tcx hir::Stmt) -> Promotability {
222222
match stmt.node {
223-
hir::StmtKind::Decl(ref decl) => {
224-
match &decl.node {
225-
hir::DeclKind::Local(local) => {
226-
if self.remove_mut_rvalue_borrow(&local.pat) {
227-
if let Some(init) = &local.init {
228-
self.mut_rvalue_borrows.insert(init.id);
229-
}
230-
}
231-
232-
if let Some(ref expr) = local.init {
233-
let _ = self.check_expr(&expr);
234-
}
235-
NotPromotable
223+
hir::StmtKind::Local(ref local) => {
224+
if self.remove_mut_rvalue_borrow(&local.pat) {
225+
if let Some(init) = &local.init {
226+
self.mut_rvalue_borrows.insert(init.id);
236227
}
237-
// Item statements are allowed
238-
hir::DeclKind::Item(_) => Promotable
239228
}
229+
230+
if let Some(ref expr) = local.init {
231+
let _ = self.check_expr(&expr);
232+
}
233+
NotPromotable
240234
}
235+
// Item statements are allowed
236+
hir::StmtKind::Item(..) => Promotable,
241237
hir::StmtKind::Expr(ref box_expr) |
242238
hir::StmtKind::Semi(ref box_expr) => {
243239
let _ = self.check_expr(box_expr);

‎src/librustc_typeck/check/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,12 +4840,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48404840
pub fn check_stmt(&self, stmt: &'gcx hir::Stmt) {
48414841
// Don't do all the complex logic below for `DeclItem`.
48424842
match stmt.node {
4843-
hir::StmtKind::Decl(ref decl) => {
4844-
if let hir::DeclKind::Item(_) = decl.node {
4845-
return
4846-
}
4847-
}
4848-
hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {}
4843+
hir::StmtKind::Item(..) => return,
4844+
hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {}
48494845
}
48504846

48514847
self.warn_if_unreachable(stmt.id, stmt.span, "statement");
@@ -4857,15 +4853,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
48574853
self.has_errors.set(false);
48584854

48594855
match stmt.node {
4860-
hir::StmtKind::Decl(ref decl) => {
4861-
match decl.node {
4862-
hir::DeclKind::Local(ref l) => {
4863-
self.check_decl_local(&l);
4864-
}
4865-
// Ignore for now.
4866-
hir::DeclKind::Item(_) => ()
4867-
}
4856+
hir::StmtKind::Local(ref l) => {
4857+
self.check_decl_local(&l);
48684858
}
4859+
// Ignore for now.
4860+
hir::StmtKind::Item(_) => {}
48694861
hir::StmtKind::Expr(ref expr) => {
48704862
// Check with expected type of `()`.
48714863
self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit());

0 commit comments

Comments
 (0)
Please sign in to comment.