Skip to content

Commit 2b1cfe5

Browse files
committed
Syntax for hir::Expr.
1 parent 3e0a1c0 commit 2b1cfe5

File tree

24 files changed

+355
-341
lines changed

24 files changed

+355
-341
lines changed

src/librustc/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ macro_rules! arena_types {
131131
[] foreign_item: rustc::hir::ForeignItem<$tcx>,
132132
[] impl_item_ref: rustc::hir::ImplItemRef,
133133
[few] macro_def: rustc::hir::MacroDef<$tcx>,
134-
[] param: rustc::hir::Param,
134+
[] param: rustc::hir::Param<$tcx>,
135135
[] path: rustc::hir::Path,
136136
[] struct_field: rustc::hir::StructField<$tcx>,
137137
[] trait_item_ref: rustc::hir::TraitItemRef,

src/librustc/hir/check_attr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl CheckAttrVisitor<'tcx> {
458458
.emit();
459459
}
460460

461-
fn check_stmt_attributes(&self, stmt: &hir::Stmt) {
461+
fn check_stmt_attributes(&self, stmt: &hir::Stmt<'_>) {
462462
// When checking statements ignore expressions, they will be checked later
463463
if let hir::StmtKind::Local(ref l) = stmt.kind {
464464
for attr in l.attrs.iter() {
@@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> {
477477
}
478478
}
479479

480-
fn check_expr_attributes(&self, expr: &hir::Expr) {
480+
fn check_expr_attributes(&self, expr: &hir::Expr<'_>) {
481481
let target = match expr.kind {
482482
hir::ExprKind::Closure(..) => Target::Closure,
483483
_ => Target::Expression,
@@ -537,12 +537,12 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
537537
intravisit::walk_impl_item(self, impl_item)
538538
}
539539

540-
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt) {
540+
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
541541
self.check_stmt_attributes(stmt);
542542
intravisit::walk_stmt(self, stmt)
543543
}
544544

545-
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
545+
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
546546
self.check_expr_attributes(expr);
547547
intravisit::walk_expr(self, expr)
548548
}

src/librustc/hir/intravisit.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub trait Visitor<'v>: Sized {
212212
}
213213
}
214214

215-
fn visit_param(&mut self, param: &'v Param) {
215+
fn visit_param(&mut self, param: &'v Param<'v>) {
216216
walk_param(self, param)
217217
}
218218

@@ -253,25 +253,25 @@ pub trait Visitor<'v>: Sized {
253253
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
254254
walk_foreign_item(self, i)
255255
}
256-
fn visit_local(&mut self, l: &'v Local) {
256+
fn visit_local(&mut self, l: &'v Local<'v>) {
257257
walk_local(self, l)
258258
}
259-
fn visit_block(&mut self, b: &'v Block) {
259+
fn visit_block(&mut self, b: &'v Block<'v>) {
260260
walk_block(self, b)
261261
}
262-
fn visit_stmt(&mut self, s: &'v Stmt) {
262+
fn visit_stmt(&mut self, s: &'v Stmt<'v>) {
263263
walk_stmt(self, s)
264264
}
265-
fn visit_arm(&mut self, a: &'v Arm) {
265+
fn visit_arm(&mut self, a: &'v Arm<'v>) {
266266
walk_arm(self, a)
267267
}
268-
fn visit_pat(&mut self, p: &'v Pat) {
268+
fn visit_pat(&mut self, p: &'v Pat<'v>) {
269269
walk_pat(self, p)
270270
}
271271
fn visit_anon_const(&mut self, c: &'v AnonConst) {
272272
walk_anon_const(self, c)
273273
}
274-
fn visit_expr(&mut self, ex: &'v Expr) {
274+
fn visit_expr(&mut self, ex: &'v Expr<'v>) {
275275
walk_expr(self, ex)
276276
}
277277
fn visit_ty(&mut self, t: &'v Ty) {
@@ -409,7 +409,7 @@ pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
409409
visitor.visit_expr(&body.value);
410410
}
411411

412-
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
412+
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
413413
// Intentionally visiting the expr first - the initialization expr
414414
// dominates the local's definition.
415415
walk_list!(visitor, visit_expr, &local.init);
@@ -462,7 +462,7 @@ where
462462
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
463463
}
464464

465-
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param) {
465+
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
466466
visitor.visit_id(param.hir_id);
467467
visitor.visit_pat(&param.pat);
468468
walk_list!(visitor, visit_attribute, &param.attrs);
@@ -684,7 +684,7 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, type_binding
684684
}
685685
}
686686

687-
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
687+
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
688688
visitor.visit_id(pattern.hir_id);
689689
match pattern.kind {
690690
PatKind::TupleStruct(ref qpath, ref children, _) => {
@@ -955,13 +955,13 @@ pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v
955955
walk_list!(visitor, visit_attribute, struct_field.attrs);
956956
}
957957

958-
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
958+
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
959959
visitor.visit_id(block.hir_id);
960960
walk_list!(visitor, visit_stmt, &block.stmts);
961961
walk_list!(visitor, visit_expr, &block.expr);
962962
}
963963

964-
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
964+
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
965965
visitor.visit_id(statement.hir_id);
966966
match statement.kind {
967967
StmtKind::Local(ref local) => visitor.visit_local(local),
@@ -977,7 +977,7 @@ pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonCo
977977
visitor.visit_nested_body(constant.body);
978978
}
979979

980-
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
980+
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
981981
visitor.visit_id(expression.hir_id);
982982
walk_list!(visitor, visit_attribute, expression.attrs.iter());
983983
match expression.kind {
@@ -1087,7 +1087,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
10871087
}
10881088
}
10891089

1090-
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
1090+
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
10911091
visitor.visit_id(arm.hir_id);
10921092
visitor.visit_pat(&arm.pat);
10931093
if let Some(ref g) = arm.guard {

src/librustc/hir/lowering.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20222022
})
20232023
}
20242024

2025-
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[NodeId; 1]>) {
2025+
fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) {
20262026
let mut ids = SmallVec::<[NodeId; 1]>::new();
20272027
if self.sess.features_untracked().impl_trait_in_bindings {
20282028
if let Some(ref ty) = l.ty {
@@ -2586,7 +2586,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25862586
bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect()
25872587
}
25882588

2589-
fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<hir::Block> {
2589+
fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<hir::Block<'hir>> {
25902590
let mut stmts = vec![];
25912591
let mut expr = None;
25922592

@@ -2614,12 +2614,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26142614

26152615
/// Lowers a block directly to an expression, presuming that it
26162616
/// has no attributes and is not targeted by a `break`.
2617-
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr {
2617+
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
26182618
let block = self.lower_block(b, false);
26192619
self.expr_block(block, AttrVec::new())
26202620
}
26212621

2622-
fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
2622+
fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat<'hir>> {
26232623
let node = match p.kind {
26242624
PatKind::Wild => hir::PatKind::Wild,
26252625
PatKind::Ident(ref binding_mode, ident, ref sub) => {
@@ -2700,7 +2700,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
27002700
&mut self,
27012701
pats: &[AstP<Pat>],
27022702
ctx: &str,
2703-
) -> (HirVec<P<hir::Pat>>, Option<usize>) {
2703+
) -> (HirVec<P<hir::Pat<'hir>>>, Option<usize>) {
27042704
let mut elems = Vec::with_capacity(pats.len());
27052705
let mut rest = None;
27062706

@@ -2737,7 +2737,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
27372737
/// When encountering `($binding_mode $ident @)? ..` (`slice`),
27382738
/// this is interpreted as a sub-slice pattern semantically.
27392739
/// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`.
2740-
fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind {
2740+
fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind<'hir> {
27412741
let mut before = Vec::new();
27422742
let mut after = Vec::new();
27432743
let mut slice = None;
@@ -2796,8 +2796,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
27962796
p: &Pat,
27972797
binding_mode: &BindingMode,
27982798
ident: Ident,
2799-
lower_sub: impl FnOnce(&mut Self) -> Option<P<hir::Pat>>,
2800-
) -> hir::PatKind {
2799+
lower_sub: impl FnOnce(&mut Self) -> Option<P<hir::Pat<'hir>>>,
2800+
) -> hir::PatKind<'hir> {
28012801
match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) {
28022802
// `None` can occur in body-less function signatures
28032803
res @ None | res @ Some(Res::Local(_)) => {
@@ -2824,12 +2824,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
28242824
}
28252825
}
28262826

2827-
fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> P<hir::Pat> {
2827+
fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> P<hir::Pat<'hir>> {
28282828
self.pat_with_node_id_of(p, hir::PatKind::Wild)
28292829
}
28302830

28312831
/// Construct a `Pat` with the `HirId` of `p.id` lowered.
2832-
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind) -> P<hir::Pat> {
2832+
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> P<hir::Pat<'hir>> {
28332833
P(hir::Pat { hir_id: self.lower_node_id(p.id), kind, span: p.span })
28342834
}
28352835

@@ -2843,7 +2843,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
28432843
}
28442844

28452845
/// Used to ban the `..` pattern in places it shouldn't be semantically.
2846-
fn ban_illegal_rest_pat(&self, sp: Span) -> hir::PatKind {
2846+
fn ban_illegal_rest_pat(&self, sp: Span) -> hir::PatKind<'hir> {
28472847
self.diagnostic()
28482848
.struct_span_err(sp, "`..` patterns are not allowed here")
28492849
.note("only allowed in tuple, tuple struct, and slice patterns")
@@ -2869,11 +2869,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
28692869
})
28702870
}
28712871

2872-
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> {
2872+
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
28732873
let kind = match s.kind {
28742874
StmtKind::Local(ref l) => {
28752875
let (l, item_ids) = self.lower_local(l);
2876-
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
2876+
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
28772877
.into_iter()
28782878
.map(|item_id| {
28792879
let item_id = hir::ItemId { id: self.lower_node_id(item_id) };
@@ -2944,36 +2944,36 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
29442944

29452945
// Helper methods for building HIR.
29462946

2947-
fn stmt(&mut self, span: Span, kind: hir::StmtKind) -> hir::Stmt {
2947+
fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
29482948
hir::Stmt { span, kind, hir_id: self.next_id() }
29492949
}
29502950

2951-
fn stmt_expr(&mut self, span: Span, expr: hir::Expr) -> hir::Stmt {
2951+
fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
29522952
self.stmt(span, hir::StmtKind::Expr(P(expr)))
29532953
}
29542954

29552955
fn stmt_let_pat(
29562956
&mut self,
29572957
attrs: AttrVec,
29582958
span: Span,
2959-
init: Option<P<hir::Expr>>,
2960-
pat: P<hir::Pat>,
2959+
init: Option<P<hir::Expr<'hir>>>,
2960+
pat: P<hir::Pat<'hir>>,
29612961
source: hir::LocalSource,
2962-
) -> hir::Stmt {
2962+
) -> hir::Stmt<'hir> {
29632963
let local = hir::Local { attrs, hir_id: self.next_id(), init, pat, source, span, ty: None };
29642964
self.stmt(span, hir::StmtKind::Local(P(local)))
29652965
}
29662966

2967-
fn block_expr(&mut self, expr: P<hir::Expr>) -> hir::Block {
2967+
fn block_expr(&mut self, expr: P<hir::Expr<'hir>>) -> hir::Block<'hir> {
29682968
self.block_all(expr.span, hir::HirVec::new(), Some(expr))
29692969
}
29702970

29712971
fn block_all(
29722972
&mut self,
29732973
span: Span,
2974-
stmts: hir::HirVec<hir::Stmt>,
2975-
expr: Option<P<hir::Expr>>,
2976-
) -> hir::Block {
2974+
stmts: hir::HirVec<hir::Stmt<'hir>>,
2975+
expr: Option<P<hir::Expr<'hir>>>,
2976+
) -> hir::Block<'hir> {
29772977
hir::Block {
29782978
stmts,
29792979
expr,
@@ -2985,33 +2985,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
29852985
}
29862986

29872987
/// Constructs a `true` or `false` literal pattern.
2988-
fn pat_bool(&mut self, span: Span, val: bool) -> P<hir::Pat> {
2988+
fn pat_bool(&mut self, span: Span, val: bool) -> P<hir::Pat<'hir>> {
29892989
let expr = self.expr_bool(span, val);
29902990
self.pat(span, hir::PatKind::Lit(P(expr)))
29912991
}
29922992

2993-
fn pat_ok(&mut self, span: Span, pat: P<hir::Pat>) -> P<hir::Pat> {
2993+
fn pat_ok(&mut self, span: Span, pat: P<hir::Pat<'hir>>) -> P<hir::Pat<'hir>> {
29942994
self.pat_std_enum(span, &[sym::result, sym::Result, sym::Ok], hir_vec![pat])
29952995
}
29962996

2997-
fn pat_err(&mut self, span: Span, pat: P<hir::Pat>) -> P<hir::Pat> {
2997+
fn pat_err(&mut self, span: Span, pat: P<hir::Pat<'hir>>) -> P<hir::Pat<'hir>> {
29982998
self.pat_std_enum(span, &[sym::result, sym::Result, sym::Err], hir_vec![pat])
29992999
}
30003000

3001-
fn pat_some(&mut self, span: Span, pat: P<hir::Pat>) -> P<hir::Pat> {
3001+
fn pat_some(&mut self, span: Span, pat: P<hir::Pat<'hir>>) -> P<hir::Pat<'hir>> {
30023002
self.pat_std_enum(span, &[sym::option, sym::Option, sym::Some], hir_vec![pat])
30033003
}
30043004

3005-
fn pat_none(&mut self, span: Span) -> P<hir::Pat> {
3005+
fn pat_none(&mut self, span: Span) -> P<hir::Pat<'hir>> {
30063006
self.pat_std_enum(span, &[sym::option, sym::Option, sym::None], hir_vec![])
30073007
}
30083008

30093009
fn pat_std_enum(
30103010
&mut self,
30113011
span: Span,
30123012
components: &[Symbol],
3013-
subpats: hir::HirVec<P<hir::Pat>>,
3014-
) -> P<hir::Pat> {
3013+
subpats: hir::HirVec<P<hir::Pat<'hir>>>,
3014+
) -> P<hir::Pat<'hir>> {
30153015
let path = self.std_path(span, components, None, true);
30163016
let qpath = hir::QPath::Resolved(None, P(path));
30173017
let pt = if subpats.is_empty() {
@@ -3022,7 +3022,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
30223022
self.pat(span, pt)
30233023
}
30243024

3025-
fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat>, hir::HirId) {
3025+
fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat<'hir>>, hir::HirId) {
30263026
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
30273027
}
30283028

@@ -3031,7 +3031,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
30313031
span: Span,
30323032
ident: Ident,
30333033
bm: hir::BindingAnnotation,
3034-
) -> (P<hir::Pat>, hir::HirId) {
3034+
) -> (P<hir::Pat<'hir>>, hir::HirId) {
30353035
let hir_id = self.next_id();
30363036

30373037
(
@@ -3044,11 +3044,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
30443044
)
30453045
}
30463046

3047-
fn pat_wild(&mut self, span: Span) -> P<hir::Pat> {
3047+
fn pat_wild(&mut self, span: Span) -> P<hir::Pat<'hir>> {
30483048
self.pat(span, hir::PatKind::Wild)
30493049
}
30503050

3051-
fn pat(&mut self, span: Span, kind: hir::PatKind) -> P<hir::Pat> {
3051+
fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> P<hir::Pat<'hir>> {
30523052
P(hir::Pat { hir_id: self.next_id(), kind, span })
30533053
}
30543054

0 commit comments

Comments
 (0)