Syntax for hir::Expr.

This commit is contained in:
Camille GILLOT 2019-11-29 13:43:03 +01:00
parent 3e0a1c0910
commit 2b1cfe5b5b
24 changed files with 355 additions and 341 deletions

View File

@ -131,7 +131,7 @@ macro_rules! arena_types {
[] foreign_item: rustc::hir::ForeignItem<$tcx>, [] foreign_item: rustc::hir::ForeignItem<$tcx>,
[] impl_item_ref: rustc::hir::ImplItemRef, [] impl_item_ref: rustc::hir::ImplItemRef,
[few] macro_def: rustc::hir::MacroDef<$tcx>, [few] macro_def: rustc::hir::MacroDef<$tcx>,
[] param: rustc::hir::Param, [] param: rustc::hir::Param<$tcx>,
[] path: rustc::hir::Path, [] path: rustc::hir::Path,
[] struct_field: rustc::hir::StructField<$tcx>, [] struct_field: rustc::hir::StructField<$tcx>,
[] trait_item_ref: rustc::hir::TraitItemRef, [] trait_item_ref: rustc::hir::TraitItemRef,

View File

@ -458,7 +458,7 @@ impl CheckAttrVisitor<'tcx> {
.emit(); .emit();
} }
fn check_stmt_attributes(&self, stmt: &hir::Stmt) { fn check_stmt_attributes(&self, stmt: &hir::Stmt<'_>) {
// When checking statements ignore expressions, they will be checked later // When checking statements ignore expressions, they will be checked later
if let hir::StmtKind::Local(ref l) = stmt.kind { if let hir::StmtKind::Local(ref l) = stmt.kind {
for attr in l.attrs.iter() { for attr in l.attrs.iter() {
@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> {
} }
} }
fn check_expr_attributes(&self, expr: &hir::Expr) { fn check_expr_attributes(&self, expr: &hir::Expr<'_>) {
let target = match expr.kind { let target = match expr.kind {
hir::ExprKind::Closure(..) => Target::Closure, hir::ExprKind::Closure(..) => Target::Closure,
_ => Target::Expression, _ => Target::Expression,
@ -537,12 +537,12 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
intravisit::walk_impl_item(self, impl_item) intravisit::walk_impl_item(self, impl_item)
} }
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt) { fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
self.check_stmt_attributes(stmt); self.check_stmt_attributes(stmt);
intravisit::walk_stmt(self, stmt) intravisit::walk_stmt(self, stmt)
} }
fn visit_expr(&mut self, expr: &'tcx hir::Expr) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
self.check_expr_attributes(expr); self.check_expr_attributes(expr);
intravisit::walk_expr(self, expr) intravisit::walk_expr(self, expr)
} }

View File

@ -212,7 +212,7 @@ pub trait Visitor<'v>: Sized {
} }
} }
fn visit_param(&mut self, param: &'v Param) { fn visit_param(&mut self, param: &'v Param<'v>) {
walk_param(self, param) walk_param(self, param)
} }
@ -253,25 +253,25 @@ pub trait Visitor<'v>: Sized {
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) { fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
walk_foreign_item(self, i) walk_foreign_item(self, i)
} }
fn visit_local(&mut self, l: &'v Local) { fn visit_local(&mut self, l: &'v Local<'v>) {
walk_local(self, l) walk_local(self, l)
} }
fn visit_block(&mut self, b: &'v Block) { fn visit_block(&mut self, b: &'v Block<'v>) {
walk_block(self, b) walk_block(self, b)
} }
fn visit_stmt(&mut self, s: &'v Stmt) { fn visit_stmt(&mut self, s: &'v Stmt<'v>) {
walk_stmt(self, s) walk_stmt(self, s)
} }
fn visit_arm(&mut self, a: &'v Arm) { fn visit_arm(&mut self, a: &'v Arm<'v>) {
walk_arm(self, a) walk_arm(self, a)
} }
fn visit_pat(&mut self, p: &'v Pat) { fn visit_pat(&mut self, p: &'v Pat<'v>) {
walk_pat(self, p) walk_pat(self, p)
} }
fn visit_anon_const(&mut self, c: &'v AnonConst) { fn visit_anon_const(&mut self, c: &'v AnonConst) {
walk_anon_const(self, c) walk_anon_const(self, c)
} }
fn visit_expr(&mut self, ex: &'v Expr) { fn visit_expr(&mut self, ex: &'v Expr<'v>) {
walk_expr(self, ex) walk_expr(self, ex)
} }
fn visit_ty(&mut self, t: &'v Ty) { 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>) {
visitor.visit_expr(&body.value); visitor.visit_expr(&body.value);
} }
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
// Intentionally visiting the expr first - the initialization expr // Intentionally visiting the expr first - the initialization expr
// dominates the local's definition. // dominates the local's definition.
walk_list!(visitor, visit_expr, &local.init); walk_list!(visitor, visit_expr, &local.init);
@ -462,7 +462,7 @@ where
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id) visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
} }
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param) { pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
visitor.visit_id(param.hir_id); visitor.visit_id(param.hir_id);
visitor.visit_pat(&param.pat); visitor.visit_pat(&param.pat);
walk_list!(visitor, visit_attribute, &param.attrs); 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
} }
} }
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
visitor.visit_id(pattern.hir_id); visitor.visit_id(pattern.hir_id);
match pattern.kind { match pattern.kind {
PatKind::TupleStruct(ref qpath, ref children, _) => { 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
walk_list!(visitor, visit_attribute, struct_field.attrs); walk_list!(visitor, visit_attribute, struct_field.attrs);
} }
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
visitor.visit_id(block.hir_id); visitor.visit_id(block.hir_id);
walk_list!(visitor, visit_stmt, &block.stmts); walk_list!(visitor, visit_stmt, &block.stmts);
walk_list!(visitor, visit_expr, &block.expr); walk_list!(visitor, visit_expr, &block.expr);
} }
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
visitor.visit_id(statement.hir_id); visitor.visit_id(statement.hir_id);
match statement.kind { match statement.kind {
StmtKind::Local(ref local) => visitor.visit_local(local), 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
visitor.visit_nested_body(constant.body); visitor.visit_nested_body(constant.body);
} }
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
visitor.visit_id(expression.hir_id); visitor.visit_id(expression.hir_id);
walk_list!(visitor, visit_attribute, expression.attrs.iter()); walk_list!(visitor, visit_attribute, expression.attrs.iter());
match expression.kind { match expression.kind {
@ -1087,7 +1087,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
} }
} }
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
visitor.visit_id(arm.hir_id); visitor.visit_id(arm.hir_id);
visitor.visit_pat(&arm.pat); visitor.visit_pat(&arm.pat);
if let Some(ref g) = arm.guard { if let Some(ref g) = arm.guard {

View File

@ -2022,7 +2022,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}) })
} }
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[NodeId; 1]>) { fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) {
let mut ids = SmallVec::<[NodeId; 1]>::new(); let mut ids = SmallVec::<[NodeId; 1]>::new();
if self.sess.features_untracked().impl_trait_in_bindings { if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty { if let Some(ref ty) = l.ty {
@ -2586,7 +2586,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect() bounds.iter().map(|bound| self.lower_param_bound(bound, itctx.reborrow())).collect()
} }
fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<hir::Block> { fn lower_block(&mut self, b: &Block, targeted_by_break: bool) -> P<hir::Block<'hir>> {
let mut stmts = vec![]; let mut stmts = vec![];
let mut expr = None; let mut expr = None;
@ -2614,12 +2614,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// Lowers a block directly to an expression, presuming that it /// Lowers a block directly to an expression, presuming that it
/// has no attributes and is not targeted by a `break`. /// has no attributes and is not targeted by a `break`.
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr { fn lower_block_expr(&mut self, b: &Block) -> hir::Expr<'hir> {
let block = self.lower_block(b, false); let block = self.lower_block(b, false);
self.expr_block(block, AttrVec::new()) self.expr_block(block, AttrVec::new())
} }
fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> { fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat<'hir>> {
let node = match p.kind { let node = match p.kind {
PatKind::Wild => hir::PatKind::Wild, PatKind::Wild => hir::PatKind::Wild,
PatKind::Ident(ref binding_mode, ident, ref sub) => { PatKind::Ident(ref binding_mode, ident, ref sub) => {
@ -2700,7 +2700,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self, &mut self,
pats: &[AstP<Pat>], pats: &[AstP<Pat>],
ctx: &str, ctx: &str,
) -> (HirVec<P<hir::Pat>>, Option<usize>) { ) -> (HirVec<P<hir::Pat<'hir>>>, Option<usize>) {
let mut elems = Vec::with_capacity(pats.len()); let mut elems = Vec::with_capacity(pats.len());
let mut rest = None; let mut rest = None;
@ -2737,7 +2737,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// When encountering `($binding_mode $ident @)? ..` (`slice`), /// When encountering `($binding_mode $ident @)? ..` (`slice`),
/// this is interpreted as a sub-slice pattern semantically. /// this is interpreted as a sub-slice pattern semantically.
/// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`. /// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`.
fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind { fn lower_pat_slice(&mut self, pats: &[AstP<Pat>]) -> hir::PatKind<'hir> {
let mut before = Vec::new(); let mut before = Vec::new();
let mut after = Vec::new(); let mut after = Vec::new();
let mut slice = None; let mut slice = None;
@ -2796,8 +2796,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
p: &Pat, p: &Pat,
binding_mode: &BindingMode, binding_mode: &BindingMode,
ident: Ident, ident: Ident,
lower_sub: impl FnOnce(&mut Self) -> Option<P<hir::Pat>>, lower_sub: impl FnOnce(&mut Self) -> Option<P<hir::Pat<'hir>>>,
) -> hir::PatKind { ) -> hir::PatKind<'hir> {
match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) { match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) {
// `None` can occur in body-less function signatures // `None` can occur in body-less function signatures
res @ None | res @ Some(Res::Local(_)) => { res @ None | res @ Some(Res::Local(_)) => {
@ -2824,12 +2824,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
} }
fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> P<hir::Pat> { fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> P<hir::Pat<'hir>> {
self.pat_with_node_id_of(p, hir::PatKind::Wild) self.pat_with_node_id_of(p, hir::PatKind::Wild)
} }
/// Construct a `Pat` with the `HirId` of `p.id` lowered. /// Construct a `Pat` with the `HirId` of `p.id` lowered.
fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind) -> P<hir::Pat> { fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> P<hir::Pat<'hir>> {
P(hir::Pat { hir_id: self.lower_node_id(p.id), kind, span: p.span }) P(hir::Pat { hir_id: self.lower_node_id(p.id), kind, span: p.span })
} }
@ -2843,7 +2843,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
/// Used to ban the `..` pattern in places it shouldn't be semantically. /// Used to ban the `..` pattern in places it shouldn't be semantically.
fn ban_illegal_rest_pat(&self, sp: Span) -> hir::PatKind { fn ban_illegal_rest_pat(&self, sp: Span) -> hir::PatKind<'hir> {
self.diagnostic() self.diagnostic()
.struct_span_err(sp, "`..` patterns are not allowed here") .struct_span_err(sp, "`..` patterns are not allowed here")
.note("only allowed in tuple, tuple struct, and slice patterns") .note("only allowed in tuple, tuple struct, and slice patterns")
@ -2869,11 +2869,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}) })
} }
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> { fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
let kind = match s.kind { let kind = match s.kind {
StmtKind::Local(ref l) => { StmtKind::Local(ref l) => {
let (l, item_ids) = self.lower_local(l); let (l, item_ids) = self.lower_local(l);
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
.into_iter() .into_iter()
.map(|item_id| { .map(|item_id| {
let item_id = hir::ItemId { id: self.lower_node_id(item_id) }; let item_id = hir::ItemId { id: self.lower_node_id(item_id) };
@ -2944,11 +2944,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Helper methods for building HIR. // Helper methods for building HIR.
fn stmt(&mut self, span: Span, kind: hir::StmtKind) -> hir::Stmt { fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
hir::Stmt { span, kind, hir_id: self.next_id() } hir::Stmt { span, kind, hir_id: self.next_id() }
} }
fn stmt_expr(&mut self, span: Span, expr: hir::Expr) -> hir::Stmt { fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
self.stmt(span, hir::StmtKind::Expr(P(expr))) self.stmt(span, hir::StmtKind::Expr(P(expr)))
} }
@ -2956,24 +2956,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self, &mut self,
attrs: AttrVec, attrs: AttrVec,
span: Span, span: Span,
init: Option<P<hir::Expr>>, init: Option<P<hir::Expr<'hir>>>,
pat: P<hir::Pat>, pat: P<hir::Pat<'hir>>,
source: hir::LocalSource, source: hir::LocalSource,
) -> hir::Stmt { ) -> hir::Stmt<'hir> {
let local = hir::Local { attrs, hir_id: self.next_id(), init, pat, source, span, ty: None }; let local = hir::Local { attrs, hir_id: self.next_id(), init, pat, source, span, ty: None };
self.stmt(span, hir::StmtKind::Local(P(local))) self.stmt(span, hir::StmtKind::Local(P(local)))
} }
fn block_expr(&mut self, expr: P<hir::Expr>) -> hir::Block { fn block_expr(&mut self, expr: P<hir::Expr<'hir>>) -> hir::Block<'hir> {
self.block_all(expr.span, hir::HirVec::new(), Some(expr)) self.block_all(expr.span, hir::HirVec::new(), Some(expr))
} }
fn block_all( fn block_all(
&mut self, &mut self,
span: Span, span: Span,
stmts: hir::HirVec<hir::Stmt>, stmts: hir::HirVec<hir::Stmt<'hir>>,
expr: Option<P<hir::Expr>>, expr: Option<P<hir::Expr<'hir>>>,
) -> hir::Block { ) -> hir::Block<'hir> {
hir::Block { hir::Block {
stmts, stmts,
expr, expr,
@ -2985,24 +2985,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
/// Constructs a `true` or `false` literal pattern. /// Constructs a `true` or `false` literal pattern.
fn pat_bool(&mut self, span: Span, val: bool) -> P<hir::Pat> { fn pat_bool(&mut self, span: Span, val: bool) -> P<hir::Pat<'hir>> {
let expr = self.expr_bool(span, val); let expr = self.expr_bool(span, val);
self.pat(span, hir::PatKind::Lit(P(expr))) self.pat(span, hir::PatKind::Lit(P(expr)))
} }
fn pat_ok(&mut self, span: Span, pat: P<hir::Pat>) -> P<hir::Pat> { fn pat_ok(&mut self, span: Span, pat: P<hir::Pat<'hir>>) -> P<hir::Pat<'hir>> {
self.pat_std_enum(span, &[sym::result, sym::Result, sym::Ok], hir_vec![pat]) self.pat_std_enum(span, &[sym::result, sym::Result, sym::Ok], hir_vec![pat])
} }
fn pat_err(&mut self, span: Span, pat: P<hir::Pat>) -> P<hir::Pat> { fn pat_err(&mut self, span: Span, pat: P<hir::Pat<'hir>>) -> P<hir::Pat<'hir>> {
self.pat_std_enum(span, &[sym::result, sym::Result, sym::Err], hir_vec![pat]) self.pat_std_enum(span, &[sym::result, sym::Result, sym::Err], hir_vec![pat])
} }
fn pat_some(&mut self, span: Span, pat: P<hir::Pat>) -> P<hir::Pat> { fn pat_some(&mut self, span: Span, pat: P<hir::Pat<'hir>>) -> P<hir::Pat<'hir>> {
self.pat_std_enum(span, &[sym::option, sym::Option, sym::Some], hir_vec![pat]) self.pat_std_enum(span, &[sym::option, sym::Option, sym::Some], hir_vec![pat])
} }
fn pat_none(&mut self, span: Span) -> P<hir::Pat> { fn pat_none(&mut self, span: Span) -> P<hir::Pat<'hir>> {
self.pat_std_enum(span, &[sym::option, sym::Option, sym::None], hir_vec![]) self.pat_std_enum(span, &[sym::option, sym::Option, sym::None], hir_vec![])
} }
@ -3010,8 +3010,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&mut self, &mut self,
span: Span, span: Span,
components: &[Symbol], components: &[Symbol],
subpats: hir::HirVec<P<hir::Pat>>, subpats: hir::HirVec<P<hir::Pat<'hir>>>,
) -> P<hir::Pat> { ) -> P<hir::Pat<'hir>> {
let path = self.std_path(span, components, None, true); let path = self.std_path(span, components, None, true);
let qpath = hir::QPath::Resolved(None, P(path)); let qpath = hir::QPath::Resolved(None, P(path));
let pt = if subpats.is_empty() { let pt = if subpats.is_empty() {
@ -3022,7 +3022,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.pat(span, pt) self.pat(span, pt)
} }
fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat>, hir::HirId) { fn pat_ident(&mut self, span: Span, ident: Ident) -> (P<hir::Pat<'hir>>, hir::HirId) {
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated) self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
} }
@ -3031,7 +3031,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span, span: Span,
ident: Ident, ident: Ident,
bm: hir::BindingAnnotation, bm: hir::BindingAnnotation,
) -> (P<hir::Pat>, hir::HirId) { ) -> (P<hir::Pat<'hir>>, hir::HirId) {
let hir_id = self.next_id(); let hir_id = self.next_id();
( (
@ -3044,11 +3044,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) )
} }
fn pat_wild(&mut self, span: Span) -> P<hir::Pat> { fn pat_wild(&mut self, span: Span) -> P<hir::Pat<'hir>> {
self.pat(span, hir::PatKind::Wild) self.pat(span, hir::PatKind::Wild)
} }
fn pat(&mut self, span: Span, kind: hir::PatKind) -> P<hir::Pat> { fn pat(&mut self, span: Span, kind: hir::PatKind<'hir>) -> P<hir::Pat<'hir>> {
P(hir::Pat { hir_id: self.next_id(), kind, span }) P(hir::Pat { hir_id: self.next_id(), kind, span })
} }

View File

@ -13,12 +13,12 @@ use syntax::symbol::{sym, Symbol};
use rustc_error_codes::*; use rustc_error_codes::*;
impl LoweringContext<'_, '_> { impl<'hir> LoweringContext<'_, 'hir> {
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> { fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr<'hir>> {
exprs.iter().map(|x| self.lower_expr(x)).collect() exprs.iter().map(|x| self.lower_expr(x)).collect()
} }
pub(super) fn lower_expr(&mut self, e: &Expr) -> hir::Expr { pub(super) fn lower_expr(&mut self, e: &Expr) -> hir::Expr<'hir> {
let kind = match e.kind { let kind = match e.kind {
ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))), ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))),
ExprKind::Array(ref exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)), ExprKind::Array(ref exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
@ -237,7 +237,7 @@ impl LoweringContext<'_, '_> {
/// ```rust /// ```rust
/// match scrutinee { pats => true, _ => false } /// match scrutinee { pats => true, _ => false }
/// ``` /// ```
fn lower_expr_let(&mut self, span: Span, pat: &Pat, scrutinee: &Expr) -> hir::ExprKind { fn lower_expr_let(&mut self, span: Span, pat: &Pat, scrutinee: &Expr) -> hir::ExprKind<'hir> {
// If we got here, the `let` expression is not allowed. // If we got here, the `let` expression is not allowed.
if self.sess.opts.unstable_features.is_nightly_build() { if self.sess.opts.unstable_features.is_nightly_build() {
@ -286,7 +286,7 @@ impl LoweringContext<'_, '_> {
cond: &Expr, cond: &Expr,
then: &Block, then: &Block,
else_opt: Option<&Expr>, else_opt: Option<&Expr>,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
// FIXME(#53667): handle lowering of && and parens. // FIXME(#53667): handle lowering of && and parens.
// `_ => else_block` where `else_block` is `{}` if there's `None`: // `_ => else_block` where `else_block` is `{}` if there's `None`:
@ -331,7 +331,7 @@ impl LoweringContext<'_, '_> {
cond: &Expr, cond: &Expr,
body: &Block, body: &Block,
opt_label: Option<Label>, opt_label: Option<Label>,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
// FIXME(#53667): handle lowering of && and parens. // FIXME(#53667): handle lowering of && and parens.
// Note that the block AND the condition are evaluated in the loop scope. // Note that the block AND the condition are evaluated in the loop scope.
@ -398,7 +398,7 @@ impl LoweringContext<'_, '_> {
/// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok(<expr>) }`, /// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok(<expr>) }`,
/// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_ok(()) }` /// `try { <stmts>; }` into `{ <stmts>; ::std::ops::Try::from_ok(()) }`
/// and save the block id to use it as a break target for desugaring of the `?` operator. /// and save the block id to use it as a break target for desugaring of the `?` operator.
fn lower_expr_try_block(&mut self, body: &Block) -> hir::ExprKind { fn lower_expr_try_block(&mut self, body: &Block) -> hir::ExprKind<'hir> {
self.with_catch_scope(body.id, |this| { self.with_catch_scope(body.id, |this| {
let mut block = this.lower_block(body, true).into_inner(); let mut block = this.lower_block(body, true).into_inner();
@ -411,7 +411,7 @@ impl LoweringContext<'_, '_> {
// Final expression of the block (if present) or `()` with span at the end of block // Final expression of the block (if present) or `()` with span at the end of block
let tail_expr = block.expr.take().map_or_else( let tail_expr = block.expr.take().map_or_else(
|| this.expr_unit(this.sess.source_map().end_point(try_span)), || this.expr_unit(this.sess.source_map().end_point(try_span)),
|x: P<hir::Expr>| x.into_inner(), |x: P<hir::Expr<'hir>>| x.into_inner(),
); );
let ok_wrapped_span = let ok_wrapped_span =
@ -433,15 +433,15 @@ impl LoweringContext<'_, '_> {
&mut self, &mut self,
method: Symbol, method: Symbol,
method_span: Span, method_span: Span,
expr: hir::Expr, expr: hir::Expr<'hir>,
overall_span: Span, overall_span: Span,
) -> P<hir::Expr> { ) -> P<hir::Expr<'hir>> {
let path = &[sym::ops, sym::Try, method]; let path = &[sym::ops, sym::Try, method];
let constructor = P(self.expr_std_path(method_span, path, None, ThinVec::new())); let constructor = P(self.expr_std_path(method_span, path, None, ThinVec::new()));
P(self.expr_call(overall_span, constructor, hir_vec![expr])) P(self.expr_call(overall_span, constructor, hir_vec![expr]))
} }
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm { fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
hir::Arm { hir::Arm {
hir_id: self.next_id(), hir_id: self.next_id(),
attrs: self.lower_attrs(&arm.attrs), attrs: self.lower_attrs(&arm.attrs),
@ -462,8 +462,8 @@ impl LoweringContext<'_, '_> {
ret_ty: Option<AstP<Ty>>, ret_ty: Option<AstP<Ty>>,
span: Span, span: Span,
async_gen_kind: hir::AsyncGeneratorKind, async_gen_kind: hir::AsyncGeneratorKind,
body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr, body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
let output = match ret_ty { let output = match ret_ty {
Some(ty) => FunctionRetTy::Ty(ty), Some(ty) => FunctionRetTy::Ty(ty),
None => FunctionRetTy::Default(span), None => FunctionRetTy::Default(span),
@ -518,7 +518,7 @@ impl LoweringContext<'_, '_> {
/// } /// }
/// } /// }
/// ``` /// ```
fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind { fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
match self.generator_kind { match self.generator_kind {
Some(hir::GeneratorKind::Async(_)) => {} Some(hir::GeneratorKind::Async(_)) => {}
Some(hir::GeneratorKind::Gen) | None => { Some(hir::GeneratorKind::Gen) | None => {
@ -641,7 +641,7 @@ impl LoweringContext<'_, '_> {
decl: &FnDecl, decl: &FnDecl,
body: &Expr, body: &Expr,
fn_decl_span: Span, fn_decl_span: Span,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
// Lower outside new scope to preserve `is_in_loop_condition`. // Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = self.lower_fn_decl(decl, None, false, None); let fn_decl = self.lower_fn_decl(decl, None, false, None);
@ -699,7 +699,7 @@ impl LoweringContext<'_, '_> {
decl: &FnDecl, decl: &FnDecl,
body: &Expr, body: &Expr,
fn_decl_span: Span, fn_decl_span: Span,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
let outer_decl = let outer_decl =
FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span) }; FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span) };
// We need to lower the declaration outside the new scope, because we // We need to lower the declaration outside the new scope, because we
@ -743,7 +743,7 @@ impl LoweringContext<'_, '_> {
} }
/// Desugar `<start>..=<end>` into `std::ops::RangeInclusive::new(<start>, <end>)`. /// Desugar `<start>..=<end>` into `std::ops::RangeInclusive::new(<start>, <end>)`.
fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind { fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> {
let id = self.next_id(); let id = self.next_id();
let e1 = self.lower_expr(e1); let e1 = self.lower_expr(e1);
let e2 = self.lower_expr(e2); let e2 = self.lower_expr(e2);
@ -762,7 +762,7 @@ impl LoweringContext<'_, '_> {
e1: Option<&Expr>, e1: Option<&Expr>,
e2: Option<&Expr>, e2: Option<&Expr>,
lims: RangeLimits, lims: RangeLimits,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
use syntax::ast::RangeLimits::*; use syntax::ast::RangeLimits::*;
let path = match (e1, e2, lims) { let path = match (e1, e2, lims) {
@ -786,7 +786,7 @@ impl LoweringContext<'_, '_> {
let ident = Ident::new(Symbol::intern(s), e.span); let ident = Ident::new(Symbol::intern(s), e.span);
self.field(ident, expr, e.span) self.field(ident, expr, e.span)
}) })
.collect::<P<[hir::Field]>>(); .collect::<P<[hir::Field<'hir>]>>();
let is_unit = fields.is_empty(); let is_unit = fields.is_empty();
let struct_path = [sym::ops, path]; let struct_path = [sym::ops, path];
@ -893,7 +893,7 @@ impl LoweringContext<'_, '_> {
result result
} }
fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind { fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind<'hir> {
let inner = hir::InlineAsmInner { let inner = hir::InlineAsmInner {
inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(), inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
outputs: asm outputs: asm
@ -921,7 +921,7 @@ impl LoweringContext<'_, '_> {
hir::ExprKind::InlineAsm(P(hir_asm)) hir::ExprKind::InlineAsm(P(hir_asm))
} }
fn lower_field(&mut self, f: &Field) -> hir::Field { fn lower_field(&mut self, f: &Field) -> hir::Field<'hir> {
hir::Field { hir::Field {
hir_id: self.next_id(), hir_id: self.next_id(),
ident: f.ident, ident: f.ident,
@ -931,7 +931,7 @@ impl LoweringContext<'_, '_> {
} }
} }
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind { fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
match self.generator_kind { match self.generator_kind {
Some(hir::GeneratorKind::Gen) => {} Some(hir::GeneratorKind::Gen) => {}
Some(hir::GeneratorKind::Async(_)) => { Some(hir::GeneratorKind::Async(_)) => {
@ -973,7 +973,7 @@ impl LoweringContext<'_, '_> {
head: &Expr, head: &Expr,
body: &Block, body: &Block,
opt_label: Option<Label>, opt_label: Option<Label>,
) -> hir::Expr { ) -> hir::Expr<'hir> {
// expand <head> // expand <head>
let mut head = self.lower_expr(head); let mut head = self.lower_expr(head);
let desugared_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None); let desugared_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
@ -1102,7 +1102,7 @@ impl LoweringContext<'_, '_> {
/// return Try::from_error(From::from(err)), /// return Try::from_error(From::from(err)),
/// } /// }
/// ``` /// ```
fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind { fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind<'hir> {
let unstable_span = self.mark_span_with_reason( let unstable_span = self.mark_span_with_reason(
DesugaringKind::QuestionMark, DesugaringKind::QuestionMark,
span, span,
@ -1191,7 +1191,7 @@ impl LoweringContext<'_, '_> {
// ========================================================================= // =========================================================================
/// Constructs a `true` or `false` literal expression. /// Constructs a `true` or `false` literal expression.
pub(super) fn expr_bool(&mut self, span: Span, val: bool) -> hir::Expr { pub(super) fn expr_bool(&mut self, span: Span, val: bool) -> hir::Expr<'hir> {
let lit = Spanned { span, node: LitKind::Bool(val) }; let lit = Spanned { span, node: LitKind::Bool(val) };
self.expr(span, hir::ExprKind::Lit(lit), ThinVec::new()) self.expr(span, hir::ExprKind::Lit(lit), ThinVec::new())
} }
@ -1205,28 +1205,28 @@ impl LoweringContext<'_, '_> {
pub(super) fn expr_drop_temps( pub(super) fn expr_drop_temps(
&mut self, &mut self,
span: Span, span: Span,
expr: P<hir::Expr>, expr: P<hir::Expr<'hir>>,
attrs: AttrVec, attrs: AttrVec,
) -> hir::Expr { ) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::DropTemps(expr), attrs) self.expr(span, hir::ExprKind::DropTemps(expr), attrs)
} }
fn expr_match( fn expr_match(
&mut self, &mut self,
span: Span, span: Span,
arg: P<hir::Expr>, arg: P<hir::Expr<'hir>>,
arms: hir::HirVec<hir::Arm>, arms: hir::HirVec<hir::Arm<'hir>>,
source: hir::MatchSource, source: hir::MatchSource,
) -> hir::Expr { ) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::Match(arg, arms, source), ThinVec::new()) self.expr(span, hir::ExprKind::Match(arg, arms, source), ThinVec::new())
} }
fn expr_break(&mut self, span: Span, attrs: AttrVec) -> P<hir::Expr> { fn expr_break(&mut self, span: Span, attrs: AttrVec) -> P<hir::Expr<'hir>> {
let expr_break = hir::ExprKind::Break(self.lower_loop_destination(None), None); let expr_break = hir::ExprKind::Break(self.lower_loop_destination(None), None);
P(self.expr(span, expr_break, attrs)) P(self.expr(span, expr_break, attrs))
} }
fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr>) -> hir::Expr { fn expr_mut_addr_of(&mut self, span: Span, e: P<hir::Expr<'_>>) -> hir::Expr<'_> {
self.expr( self.expr(
span, span,
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e), hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
@ -1234,20 +1234,20 @@ impl LoweringContext<'_, '_> {
) )
} }
fn expr_unit(&mut self, sp: Span) -> hir::Expr { fn expr_unit(&mut self, sp: Span) -> hir::Expr<'hir> {
self.expr_tuple(sp, hir_vec![]) self.expr_tuple(sp, hir_vec![])
} }
fn expr_tuple(&mut self, sp: Span, exprs: hir::HirVec<hir::Expr>) -> hir::Expr { fn expr_tuple(&mut self, sp: Span, exprs: hir::HirVec<hir::Expr<'hir>>) -> hir::Expr<'hir> {
self.expr(sp, hir::ExprKind::Tup(exprs), ThinVec::new()) self.expr(sp, hir::ExprKind::Tup(exprs), ThinVec::new())
} }
fn expr_call( fn expr_call(
&mut self, &mut self,
span: Span, span: Span,
e: P<hir::Expr>, e: P<hir::Expr<'hir>>,
args: hir::HirVec<hir::Expr>, args: hir::HirVec<hir::Expr<'hir>>,
) -> hir::Expr { ) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new()) self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new())
} }
@ -1256,8 +1256,8 @@ impl LoweringContext<'_, '_> {
&mut self, &mut self,
span: Span, span: Span,
path_components: &[Symbol], path_components: &[Symbol],
args: hir::HirVec<hir::Expr>, args: hir::HirVec<hir::Expr<'hir>>,
) -> hir::Expr { ) -> hir::Expr<'hir> {
let path = P(self.expr_std_path(span, path_components, None, ThinVec::new())); let path = P(self.expr_std_path(span, path_components, None, ThinVec::new()));
self.expr_call(span, path, args) self.expr_call(span, path, args)
} }
@ -1277,8 +1277,8 @@ impl LoweringContext<'_, '_> {
span: Span, span: Span,
ty_path_components: &[Symbol], ty_path_components: &[Symbol],
assoc_fn_name: &str, assoc_fn_name: &str,
args: hir::HirVec<hir::Expr>, args: hir::HirVec<hir::Expr<'hir>>,
) -> hir::ExprKind { ) -> hir::ExprKind<'hir> {
let ty_path = P(self.std_path(span, ty_path_components, None, false)); let ty_path = P(self.std_path(span, ty_path_components, None, false));
let ty = P(self.ty_path(ty_path_id, span, hir::QPath::Resolved(None, ty_path))); let ty = P(self.ty_path(ty_path_id, span, hir::QPath::Resolved(None, ty_path)));
let fn_seg = P(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name))); let fn_seg = P(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name)));
@ -1293,12 +1293,17 @@ impl LoweringContext<'_, '_> {
components: &[Symbol], components: &[Symbol],
params: Option<P<hir::GenericArgs>>, params: Option<P<hir::GenericArgs>>,
attrs: AttrVec, attrs: AttrVec,
) -> hir::Expr { ) -> hir::Expr<'hir> {
let path = self.std_path(span, components, params, true); let path = self.std_path(span, components, params, true);
self.expr(span, hir::ExprKind::Path(hir::QPath::Resolved(None, P(path))), attrs) self.expr(span, hir::ExprKind::Path(hir::QPath::Resolved(None, P(path))), attrs)
} }
pub(super) fn expr_ident(&mut self, sp: Span, ident: Ident, binding: hir::HirId) -> hir::Expr { pub(super) fn expr_ident(
&mut self,
sp: Span,
ident: Ident,
binding: hir::HirId,
) -> hir::Expr<'hir> {
self.expr_ident_with_attrs(sp, ident, binding, ThinVec::new()) self.expr_ident_with_attrs(sp, ident, binding, ThinVec::new())
} }
@ -1308,7 +1313,7 @@ impl LoweringContext<'_, '_> {
ident: Ident, ident: Ident,
binding: hir::HirId, binding: hir::HirId,
attrs: AttrVec, attrs: AttrVec,
) -> hir::Expr { ) -> hir::Expr<'hir> {
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved( let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
None, None,
P(hir::Path { P(hir::Path {
@ -1321,7 +1326,7 @@ impl LoweringContext<'_, '_> {
self.expr(span, expr_path, attrs) self.expr(span, expr_path, attrs)
} }
fn expr_unsafe(&mut self, expr: P<hir::Expr>) -> hir::Expr { fn expr_unsafe(&mut self, expr: P<hir::Expr<'hir>>) -> hir::Expr<'hir> {
let hir_id = self.next_id(); let hir_id = self.next_id();
let span = expr.span; let span = expr.span;
self.expr( self.expr(
@ -1341,24 +1346,29 @@ impl LoweringContext<'_, '_> {
) )
} }
fn expr_block_empty(&mut self, span: Span) -> hir::Expr { fn expr_block_empty(&mut self, span: Span) -> hir::Expr<'hir> {
let blk = self.block_all(span, hir_vec![], None); let blk = self.block_all(span, hir_vec![], None);
self.expr_block(P(blk), ThinVec::new()) self.expr_block(P(blk), ThinVec::new())
} }
pub(super) fn expr_block(&mut self, b: P<hir::Block>, attrs: AttrVec) -> hir::Expr { pub(super) fn expr_block(&mut self, b: P<hir::Block<'hir>>, attrs: AttrVec) -> hir::Expr<'hir> {
self.expr(b.span, hir::ExprKind::Block(b, None), attrs) self.expr(b.span, hir::ExprKind::Block(b, None), attrs)
} }
pub(super) fn expr(&mut self, span: Span, kind: hir::ExprKind, attrs: AttrVec) -> hir::Expr { pub(super) fn expr(
&mut self,
span: Span,
kind: hir::ExprKind<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
hir::Expr { hir_id: self.next_id(), kind, span, attrs } hir::Expr { hir_id: self.next_id(), kind, span, attrs }
} }
fn field(&mut self, ident: Ident, expr: P<hir::Expr>, span: Span) -> hir::Field { fn field(&mut self, ident: Ident, expr: P<hir::Expr<'hir>>, span: Span) -> hir::Field<'hir> {
hir::Field { hir_id: self.next_id(), ident, span, expr, is_shorthand: false } hir::Field { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
} }
fn arm(&mut self, pat: P<hir::Pat>, expr: P<hir::Expr>) -> hir::Arm { fn arm(&mut self, pat: P<hir::Pat<'hir>>, expr: P<hir::Expr<'hir>>) -> hir::Arm<'hir> {
hir::Arm { hir::Arm {
hir_id: self.next_id(), hir_id: self.next_id(),
attrs: hir_vec![], attrs: hir_vec![],

View File

@ -840,7 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
/// Construct `ExprKind::Err` for the given `span`. /// Construct `ExprKind::Err` for the given `span`.
fn expr_err(&mut self, span: Span) -> hir::Expr { fn expr_err(&mut self, span: Span) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::Err, AttrVec::new()) self.expr(span, hir::ExprKind::Err, AttrVec::new())
} }
@ -981,7 +981,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
} }
fn record_body(&mut self, params: &'hir [hir::Param], value: hir::Expr) -> hir::BodyId { fn record_body(
&mut self,
params: &'hir [hir::Param<'hir>],
value: hir::Expr<'hir>,
) -> hir::BodyId {
let body = hir::Body { generator_kind: self.generator_kind, params, value }; let body = hir::Body { generator_kind: self.generator_kind, params, value };
let id = body.id(); let id = body.id();
self.bodies.insert(id, body); self.bodies.insert(id, body);
@ -990,7 +994,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_body( fn lower_body(
&mut self, &mut self,
f: impl FnOnce(&mut Self) -> (&'hir [hir::Param], hir::Expr), f: impl FnOnce(&mut Self) -> (&'hir [hir::Param<'hir>], hir::Expr<'hir>),
) -> hir::BodyId { ) -> hir::BodyId {
let prev_gen_kind = self.generator_kind.take(); let prev_gen_kind = self.generator_kind.take();
let (parameters, result) = f(self); let (parameters, result) = f(self);
@ -999,7 +1003,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
body_id body_id
} }
fn lower_param(&mut self, param: &Param) -> hir::Param { fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
hir::Param { hir::Param {
attrs: self.lower_attrs(&param.attrs), attrs: self.lower_attrs(&param.attrs),
hir_id: self.lower_node_id(param.id), hir_id: self.lower_node_id(param.id),
@ -1011,7 +1015,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_fn_body( pub(super) fn lower_fn_body(
&mut self, &mut self,
decl: &FnDecl, decl: &FnDecl,
body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr, body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
) -> hir::BodyId { ) -> hir::BodyId {
self.lower_body(|this| { self.lower_body(|this| {
( (
@ -1030,7 +1034,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_fn_body(decl, |this| this.lower_block_expr_opt(span, body)) self.lower_fn_body(decl, |this| this.lower_block_expr_opt(span, body))
} }
fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr { fn lower_block_expr_opt(&mut self, span: Span, block: Option<&Block>) -> hir::Expr<'hir> {
match block { match block {
Some(block) => self.lower_block_expr(block), Some(block) => self.lower_block_expr(block),
None => self.expr_err(span), None => self.expr_err(span),
@ -1062,8 +1066,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}; };
self.lower_body(|this| { self.lower_body(|this| {
let mut parameters: Vec<hir::Param> = Vec::new(); let mut parameters: Vec<hir::Param<'hir>> = Vec::new();
let mut statements: Vec<hir::Stmt> = Vec::new(); let mut statements: Vec<hir::Stmt<'hir>> = Vec::new();
// Async function parameters are lowered into the closure body so that they are // Async function parameters are lowered into the closure body so that they are
// captured and so that the drop order matches the equivalent non-async functions. // captured and so that the drop order matches the equivalent non-async functions.

View File

@ -66,7 +66,7 @@ impl MaybeFnLike for ast::TraitItem<'_> {
} }
} }
impl MaybeFnLike for ast::Expr { impl MaybeFnLike for ast::Expr<'_> {
fn is_fn_like(&self) -> bool { fn is_fn_like(&self) -> bool {
match self.kind { match self.kind {
ast::ExprKind::Closure(..) => true, ast::ExprKind::Closure(..) => true,
@ -81,7 +81,7 @@ impl MaybeFnLike for ast::Expr {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum Code<'a> { pub enum Code<'a> {
FnLike(FnLikeNode<'a>), FnLike(FnLikeNode<'a>),
Expr(&'a Expr), Expr(&'a Expr<'a>),
} }
impl<'a> Code<'a> { impl<'a> Code<'a> {

View File

@ -365,7 +365,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
self.currently_in_body = prev_in_body; self.currently_in_body = prev_in_body;
} }
fn visit_param(&mut self, param: &'hir Param) { fn visit_param(&mut self, param: &'hir Param<'hir>) {
let node = Node::Param(param); let node = Node::Param(param);
self.insert(param.pat.span, param.hir_id, node); self.insert(param.pat.span, param.hir_id, node);
self.with_parent(param.hir_id, |this| { self.with_parent(param.hir_id, |this| {
@ -434,7 +434,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}); });
} }
fn visit_pat(&mut self, pat: &'hir Pat) { fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
let node = let node =
if let PatKind::Binding(..) = pat.kind { Node::Binding(pat) } else { Node::Pat(pat) }; if let PatKind::Binding(..) = pat.kind { Node::Binding(pat) } else { Node::Pat(pat) };
self.insert(pat.span, pat.hir_id, node); self.insert(pat.span, pat.hir_id, node);
@ -444,7 +444,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}); });
} }
fn visit_arm(&mut self, arm: &'hir Arm) { fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
let node = Node::Arm(arm); let node = Node::Arm(arm);
self.insert(arm.span, arm.hir_id, node); self.insert(arm.span, arm.hir_id, node);
@ -462,7 +462,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}); });
} }
fn visit_expr(&mut self, expr: &'hir Expr) { fn visit_expr(&mut self, expr: &'hir Expr<'hir>) {
self.insert(expr.span, expr.hir_id, Node::Expr(expr)); self.insert(expr.span, expr.hir_id, Node::Expr(expr));
self.with_parent(expr.hir_id, |this| { self.with_parent(expr.hir_id, |this| {
@ -470,7 +470,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
}); });
} }
fn visit_stmt(&mut self, stmt: &'hir Stmt) { fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt)); self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
self.with_parent(stmt.hir_id, |this| { self.with_parent(stmt.hir_id, |this| {
@ -513,14 +513,14 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
intravisit::walk_fn(self, fk, fd, b, s, id); intravisit::walk_fn(self, fk, fd, b, s, id);
} }
fn visit_block(&mut self, block: &'hir Block) { fn visit_block(&mut self, block: &'hir Block<'hir>) {
self.insert(block.span, block.hir_id, Node::Block(block)); self.insert(block.span, block.hir_id, Node::Block(block));
self.with_parent(block.hir_id, |this| { self.with_parent(block.hir_id, |this| {
intravisit::walk_block(this, block); intravisit::walk_block(this, block);
}); });
} }
fn visit_local(&mut self, l: &'hir Local) { fn visit_local(&mut self, l: &'hir Local<'hir>) {
self.insert(l.span, l.hir_id, Node::Local(l)); self.insert(l.span, l.hir_id, Node::Local(l));
self.with_parent(l.hir_id, |this| intravisit::walk_local(this, l)) self.with_parent(l.hir_id, |this| intravisit::walk_local(this, l))
} }

View File

@ -782,7 +782,7 @@ impl<'hir> Map<'hir> {
/// ///
/// Used by error reporting when there's a type error in a match arm caused by the `match` /// Used by error reporting when there's a type error in a match arm caused by the `match`
/// expression needing to be unit. /// expression needing to be unit.
pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&Expr> { pub fn get_match_if_cause(&self, hir_id: HirId) -> Option<&Expr<'hir>> {
for (_, node) in ParentHirIterator::new(hir_id, &self) { for (_, node) in ParentHirIterator::new(hir_id, &self) {
match node { match node {
Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => { Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => {
@ -925,7 +925,7 @@ impl<'hir> Map<'hir> {
} }
} }
pub fn expect_expr(&self, id: HirId) -> &'hir Expr { pub fn expect_expr(&self, id: HirId) -> &'hir Expr<'hir> {
match self.find(id) { match self.find(id) {
// read recorded by find // read recorded by find
Some(Node::Expr(expr)) => expr, Some(Node::Expr(expr)) => expr,

View File

@ -832,12 +832,12 @@ pub struct MacroDef<'hir> {
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of /// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
/// the `rules` being anything but `DefaultBlock`. /// the `rules` being anything but `DefaultBlock`.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Block { pub struct Block<'hir> {
/// Statements in a block. /// Statements in a block.
pub stmts: HirVec<Stmt>, pub stmts: &'hir [Stmt<'hir>],
/// An expression at the end of the block /// An expression at the end of the block
/// without a semicolon, if any. /// without a semicolon, if any.
pub expr: Option<P<Expr>>, pub expr: Option<&'hir Expr<'hir>>,
#[stable_hasher(ignore)] #[stable_hasher(ignore)]
pub hir_id: HirId, pub hir_id: HirId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`. /// Distinguishes between `unsafe { ... }` and `{ ... }`.
@ -850,14 +850,14 @@ pub struct Block {
} }
#[derive(RustcEncodable, RustcDecodable, HashStable)] #[derive(RustcEncodable, RustcDecodable, HashStable)]
pub struct Pat { pub struct Pat<'hir> {
#[stable_hasher(ignore)] #[stable_hasher(ignore)]
pub hir_id: HirId, pub hir_id: HirId,
pub kind: PatKind, pub kind: PatKind<'hir>,
pub span: Span, pub span: Span,
} }
impl fmt::Debug for Pat { impl fmt::Debug for Pat<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
@ -868,9 +868,9 @@ impl fmt::Debug for Pat {
} }
} }
impl Pat { impl Pat<'_> {
// FIXME(#19596) this is a workaround, but there should be a better way // FIXME(#19596) this is a workaround, but there should be a better way
fn walk_short_(&self, it: &mut impl FnMut(&Pat) -> bool) -> bool { fn walk_short_(&self, it: &mut impl FnMut(&Pat<'_>) -> bool) -> bool {
if !it(self) { if !it(self) {
return false; return false;
} }
@ -893,12 +893,12 @@ impl Pat {
/// Note that when visiting e.g. `Tuple(ps)`, /// Note that when visiting e.g. `Tuple(ps)`,
/// if visiting `ps[0]` returns `false`, /// if visiting `ps[0]` returns `false`,
/// then `ps[1]` will not be visited. /// then `ps[1]` will not be visited.
pub fn walk_short(&self, mut it: impl FnMut(&Pat) -> bool) -> bool { pub fn walk_short(&self, mut it: impl FnMut(&Pat<'_>) -> bool) -> bool {
self.walk_short_(&mut it) self.walk_short_(&mut it)
} }
// FIXME(#19596) this is a workaround, but there should be a better way // FIXME(#19596) this is a workaround, but there should be a better way
fn walk_(&self, it: &mut impl FnMut(&Pat) -> bool) { fn walk_(&self, it: &mut impl FnMut(&Pat<'_>) -> bool) {
if !it(self) { if !it(self) {
return; return;
} }
@ -918,14 +918,14 @@ impl Pat {
/// Walk the pattern in left-to-right order. /// Walk the pattern in left-to-right order.
/// ///
/// If `it(pat)` returns `false`, the children are not visited. /// If `it(pat)` returns `false`, the children are not visited.
pub fn walk(&self, mut it: impl FnMut(&Pat) -> bool) { pub fn walk(&self, mut it: impl FnMut(&Pat<'_>) -> bool) {
self.walk_(&mut it) self.walk_(&mut it)
} }
/// Walk the pattern in left-to-right order. /// Walk the pattern in left-to-right order.
/// ///
/// If you always want to recurse, prefer this method over `walk`. /// If you always want to recurse, prefer this method over `walk`.
pub fn walk_always(&self, mut it: impl FnMut(&Pat)) { pub fn walk_always(&self, mut it: impl FnMut(&Pat<'_>)) {
self.walk(|p| { self.walk(|p| {
it(p); it(p);
true true
@ -939,14 +939,14 @@ impl Pat {
/// are treated the same as` x: x, y: ref y, z: ref mut z`, /// are treated the same as` x: x, y: ref y, z: ref mut z`,
/// except `is_shorthand` is true. /// except `is_shorthand` is true.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct FieldPat { pub struct FieldPat<'hir> {
#[stable_hasher(ignore)] #[stable_hasher(ignore)]
pub hir_id: HirId, pub hir_id: HirId,
/// The identifier for the field. /// The identifier for the field.
#[stable_hasher(project(name))] #[stable_hasher(project(name))]
pub ident: Ident, pub ident: Ident,
/// The pattern the field is destructured to. /// The pattern the field is destructured to.
pub pat: P<Pat>, pub pat: &'hir Pat<'hir>,
pub is_shorthand: bool, pub is_shorthand: bool,
pub span: Span, pub span: Span,
} }
@ -991,7 +991,7 @@ impl fmt::Display for RangeEnd {
} }
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum PatKind { pub enum PatKind<'hir> {
/// Represents a wildcard pattern (i.e., `_`). /// Represents a wildcard pattern (i.e., `_`).
Wild, Wild,
@ -999,20 +999,20 @@ pub enum PatKind {
/// The `HirId` is the canonical ID for the variable being bound, /// The `HirId` is the canonical ID for the variable being bound,
/// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID), /// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID),
/// which is the pattern ID of the first `x`. /// which is the pattern ID of the first `x`.
Binding(BindingAnnotation, HirId, Ident, Option<P<Pat>>), Binding(BindingAnnotation, HirId, Ident, Option<&'hir Pat<'hir>>),
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`. /// The `bool` is `true` in the presence of a `..`.
Struct(QPath, HirVec<FieldPat>, bool), Struct(QPath, &'hir [FieldPat<'hir>], bool),
/// A tuple struct/variant pattern `Variant(x, y, .., z)`. /// A tuple struct/variant pattern `Variant(x, y, .., z)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position. /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `0 <= position <= subpats.len()` /// `0 <= position <= subpats.len()`
TupleStruct(QPath, HirVec<P<Pat>>, Option<usize>), TupleStruct(QPath, &'hir [&'hir Pat<'hir>], Option<usize>),
/// An or-pattern `A | B | C`. /// An or-pattern `A | B | C`.
/// Invariant: `pats.len() >= 2`. /// Invariant: `pats.len() >= 2`.
Or(HirVec<P<Pat>>), Or(&'hir [&'hir Pat<'hir>]),
/// A path pattern for an unit struct/variant or a (maybe-associated) constant. /// A path pattern for an unit struct/variant or a (maybe-associated) constant.
Path(QPath), Path(QPath),
@ -1020,19 +1020,19 @@ pub enum PatKind {
/// A tuple pattern (e.g., `(a, b)`). /// A tuple pattern (e.g., `(a, b)`).
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position. /// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `0 <= position <= subpats.len()` /// `0 <= position <= subpats.len()`
Tuple(HirVec<P<Pat>>, Option<usize>), Tuple(&'hir [&'hir Pat<'hir>], Option<usize>),
/// A `box` pattern. /// A `box` pattern.
Box(P<Pat>), Box(&'hir Pat<'hir>),
/// A reference pattern (e.g., `&mut (a, b)`). /// A reference pattern (e.g., `&mut (a, b)`).
Ref(P<Pat>, Mutability), Ref(&'hir Pat<'hir>, Mutability),
/// A literal. /// A literal.
Lit(P<Expr>), Lit(&'hir Expr<'hir>),
/// A range pattern (e.g., `1..=2` or `1..2`). /// A range pattern (e.g., `1..=2` or `1..2`).
Range(P<Expr>, P<Expr>, RangeEnd), Range(&'hir Expr<'hir>, &'hir Expr<'hir>, RangeEnd),
/// A slice pattern, `[before_0, ..., before_n, (slice, after_0, ..., after_n)?]`. /// A slice pattern, `[before_0, ..., before_n, (slice, after_0, ..., after_n)?]`.
/// ///
@ -1043,7 +1043,7 @@ pub enum PatKind {
/// ``` /// ```
/// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)]) /// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)])
/// ``` /// ```
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>), Slice(&'hir [&'hir Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [&'hir Pat<'hir>]),
} }
#[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable)]
@ -1210,13 +1210,13 @@ impl UnOp {
/// A statement. /// A statement.
#[derive(RustcEncodable, RustcDecodable, HashStable)] #[derive(RustcEncodable, RustcDecodable, HashStable)]
pub struct Stmt { pub struct Stmt<'hir> {
pub hir_id: HirId, pub hir_id: HirId,
pub kind: StmtKind, pub kind: StmtKind<'hir>,
pub span: Span, pub span: Span,
} }
impl fmt::Debug for Stmt { impl fmt::Debug for Stmt<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
@ -1229,22 +1229,22 @@ impl fmt::Debug for Stmt {
/// The contents of a statement. /// The contents of a statement.
#[derive(RustcEncodable, RustcDecodable, HashStable)] #[derive(RustcEncodable, RustcDecodable, HashStable)]
pub enum StmtKind { pub enum StmtKind<'hir> {
/// A local (`let`) binding. /// A local (`let`) binding.
Local(P<Local>), Local(&'hir Local<'hir>),
/// An item binding. /// An item binding.
Item(ItemId), Item(ItemId),
/// An expression without a trailing semi-colon (must have unit type). /// An expression without a trailing semi-colon (must have unit type).
Expr(P<Expr>), Expr(&'hir Expr<'hir>),
/// An expression with a trailing semi-colon (may have any type). /// An expression with a trailing semi-colon (may have any type).
Semi(P<Expr>), Semi(&'hir Expr<'hir>),
} }
impl StmtKind { impl StmtKind<'hir> {
pub fn attrs(&self) -> &[Attribute] { pub fn attrs(&self) -> &'hir [Attribute] {
match *self { match *self {
StmtKind::Local(ref l) => &l.attrs, StmtKind::Local(ref l) => &l.attrs,
StmtKind::Item(_) => &[], StmtKind::Item(_) => &[],
@ -1255,12 +1255,12 @@ impl StmtKind {
/// Represents a `let` statement (i.e., `let <pat>:<ty> = <expr>;`). /// Represents a `let` statement (i.e., `let <pat>:<ty> = <expr>;`).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Local { pub struct Local<'hir> {
pub pat: P<Pat>, pub pat: &'hir Pat<'hir>,
/// Type annotation, if any (otherwise the type will be inferred). /// Type annotation, if any (otherwise the type will be inferred).
pub ty: Option<P<Ty>>, pub ty: Option<&'hir Ty>,
/// Initializer expression to set the value, if any. /// Initializer expression to set the value, if any.
pub init: Option<P<Expr>>, pub init: Option<&'hir Expr<'hir>>,
pub hir_id: HirId, pub hir_id: HirId,
pub span: Span, pub span: Span,
pub attrs: AttrVec, pub attrs: AttrVec,
@ -1272,30 +1272,30 @@ pub struct Local {
/// Represents a single arm of a `match` expression, e.g. /// Represents a single arm of a `match` expression, e.g.
/// `<pat> (if <guard>) => <body>`. /// `<pat> (if <guard>) => <body>`.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Arm { pub struct Arm<'hir> {
#[stable_hasher(ignore)] #[stable_hasher(ignore)]
pub hir_id: HirId, pub hir_id: HirId,
pub span: Span, pub span: Span,
pub attrs: HirVec<Attribute>, pub attrs: &'hir [Attribute],
/// If this pattern and the optional guard matches, then `body` is evaluated. /// If this pattern and the optional guard matches, then `body` is evaluated.
pub pat: P<Pat>, pub pat: &'hir Pat<'hir>,
/// Optional guard clause. /// Optional guard clause.
pub guard: Option<Guard>, pub guard: Option<Guard<'hir>>,
/// The expression the arm evaluates to if this arm matches. /// The expression the arm evaluates to if this arm matches.
pub body: P<Expr>, pub body: &'hir Expr<'hir>,
} }
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum Guard { pub enum Guard<'hir> {
If(P<Expr>), If(&'hir Expr<'hir>),
} }
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Field { pub struct Field<'hir> {
#[stable_hasher(ignore)] #[stable_hasher(ignore)]
pub hir_id: HirId, pub hir_id: HirId,
pub ident: Ident, pub ident: Ident,
pub expr: P<Expr>, pub expr: &'hir Expr<'hir>,
pub span: Span, pub span: Span,
pub is_shorthand: bool, pub is_shorthand: bool,
} }
@ -1342,8 +1342,8 @@ pub struct BodyId {
/// map using `body_owner_def_id()`. /// map using `body_owner_def_id()`.
#[derive(RustcEncodable, RustcDecodable, Debug)] #[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct Body<'hir> { pub struct Body<'hir> {
pub params: &'hir [Param], pub params: &'hir [Param<'hir>],
pub value: Expr, pub value: Expr<'hir>,
pub generator_kind: Option<GeneratorKind>, pub generator_kind: Option<GeneratorKind>,
} }
@ -1443,18 +1443,18 @@ pub struct AnonConst {
/// An expression. /// An expression.
#[derive(RustcEncodable, RustcDecodable)] #[derive(RustcEncodable, RustcDecodable)]
pub struct Expr { pub struct Expr<'hir> {
pub hir_id: HirId, pub hir_id: HirId,
pub kind: ExprKind, pub kind: ExprKind<'hir>,
pub attrs: AttrVec, pub attrs: AttrVec,
pub span: Span, pub span: Span,
} }
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger. // `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
static_assert_size!(Expr, 64); static_assert_size!(Expr<'static>, 64);
impl Expr { impl Expr<'_> {
pub fn precedence(&self) -> ExprPrecedence { pub fn precedence(&self) -> ExprPrecedence {
match self.kind { match self.kind {
ExprKind::Box(_) => ExprPrecedence::Box, ExprKind::Box(_) => ExprPrecedence::Box,
@ -1563,7 +1563,7 @@ impl Expr {
} }
} }
impl fmt::Debug for Expr { impl fmt::Debug for Expr<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
@ -1579,7 +1579,7 @@ impl fmt::Debug for Expr {
/// ///
/// FIXME(#60607): This function is a hack. If and when we have `QPath::Lang(...)`, /// FIXME(#60607): This function is a hack. If and when we have `QPath::Lang(...)`,
/// we can use that instead as simpler, more reliable mechanism, as opposed to using `SourceMap`. /// we can use that instead as simpler, more reliable mechanism, as opposed to using `SourceMap`.
pub fn is_range_literal(sm: &SourceMap, expr: &Expr) -> bool { pub fn is_range_literal(sm: &SourceMap, expr: &Expr<'_>) -> bool {
// Returns whether the given path represents a (desugared) range, // Returns whether the given path represents a (desugared) range,
// either in std or core, i.e. has either a `::std::ops::Range` or // either in std or core, i.e. has either a `::std::ops::Range` or
// `::core::ops::Range` prefix. // `::core::ops::Range` prefix.
@ -1637,18 +1637,18 @@ pub fn is_range_literal(sm: &SourceMap, expr: &Expr) -> bool {
} }
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum ExprKind { pub enum ExprKind<'hir> {
/// A `box x` expression. /// A `box x` expression.
Box(P<Expr>), Box(&'hir Expr<'hir>),
/// An array (e.g., `[a, b, c, d]`). /// An array (e.g., `[a, b, c, d]`).
Array(HirVec<Expr>), Array(&'hir [Expr<'hir>]),
/// A function call. /// A function call.
/// ///
/// The first field resolves to the function itself (usually an `ExprKind::Path`), /// The first field resolves to the function itself (usually an `ExprKind::Path`),
/// and the second field is the list of arguments. /// and the second field is the list of arguments.
/// This also represents calling the constructor of /// This also represents calling the constructor of
/// tuple-like ADTs such as tuple structs and enum variants. /// tuple-like ADTs such as tuple structs and enum variants.
Call(P<Expr>, HirVec<Expr>), Call(&'hir Expr<'hir>, &'hir [Expr<'hir>]),
/// A method call (e.g., `x.foo::<'static, Bar, Baz>(a, b, c, d)`). /// A method call (e.g., `x.foo::<'static, Bar, Baz>(a, b, c, d)`).
/// ///
/// The `PathSegment`/`Span` represent the method name and its generic arguments /// The `PathSegment`/`Span` represent the method name and its generic arguments
@ -1663,83 +1663,82 @@ pub enum ExprKind {
/// the `hir_id` of the `MethodCall` node itself. /// the `hir_id` of the `MethodCall` node itself.
/// ///
/// [`type_dependent_def_id`]: ../ty/struct.TypeckTables.html#method.type_dependent_def_id /// [`type_dependent_def_id`]: ../ty/struct.TypeckTables.html#method.type_dependent_def_id
MethodCall(P<PathSegment>, Span, HirVec<Expr>), MethodCall(&'hir PathSegment, Span, &'hir [Expr<'hir>]),
/// A tuple (e.g., `(a, b, c, d)`). /// A tuple (e.g., `(a, b, c, d)`).
Tup(HirVec<Expr>), Tup(&'hir [Expr<'hir>]),
/// A binary operation (e.g., `a + b`, `a * b`). /// A binary operation (e.g., `a + b`, `a * b`).
Binary(BinOp, P<Expr>, P<Expr>), Binary(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>),
/// A unary operation (e.g., `!x`, `*x`). /// A unary operation (e.g., `!x`, `*x`).
Unary(UnOp, P<Expr>), Unary(UnOp, &'hir Expr<'hir>),
/// A literal (e.g., `1`, `"foo"`). /// A literal (e.g., `1`, `"foo"`).
Lit(Lit), Lit(Lit),
/// A cast (e.g., `foo as f64`). /// A cast (e.g., `foo as f64`).
Cast(P<Expr>, P<Ty>), Cast(&'hir Expr<'hir>, &'hir Ty),
/// A type reference (e.g., `Foo`). /// A type reference (e.g., `Foo`).
Type(P<Expr>, P<Ty>), Type(&'hir Expr<'hir>, &'hir Ty),
/// Wraps the expression in a terminating scope. /// Wraps the expression in a terminating scope.
/// This makes it semantically equivalent to `{ let _t = expr; _t }`. /// This makes it semantically equivalent to `{ let _t = expr; _t }`.
/// ///
/// This construct only exists to tweak the drop order in HIR lowering. /// This construct only exists to tweak the drop order in HIR lowering.
/// An example of that is the desugaring of `for` loops. /// An example of that is the desugaring of `for` loops.
DropTemps(P<Expr>), DropTemps(&'hir Expr<'hir>),
/// A conditionless loop (can be exited with `break`, `continue`, or `return`). /// A conditionless loop (can be exited with `break`, `continue`, or `return`).
/// ///
/// I.e., `'label: loop { <block> }`. /// I.e., `'label: loop { <block> }`.
Loop(P<Block>, Option<Label>, LoopSource), Loop(&'hir Block<'hir>, Option<Label>, LoopSource),
/// A `match` block, with a source that indicates whether or not it is /// A `match` block, with a source that indicates whether or not it is
/// the result of a desugaring, and if so, which kind. /// the result of a desugaring, and if so, which kind.
Match(P<Expr>, HirVec<Arm>, MatchSource), Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource),
/// A closure (e.g., `move |a, b, c| {a + b + c}`). /// A closure (e.g., `move |a, b, c| {a + b + c}`).
/// ///
/// The `Span` is the argument block `|...|`. /// The `Span` is the argument block `|...|`.
/// ///
/// This may also be a generator literal or an `async block` as indicated by the /// This may also be a generator literal or an `async block` as indicated by the
/// `Option<Movability>`. /// `Option<Movability>`.
Closure(CaptureBy, P<FnDecl>, BodyId, Span, Option<Movability>), Closure(CaptureBy, &'hir FnDecl, BodyId, Span, Option<Movability>),
/// A block (e.g., `'label: { ... }`). /// A block (e.g., `'label: { ... }`).
Block(P<Block>, Option<Label>), Block(&'hir Block<'hir>, Option<Label>),
/// An assignment (e.g., `a = foo()`). /// An assignment (e.g., `a = foo()`).
/// The `Span` argument is the span of the `=` token. Assign(&'hir Expr<'hir>, &'hir Expr<'hir>, Span),
Assign(P<Expr>, P<Expr>, Span),
/// An assignment with an operator. /// An assignment with an operator.
/// ///
/// E.g., `a += 1`. /// E.g., `a += 1`.
AssignOp(BinOp, P<Expr>, P<Expr>), AssignOp(BinOp, &'hir Expr<'hir>, &'hir Expr<'hir>),
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct or tuple field. /// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct or tuple field.
Field(P<Expr>, Ident), Field(&'hir Expr<'hir>, Ident),
/// An indexing operation (`foo[2]`). /// An indexing operation (`foo[2]`).
Index(P<Expr>, P<Expr>), Index(&'hir Expr<'hir>, &'hir Expr<'hir>),
/// Path to a definition, possibly containing lifetime or type parameters. /// Path to a definition, possibly containing lifetime or type parameters.
Path(QPath), Path(QPath),
/// A referencing operation (i.e., `&a`, `&mut a`, `&raw const a`, or `&raw mut a`). /// A referencing operation (i.e., `&a` or `&mut a`).
AddrOf(BorrowKind, Mutability, P<Expr>), AddrOf(BorrowKind, &'hir Expr<'hir>),
/// A `break`, with an optional label to break. /// A `break`, with an optional label to break.
Break(Destination, Option<P<Expr>>), Break(Destination, Option<&'hir Expr<'hir>>),
/// A `continue`, with an optional label. /// A `continue`, with an optional label.
Continue(Destination), Continue(Destination),
/// A `return`, with an optional value to be returned. /// A `return`, with an optional value to be returned.
Ret(Option<P<Expr>>), Ret(Option<&'hir Expr<'hir>>),
/// Inline assembly (from `asm!`), with its outputs and inputs. /// Inline assembly (from `asm!`), with its outputs and inputs.
InlineAsm(P<InlineAsm>), InlineAsm(&'hir InlineAsm<'hir>),
/// A struct or struct-like variant literal expression. /// A struct or struct-like variant literal expression.
/// ///
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. base}`, /// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. base}`,
/// where `base` is the `Option<Expr>`. /// where `base` is the `Option<Expr>`.
Struct(P<QPath>, HirVec<Field>, Option<P<Expr>>), Struct(&'hir QPath, &'hir [Field<'hir>], Option<&'hir Expr<'hir>>),
/// An array literal constructed from one repeated element. /// An array literal constructed from one repeated element.
/// ///
/// E.g., `[1; 5]`. The first expression is the element /// E.g., `[1; 5]`. The first expression is the element
/// to be repeated; the second is the number of times to repeat it. /// to be repeated; the second is the number of times to repeat it.
Repeat(P<Expr>, AnonConst), Repeat(&'hir Expr<'hir>, AnonConst),
/// A suspension point for generators (i.e., `yield <expr>`). /// A suspension point for generators (i.e., `yield <expr>`).
Yield(P<Expr>, YieldSource), Yield(&'hir Expr<'hir>, YieldSource),
/// A placeholder for an expression that wasn't syntactically well formed in some way. /// A placeholder for an expression that wasn't syntactically well formed in some way.
Err, Err,
@ -2159,18 +2158,18 @@ pub struct InlineAsmInner {
} }
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct InlineAsm { pub struct InlineAsm<'hir> {
pub inner: InlineAsmInner, pub inner: InlineAsmInner,
pub outputs_exprs: HirVec<Expr>, pub outputs_exprs: &'hir [Expr<'hir>],
pub inputs_exprs: HirVec<Expr>, pub inputs_exprs: &'hir [Expr<'hir>],
} }
/// Represents a parameter in a function header. /// Represents a parameter in a function header.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct Param { pub struct Param<'hir> {
pub attrs: HirVec<Attribute>, pub attrs: &'hir [Attribute],
pub hir_id: HirId, pub hir_id: HirId,
pub pat: P<Pat>, pub pat: &'hir Pat<'hir>,
pub span: Span, pub span: Span,
} }
@ -2828,7 +2827,7 @@ impl CodegenFnAttrs {
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum Node<'hir> { pub enum Node<'hir> {
Param(&'hir Param), Param(&'hir Param<'hir>),
Item(&'hir Item<'hir>), Item(&'hir Item<'hir>),
ForeignItem(&'hir ForeignItem<'hir>), ForeignItem(&'hir ForeignItem<'hir>),
TraitItem(&'hir TraitItem<'hir>), TraitItem(&'hir TraitItem<'hir>),
@ -2836,16 +2835,16 @@ pub enum Node<'hir> {
Variant(&'hir Variant<'hir>), Variant(&'hir Variant<'hir>),
Field(&'hir StructField<'hir>), Field(&'hir StructField<'hir>),
AnonConst(&'hir AnonConst), AnonConst(&'hir AnonConst),
Expr(&'hir Expr), Expr(&'hir Expr<'hir>),
Stmt(&'hir Stmt), Stmt(&'hir Stmt<'hir>),
PathSegment(&'hir PathSegment), PathSegment(&'hir PathSegment),
Ty(&'hir Ty), Ty(&'hir Ty),
TraitRef(&'hir TraitRef), TraitRef(&'hir TraitRef),
Binding(&'hir Pat), Binding(&'hir Pat<'hir>),
Pat(&'hir Pat), Pat(&'hir Pat<'hir>),
Arm(&'hir Arm), Arm(&'hir Arm<'hir>),
Block(&'hir Block), Block(&'hir Block<'hir>),
Local(&'hir Local), Local(&'hir Local<'hir>),
MacroDef(&'hir MacroDef<'hir>), MacroDef(&'hir MacroDef<'hir>),
/// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants /// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants

View File

@ -57,7 +57,7 @@ impl<T: ExactSizeIterator> EnumerateAndAdjustIterator for T {
} }
} }
impl hir::Pat { impl hir::Pat<'_> {
pub fn is_refutable(&self) -> bool { pub fn is_refutable(&self) -> bool {
match self.kind { match self.kind {
PatKind::Lit(_) PatKind::Lit(_)

View File

@ -20,12 +20,12 @@ use std::vec;
pub enum AnnNode<'a> { pub enum AnnNode<'a> {
Name(&'a ast::Name), Name(&'a ast::Name),
Block(&'a hir::Block), Block(&'a hir::Block<'a>),
Item(&'a hir::Item<'a>), Item(&'a hir::Item<'a>),
SubItem(hir::HirId), SubItem(hir::HirId),
Expr(&'a hir::Expr), Expr(&'a hir::Expr<'a>),
Pat(&'a hir::Pat), Pat(&'a hir::Pat<'a>),
Arm(&'a hir::Arm), Arm(&'a hir::Arm<'a>),
} }
pub enum Nested { pub enum Nested {
@ -242,7 +242,7 @@ impl<'a> State<'a> {
self.end(); self.end();
} }
pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[hir::Expr]) { pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[hir::Expr<'_>]) {
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span) self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span)
} }
@ -902,7 +902,7 @@ impl<'a> State<'a> {
self.ann.post(self, AnnNode::SubItem(ii.hir_id)) self.ann.post(self, AnnNode::SubItem(ii.hir_id))
} }
pub fn print_local(&mut self, init: Option<&hir::Expr>, decl: impl Fn(&mut Self)) { pub fn print_local(&mut self, init: Option<&hir::Expr<'_>>, decl: impl Fn(&mut Self)) {
self.space_if_not_bol(); self.space_if_not_bol();
self.ibox(INDENT_UNIT); self.ibox(INDENT_UNIT);
self.word_nbsp("let"); self.word_nbsp("let");
@ -919,7 +919,7 @@ impl<'a> State<'a> {
self.end() self.end()
} }
pub fn print_stmt(&mut self, st: &hir::Stmt) { pub fn print_stmt(&mut self, st: &hir::Stmt<'_>) {
self.maybe_print_comment(st.span.lo()); self.maybe_print_comment(st.span.lo());
match st.kind { match st.kind {
hir::StmtKind::Local(ref loc) => { hir::StmtKind::Local(ref loc) => {
@ -942,21 +942,21 @@ impl<'a> State<'a> {
self.maybe_print_trailing_comment(st.span, None) self.maybe_print_trailing_comment(st.span, None)
} }
pub fn print_block(&mut self, blk: &hir::Block) { pub fn print_block(&mut self, blk: &hir::Block<'_>) {
self.print_block_with_attrs(blk, &[]) self.print_block_with_attrs(blk, &[])
} }
pub fn print_block_unclosed(&mut self, blk: &hir::Block) { pub fn print_block_unclosed(&mut self, blk: &hir::Block<'_>) {
self.print_block_maybe_unclosed(blk, &[], false) self.print_block_maybe_unclosed(blk, &[], false)
} }
pub fn print_block_with_attrs(&mut self, blk: &hir::Block, attrs: &[ast::Attribute]) { pub fn print_block_with_attrs(&mut self, blk: &hir::Block<'_>, attrs: &[ast::Attribute]) {
self.print_block_maybe_unclosed(blk, attrs, true) self.print_block_maybe_unclosed(blk, attrs, true)
} }
pub fn print_block_maybe_unclosed( pub fn print_block_maybe_unclosed(
&mut self, &mut self,
blk: &hir::Block, blk: &hir::Block<'_>,
attrs: &[ast::Attribute], attrs: &[ast::Attribute],
close_box: bool, close_box: bool,
) { ) {
@ -988,13 +988,13 @@ impl<'a> State<'a> {
self.ann.nested(self, Nested::Body(constant.body)) self.ann.nested(self, Nested::Body(constant.body))
} }
fn print_call_post(&mut self, args: &[hir::Expr]) { fn print_call_post(&mut self, args: &[hir::Expr<'_>]) {
self.popen(); self.popen();
self.commasep_exprs(Inconsistent, args); self.commasep_exprs(Inconsistent, args);
self.pclose() self.pclose()
} }
pub fn print_expr_maybe_paren(&mut self, expr: &hir::Expr, prec: i8) { pub fn print_expr_maybe_paren(&mut self, expr: &hir::Expr<'_>, prec: i8) {
let needs_par = expr.precedence().order() < prec; let needs_par = expr.precedence().order() < prec;
if needs_par { if needs_par {
self.popen(); self.popen();
@ -1007,7 +1007,7 @@ impl<'a> State<'a> {
/// Print an expr using syntax that's acceptable in a condition position, such as the `cond` in /// Print an expr using syntax that's acceptable in a condition position, such as the `cond` in
/// `if cond { ... }`. /// `if cond { ... }`.
pub fn print_expr_as_cond(&mut self, expr: &hir::Expr) { pub fn print_expr_as_cond(&mut self, expr: &hir::Expr<'_>) {
let needs_par = match expr.kind { let needs_par = match expr.kind {
// These cases need parens due to the parse error observed in #26461: `if return {}` // These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`. // parses as the erroneous construct `if (return {})`, not `if (return) {}`.
@ -1025,7 +1025,7 @@ impl<'a> State<'a> {
} }
} }
fn print_expr_vec(&mut self, exprs: &[hir::Expr]) { fn print_expr_vec(&mut self, exprs: &[hir::Expr<'_>]) {
self.ibox(INDENT_UNIT); self.ibox(INDENT_UNIT);
self.s.word("["); self.s.word("[");
self.commasep_exprs(Inconsistent, exprs); self.commasep_exprs(Inconsistent, exprs);
@ -1033,7 +1033,7 @@ impl<'a> State<'a> {
self.end() self.end()
} }
fn print_expr_repeat(&mut self, element: &hir::Expr, count: &hir::AnonConst) { fn print_expr_repeat(&mut self, element: &hir::Expr<'_>, count: &hir::AnonConst) {
self.ibox(INDENT_UNIT); self.ibox(INDENT_UNIT);
self.s.word("["); self.s.word("[");
self.print_expr(element); self.print_expr(element);
@ -1046,8 +1046,8 @@ impl<'a> State<'a> {
fn print_expr_struct( fn print_expr_struct(
&mut self, &mut self,
qpath: &hir::QPath, qpath: &hir::QPath,
fields: &[hir::Field], fields: &[hir::Field<'_>],
wth: &Option<P<hir::Expr>>, wth: &Option<P<hir::Expr<'_>>>,
) { ) {
self.print_qpath(qpath, true); self.print_qpath(qpath, true);
self.s.word("{"); self.s.word("{");
@ -1085,7 +1085,7 @@ impl<'a> State<'a> {
self.s.word("}"); self.s.word("}");
} }
fn print_expr_tup(&mut self, exprs: &[hir::Expr]) { fn print_expr_tup(&mut self, exprs: &[hir::Expr<'_>]) {
self.popen(); self.popen();
self.commasep_exprs(Inconsistent, exprs); self.commasep_exprs(Inconsistent, exprs);
if exprs.len() == 1 { if exprs.len() == 1 {
@ -1094,7 +1094,7 @@ impl<'a> State<'a> {
self.pclose() self.pclose()
} }
fn print_expr_call(&mut self, func: &hir::Expr, args: &[hir::Expr]) { fn print_expr_call(&mut self, func: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
let prec = match func.kind { let prec = match func.kind {
hir::ExprKind::Field(..) => parser::PREC_FORCE_PAREN, hir::ExprKind::Field(..) => parser::PREC_FORCE_PAREN,
_ => parser::PREC_POSTFIX, _ => parser::PREC_POSTFIX,
@ -1104,7 +1104,7 @@ impl<'a> State<'a> {
self.print_call_post(args) self.print_call_post(args)
} }
fn print_expr_method_call(&mut self, segment: &hir::PathSegment, args: &[hir::Expr]) { fn print_expr_method_call(&mut self, segment: &hir::PathSegment, args: &[hir::Expr<'_>]) {
let base_args = &args[1..]; let base_args = &args[1..];
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX); self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX);
self.s.word("."); self.s.word(".");
@ -1118,7 +1118,7 @@ impl<'a> State<'a> {
self.print_call_post(base_args) self.print_call_post(base_args)
} }
fn print_expr_binary(&mut self, op: hir::BinOp, lhs: &hir::Expr, rhs: &hir::Expr) { fn print_expr_binary(&mut self, op: hir::BinOp, lhs: &hir::Expr<'_>, rhs: &hir::Expr<'_>) {
let assoc_op = bin_op_to_assoc_op(op.node); let assoc_op = bin_op_to_assoc_op(op.node);
let prec = assoc_op.precedence() as i8; let prec = assoc_op.precedence() as i8;
let fixity = assoc_op.fixity(); let fixity = assoc_op.fixity();
@ -1144,7 +1144,7 @@ impl<'a> State<'a> {
self.print_expr_maybe_paren(rhs, right_prec) self.print_expr_maybe_paren(rhs, right_prec)
} }
fn print_expr_unary(&mut self, op: hir::UnOp, expr: &hir::Expr) { fn print_expr_unary(&mut self, op: hir::UnOp, expr: &hir::Expr<'_>) {
self.s.word(op.as_str()); self.s.word(op.as_str());
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX) self.print_expr_maybe_paren(expr, parser::PREC_PREFIX)
} }
@ -1153,7 +1153,7 @@ impl<'a> State<'a> {
&mut self, &mut self,
kind: hir::BorrowKind, kind: hir::BorrowKind,
mutability: hir::Mutability, mutability: hir::Mutability,
expr: &hir::Expr, expr: &hir::Expr<'_>,
) { ) {
self.s.word("&"); self.s.word("&");
match kind { match kind {
@ -1171,7 +1171,7 @@ impl<'a> State<'a> {
self.word(lit.node.to_lit_token().to_string()) self.word(lit.node.to_lit_token().to_string())
} }
pub fn print_expr(&mut self, expr: &hir::Expr) { pub fn print_expr(&mut self, expr: &hir::Expr<'_>) {
self.maybe_print_comment(expr.span.lo()); self.maybe_print_comment(expr.span.lo());
self.print_outer_attributes(&expr.attrs); self.print_outer_attributes(&expr.attrs);
self.ibox(INDENT_UNIT); self.ibox(INDENT_UNIT);
@ -1418,7 +1418,7 @@ impl<'a> State<'a> {
self.end() self.end()
} }
pub fn print_local_decl(&mut self, loc: &hir::Local) { pub fn print_local_decl(&mut self, loc: &hir::Local<'_>) {
self.print_pat(&loc.pat); self.print_pat(&loc.pat);
if let Some(ref ty) = loc.ty { if let Some(ref ty) = loc.ty {
self.word_space(":"); self.word_space(":");
@ -1434,7 +1434,7 @@ impl<'a> State<'a> {
self.print_ident(ast::Ident::with_dummy_span(name)) self.print_ident(ast::Ident::with_dummy_span(name))
} }
pub fn print_for_decl(&mut self, loc: &hir::Local, coll: &hir::Expr) { pub fn print_for_decl(&mut self, loc: &hir::Local<'_>, coll: &hir::Expr<'_>) {
self.print_local_decl(loc); self.print_local_decl(loc);
self.s.space(); self.s.space();
self.word_space("in"); self.word_space("in");
@ -1599,7 +1599,7 @@ impl<'a> State<'a> {
} }
} }
pub fn print_pat(&mut self, pat: &hir::Pat) { pub fn print_pat(&mut self, pat: &hir::Pat<'_>) {
self.maybe_print_comment(pat.span.lo()); self.maybe_print_comment(pat.span.lo());
self.ann.pre(self, AnnNode::Pat(pat)); self.ann.pre(self, AnnNode::Pat(pat));
// Pat isn't normalized, but the beauty of it // Pat isn't normalized, but the beauty of it
@ -1761,12 +1761,12 @@ impl<'a> State<'a> {
self.ann.post(self, AnnNode::Pat(pat)) self.ann.post(self, AnnNode::Pat(pat))
} }
pub fn print_param(&mut self, arg: &hir::Param) { pub fn print_param(&mut self, arg: &hir::Param<'_>) {
self.print_outer_attributes(&arg.attrs); self.print_outer_attributes(&arg.attrs);
self.print_pat(&arg.pat); self.print_pat(&arg.pat);
} }
pub fn print_arm(&mut self, arm: &hir::Arm) { pub fn print_arm(&mut self, arm: &hir::Arm<'_>) {
// I have no idea why this check is necessary, but here it // I have no idea why this check is necessary, but here it
// is :( // is :(
if arm.attrs.is_empty() { if arm.attrs.is_empty() {
@ -2212,7 +2212,7 @@ impl<'a> State<'a> {
/// isn't parsed as (if true {...} else {...} | x) | 5 /// isn't parsed as (if true {...} else {...} | x) | 5
// //
// Duplicated from `parse::classify`, but adapted for the HIR. // Duplicated from `parse::classify`, but adapted for the HIR.
fn expr_requires_semi_to_be_stmt(e: &hir::Expr) -> bool { fn expr_requires_semi_to_be_stmt(e: &hir::Expr<'_>) -> bool {
match e.kind { match e.kind {
hir::ExprKind::Match(..) | hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) => false, hir::ExprKind::Match(..) | hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) => false,
_ => true, _ => true,
@ -2222,7 +2222,7 @@ fn expr_requires_semi_to_be_stmt(e: &hir::Expr) -> bool {
/// This statement requires a semicolon after it. /// This statement requires a semicolon after it.
/// note that in one case (stmt_semi), we've already /// note that in one case (stmt_semi), we've already
/// seen the semicolon, and thus don't need another. /// seen the semicolon, and thus don't need another.
fn stmt_ends_with_semi(stmt: &hir::StmtKind) -> bool { fn stmt_ends_with_semi(stmt: &hir::StmtKind<'_>) -> bool {
match *stmt { match *stmt {
hir::StmtKind::Local(_) => true, hir::StmtKind::Local(_) => true,
hir::StmtKind::Item(_) => false, hir::StmtKind::Item(_) => false,
@ -2261,7 +2261,7 @@ fn bin_op_to_assoc_op(op: hir::BinOpKind) -> AssocOp {
/// Expressions that syntactically contain an "exterior" struct literal, i.e., not surrounded by any /// Expressions that syntactically contain an "exterior" struct literal, i.e., not surrounded by any
/// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and /// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not. /// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.
fn contains_exterior_struct_lit(value: &hir::Expr) -> bool { fn contains_exterior_struct_lit(value: &hir::Expr<'_>) -> bool {
match value.kind { match value.kind {
hir::ExprKind::Struct(..) => true, hir::ExprKind::Struct(..) => true,

View File

@ -46,7 +46,7 @@ impl Visitor<'tcx> for LocalCollector {
NestedVisitorMap::None NestedVisitorMap::None
} }
fn visit_pat(&mut self, pat: &'tcx hir::Pat) { fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
if let hir::PatKind::Binding(_, hir_id, ..) = pat.kind { if let hir::PatKind::Binding(_, hir_id, ..) = pat.kind {
self.locals.insert(hir_id); self.locals.insert(hir_id);
} }
@ -81,7 +81,7 @@ impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> {
intravisit::walk_path(self, path); intravisit::walk_path(self, path);
} }
fn visit_expr(&mut self, expr: &'tcx hir::Expr) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if let hir::ExprKind::Closure(..) = expr.kind { if let hir::ExprKind::Closure(..) = expr.kind {
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id); let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
if let Some(upvars) = self.tcx.upvars(closure_def_id) { if let Some(upvars) = self.tcx.upvars(closure_def_id) {

View File

@ -117,7 +117,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Ty {
} }
} }
impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr { impl<'a> HashStable<StableHashingContext<'a>> for hir::Expr<'_> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.while_hashing_hir_bodies(true, |hcx| { hcx.while_hashing_hir_bodies(true, |hcx| {
let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *self; let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *self;

View File

@ -17,11 +17,11 @@ struct FindLocalByTypeVisitor<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>, infcx: &'a InferCtxt<'a, 'tcx>,
target_ty: Ty<'tcx>, target_ty: Ty<'tcx>,
hir_map: &'a hir::map::Map<'tcx>, hir_map: &'a hir::map::Map<'tcx>,
found_local_pattern: Option<&'tcx Pat>, found_local_pattern: Option<&'tcx Pat<'tcx>>,
found_arg_pattern: Option<&'tcx Pat>, found_arg_pattern: Option<&'tcx Pat<'tcx>>,
found_ty: Option<Ty<'tcx>>, found_ty: Option<Ty<'tcx>>,
found_closure: Option<&'tcx ExprKind>, found_closure: Option<&'tcx ExprKind<'tcx>>,
found_method_call: Option<&'tcx Expr>, found_method_call: Option<&'tcx Expr<'tcx>>,
} }
impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> { impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> {
@ -72,7 +72,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> {
NestedVisitorMap::OnlyBodies(&self.hir_map) NestedVisitorMap::OnlyBodies(&self.hir_map)
} }
fn visit_local(&mut self, local: &'tcx Local) { fn visit_local(&mut self, local: &'tcx Local<'tcx>) {
if let (None, Some(ty)) = (self.found_local_pattern, self.node_matches_type(local.hir_id)) { if let (None, Some(ty)) = (self.found_local_pattern, self.node_matches_type(local.hir_id)) {
self.found_local_pattern = Some(&*local.pat); self.found_local_pattern = Some(&*local.pat);
self.found_ty = Some(ty); self.found_ty = Some(ty);
@ -91,7 +91,7 @@ impl<'a, 'tcx> Visitor<'tcx> for FindLocalByTypeVisitor<'a, 'tcx> {
intravisit::walk_body(self, body); intravisit::walk_body(self, body);
} }
fn visit_expr(&mut self, expr: &'tcx Expr) { fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
if self.node_matches_type(expr.hir_id).is_some() { if self.node_matches_type(expr.hir_id).is_some() {
match expr.kind { match expr.kind {
ExprKind::Closure(..) => self.found_closure = Some(&expr.kind), ExprKind::Closure(..) => self.found_closure = Some(&expr.kind),
@ -461,7 +461,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn annotate_method_call( fn annotate_method_call(
&self, &self,
segment: &hir::ptr::P<hir::PathSegment>, segment: &hir::ptr::P<hir::PathSegment>,
e: &Expr, e: &Expr<'_>,
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
) { ) {
if let (Ok(snippet), Some(tables), None) = ( if let (Ok(snippet), Some(tables), None) = (

View File

@ -12,7 +12,7 @@ use syntax_pos::Span;
#[derive(Debug)] #[derive(Debug)]
pub(super) struct AnonymousParamInfo<'tcx> { pub(super) struct AnonymousParamInfo<'tcx> {
// the parameter corresponding to the anonymous region // the parameter corresponding to the anonymous region
pub param: &'tcx hir::Param, pub param: &'tcx hir::Param<'tcx>,
// the type corresponding to the anonymopus region parameter // the type corresponding to the anonymopus region parameter
pub param_ty: Ty<'tcx>, pub param_ty: Ty<'tcx>,
// the ty::BoundRegion corresponding to the anonymous region // the ty::BoundRegion corresponding to the anonymous region

View File

@ -894,7 +894,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
self.context.tables = old_tables; self.context.tables = old_tables;
} }
fn visit_param(&mut self, param: &'tcx hir::Param) { fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
self.with_lint_attrs(param.hir_id, &param.attrs, |cx| { self.with_lint_attrs(param.hir_id, &param.attrs, |cx| {
lint_callback!(cx, check_param, param); lint_callback!(cx, check_param, param);
hir_visit::walk_param(cx, param); hir_visit::walk_param(cx, param);
@ -930,12 +930,12 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
}) })
} }
fn visit_pat(&mut self, p: &'tcx hir::Pat) { fn visit_pat(&mut self, p: &'tcx hir::Pat<'tcx>) {
lint_callback!(self, check_pat, p); lint_callback!(self, check_pat, p);
hir_visit::walk_pat(self, p); hir_visit::walk_pat(self, p);
} }
fn visit_expr(&mut self, e: &'tcx hir::Expr) { fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
self.with_lint_attrs(e.hir_id, &e.attrs, |cx| { self.with_lint_attrs(e.hir_id, &e.attrs, |cx| {
lint_callback!(cx, check_expr, e); lint_callback!(cx, check_expr, e);
hir_visit::walk_expr(cx, e); hir_visit::walk_expr(cx, e);
@ -943,7 +943,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
}) })
} }
fn visit_stmt(&mut self, s: &'tcx hir::Stmt) { fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
// statement attributes are actually just attributes on one of // statement attributes are actually just attributes on one of
// - item // - item
// - local // - local
@ -1020,20 +1020,20 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
} }
} }
fn visit_local(&mut self, l: &'tcx hir::Local) { fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
self.with_lint_attrs(l.hir_id, &l.attrs, |cx| { self.with_lint_attrs(l.hir_id, &l.attrs, |cx| {
lint_callback!(cx, check_local, l); lint_callback!(cx, check_local, l);
hir_visit::walk_local(cx, l); hir_visit::walk_local(cx, l);
}) })
} }
fn visit_block(&mut self, b: &'tcx hir::Block) { fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) {
lint_callback!(self, check_block, b); lint_callback!(self, check_block, b);
hir_visit::walk_block(self, b); hir_visit::walk_block(self, b);
lint_callback!(self, check_block_post, b); lint_callback!(self, check_block_post, b);
} }
fn visit_arm(&mut self, a: &'tcx hir::Arm) { fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
lint_callback!(self, check_arm, a); lint_callback!(self, check_arm, a);
hir_visit::walk_arm(self, a); hir_visit::walk_arm(self, a);
} }

View File

@ -87,7 +87,7 @@ macro_rules! declare_lint_pass {
macro_rules! late_lint_methods { macro_rules! late_lint_methods {
($macro:path, $args:tt, [$hir:tt]) => ( ($macro:path, $args:tt, [$hir:tt]) => (
$macro!($args, [$hir], [ $macro!($args, [$hir], [
fn check_param(a: &$hir hir::Param); fn check_param(a: &$hir hir::Param<$hir>);
fn check_body(a: &$hir hir::Body<$hir>); fn check_body(a: &$hir hir::Body<$hir>);
fn check_body_post(a: &$hir hir::Body<$hir>); fn check_body_post(a: &$hir hir::Body<$hir>);
fn check_name(a: Span, b: ast::Name); fn check_name(a: Span, b: ast::Name);
@ -99,14 +99,14 @@ macro_rules! late_lint_methods {
fn check_foreign_item_post(a: &$hir hir::ForeignItem<$hir>); fn check_foreign_item_post(a: &$hir hir::ForeignItem<$hir>);
fn check_item(a: &$hir hir::Item<$hir>); fn check_item(a: &$hir hir::Item<$hir>);
fn check_item_post(a: &$hir hir::Item<$hir>); fn check_item_post(a: &$hir hir::Item<$hir>);
fn check_local(a: &$hir hir::Local); fn check_local(a: &$hir hir::Local<$hir>);
fn check_block(a: &$hir hir::Block); fn check_block(a: &$hir hir::Block<$hir>);
fn check_block_post(a: &$hir hir::Block); fn check_block_post(a: &$hir hir::Block<$hir>);
fn check_stmt(a: &$hir hir::Stmt); fn check_stmt(a: &$hir hir::Stmt<$hir>);
fn check_arm(a: &$hir hir::Arm); fn check_arm(a: &$hir hir::Arm<$hir>);
fn check_pat(a: &$hir hir::Pat); fn check_pat(a: &$hir hir::Pat<$hir>);
fn check_expr(a: &$hir hir::Expr); fn check_expr(a: &$hir hir::Expr<$hir>);
fn check_expr_post(a: &$hir hir::Expr); fn check_expr_post(a: &$hir hir::Expr<$hir>);
fn check_ty(a: &$hir hir::Ty); fn check_ty(a: &$hir hir::Ty);
fn check_generic_param(a: &$hir hir::GenericParam); fn check_generic_param(a: &$hir hir::GenericParam);
fn check_generics(a: &$hir hir::Generics); fn check_generics(a: &$hir hir::Generics);
@ -610,7 +610,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
intravisit::NestedVisitorMap::All(&self.tcx.hir()) intravisit::NestedVisitorMap::All(&self.tcx.hir())
} }
fn visit_param(&mut self, param: &'tcx hir::Param) { fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
self.with_lint_attrs(param.hir_id, &param.attrs, |builder| { self.with_lint_attrs(param.hir_id, &param.attrs, |builder| {
intravisit::walk_param(builder, param); intravisit::walk_param(builder, param);
}); });
@ -628,7 +628,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
}) })
} }
fn visit_expr(&mut self, e: &'tcx hir::Expr) { fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
self.with_lint_attrs(e.hir_id, &e.attrs, |builder| { self.with_lint_attrs(e.hir_id, &e.attrs, |builder| {
intravisit::walk_expr(builder, e); intravisit::walk_expr(builder, e);
}) })
@ -651,13 +651,13 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
}) })
} }
fn visit_local(&mut self, l: &'tcx hir::Local) { fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
self.with_lint_attrs(l.hir_id, &l.attrs, |builder| { self.with_lint_attrs(l.hir_id, &l.attrs, |builder| {
intravisit::walk_local(builder, l); intravisit::walk_local(builder, l);
}) })
} }
fn visit_arm(&mut self, a: &'tcx hir::Arm) { fn visit_arm(&mut self, a: &'tcx hir::Arm<'tcx>) {
self.with_lint_attrs(a.hir_id, &a.attrs, |builder| { self.with_lint_attrs(a.hir_id, &a.attrs, |builder| {
intravisit::walk_arm(builder, a); intravisit::walk_arm(builder, a);
}) })

View File

@ -96,7 +96,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
self.tables = old_tables; self.tables = old_tables;
} }
fn visit_expr(&mut self, expr: &'tcx hir::Expr) { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
let res = match expr.kind { let res = match expr.kind {
hir::ExprKind::Path(ref qpath) => Some(self.tables.qpath_res(qpath, expr.hir_id)), hir::ExprKind::Path(ref qpath) => Some(self.tables.qpath_res(qpath, expr.hir_id)),
hir::ExprKind::MethodCall(..) => self hir::ExprKind::MethodCall(..) => self

View File

@ -432,7 +432,7 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor {
NestedVisitorMap::None NestedVisitorMap::None
} }
fn visit_pat(&mut self, pat: &'tcx Pat) { fn visit_pat(&mut self, pat: &'tcx Pat<'tcx>) {
intravisit::walk_pat(self, pat); intravisit::walk_pat(self, pat);
self.expr_and_pat_count += 1; self.expr_and_pat_count += 1;
@ -442,7 +442,7 @@ impl<'tcx> Visitor<'tcx> for ExprLocatorVisitor {
} }
} }
fn visit_expr(&mut self, expr: &'tcx Expr) { fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
debug!("ExprLocatorVisitor - pre-increment {} expr = {:?}", self.expr_and_pat_count, expr); debug!("ExprLocatorVisitor - pre-increment {} expr = {:?}", self.expr_and_pat_count, expr);
intravisit::walk_expr(self, expr); intravisit::walk_expr(self, expr);
@ -773,7 +773,7 @@ fn record_var_lifetime(
} }
} }
fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx hir::Block) { fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx hir::Block<'tcx>) {
debug!("resolve_block(blk.hir_id={:?})", blk.hir_id); debug!("resolve_block(blk.hir_id={:?})", blk.hir_id);
let prev_cx = visitor.cx; let prev_cx = visitor.cx;
@ -837,7 +837,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
visitor.cx = prev_cx; visitor.cx = prev_cx;
} }
fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir::Arm) { fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir::Arm<'tcx>) {
let prev_cx = visitor.cx; let prev_cx = visitor.cx;
visitor.enter_scope(Scope { id: arm.hir_id.local_id, data: ScopeData::Node }); visitor.enter_scope(Scope { id: arm.hir_id.local_id, data: ScopeData::Node });
@ -854,7 +854,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
visitor.cx = prev_cx; visitor.cx = prev_cx;
} }
fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir::Pat) { fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
visitor.record_child_scope(Scope { id: pat.hir_id.local_id, data: ScopeData::Node }); visitor.record_child_scope(Scope { id: pat.hir_id.local_id, data: ScopeData::Node });
// If this is a binding then record the lifetime of that binding. // If this is a binding then record the lifetime of that binding.
@ -871,7 +871,7 @@ fn resolve_pat<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, pat: &'tcx hir
debug!("resolve_pat - post-increment {} pat = {:?}", visitor.expr_and_pat_count, pat); debug!("resolve_pat - post-increment {} pat = {:?}", visitor.expr_and_pat_count, pat);
} }
fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx hir::Stmt) { fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx hir::Stmt<'tcx>) {
let stmt_id = stmt.hir_id.local_id; let stmt_id = stmt.hir_id.local_id;
debug!("resolve_stmt(stmt.id={:?})", stmt_id); debug!("resolve_stmt(stmt.id={:?})", stmt_id);
@ -890,7 +890,7 @@ fn resolve_stmt<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, stmt: &'tcx h
visitor.cx.parent = prev_parent; visitor.cx.parent = prev_parent;
} }
fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx hir::Expr) { fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
debug!("resolve_expr - pre-increment {} expr = {:?}", visitor.expr_and_pat_count, expr); debug!("resolve_expr - pre-increment {} expr = {:?}", visitor.expr_and_pat_count, expr);
let prev_cx = visitor.cx; let prev_cx = visitor.cx;
@ -1107,8 +1107,8 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
fn resolve_local<'tcx>( fn resolve_local<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>, visitor: &mut RegionResolutionVisitor<'tcx>,
pat: Option<&'tcx hir::Pat>, pat: Option<&'tcx hir::Pat<'tcx>>,
init: Option<&'tcx hir::Expr>, init: Option<&'tcx hir::Expr<'tcx>>,
) { ) {
debug!("resolve_local(pat={:?}, init={:?})", pat, init); debug!("resolve_local(pat={:?}, init={:?})", pat, init);
@ -1197,7 +1197,7 @@ fn resolve_local<'tcx>(
/// | ( ..., P&, ... ) /// | ( ..., P&, ... )
/// | ... "|" P& "|" ... /// | ... "|" P& "|" ...
/// | box P& /// | box P&
fn is_binding_pat(pat: &hir::Pat) -> bool { fn is_binding_pat(pat: &hir::Pat<'_>) -> bool {
// Note that the code below looks for *explicit* refs only, that is, it won't // Note that the code below looks for *explicit* refs only, that is, it won't
// know about *implicit* refs as introduced in #42640. // know about *implicit* refs as introduced in #42640.
// //
@ -1263,7 +1263,7 @@ fn resolve_local<'tcx>(
/// | ( E& ) /// | ( E& )
fn record_rvalue_scope_if_borrow_expr<'tcx>( fn record_rvalue_scope_if_borrow_expr<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>, visitor: &mut RegionResolutionVisitor<'tcx>,
expr: &hir::Expr, expr: &hir::Expr<'_>,
blk_id: Option<Scope>, blk_id: Option<Scope>,
) { ) {
match expr.kind { match expr.kind {
@ -1310,7 +1310,7 @@ fn resolve_local<'tcx>(
/// Note: ET is intended to match "rvalues or places based on rvalues". /// Note: ET is intended to match "rvalues or places based on rvalues".
fn record_rvalue_scope<'tcx>( fn record_rvalue_scope<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>, visitor: &mut RegionResolutionVisitor<'tcx>,
expr: &hir::Expr, expr: &hir::Expr<'_>,
blk_scope: Option<Scope>, blk_scope: Option<Scope>,
) { ) {
let mut expr = expr; let mut expr = expr;
@ -1372,7 +1372,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
NestedVisitorMap::None NestedVisitorMap::None
} }
fn visit_block(&mut self, b: &'tcx Block) { fn visit_block(&mut self, b: &'tcx Block<'tcx>) {
resolve_block(self, b); resolve_block(self, b);
} }
@ -1444,19 +1444,19 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
self.terminating_scopes = outer_ts; self.terminating_scopes = outer_ts;
} }
fn visit_arm(&mut self, a: &'tcx Arm) { fn visit_arm(&mut self, a: &'tcx Arm<'tcx>) {
resolve_arm(self, a); resolve_arm(self, a);
} }
fn visit_pat(&mut self, p: &'tcx Pat) { fn visit_pat(&mut self, p: &'tcx Pat<'tcx>) {
resolve_pat(self, p); resolve_pat(self, p);
} }
fn visit_stmt(&mut self, s: &'tcx Stmt) { fn visit_stmt(&mut self, s: &'tcx Stmt<'tcx>) {
resolve_stmt(self, s); resolve_stmt(self, s);
} }
fn visit_expr(&mut self, ex: &'tcx Expr) { fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
resolve_expr(self, ex); resolve_expr(self, ex);
} }
fn visit_local(&mut self, l: &'tcx Local) { fn visit_local(&mut self, l: &'tcx Local<'tcx>) {
resolve_local(self, Some(&l.pat), l.init.as_ref().map(|e| &**e)); resolve_local(self, Some(&l.pat), l.init.as_ref().map(|e| &**e));
} }
} }

View File

@ -1133,7 +1133,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
NestedVisitorMap::None NestedVisitorMap::None
} }
fn visit_expr(&mut self, ex: &hir::Expr) { fn visit_expr(&mut self, ex: &hir::Expr<'_>) {
if let Some(label) = expression_label(ex) { if let Some(label) = expression_label(ex) {
for prior_label in &self.labels_in_fn[..] { for prior_label in &self.labels_in_fn[..] {
// FIXME (#24278): non-hygienic comparison // FIXME (#24278): non-hygienic comparison
@ -1155,7 +1155,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
} }
} }
fn expression_label(ex: &hir::Expr) -> Option<ast::Ident> { fn expression_label(ex: &hir::Expr<'_>) -> Option<ast::Ident> {
if let hir::ExprKind::Loop(_, Some(label), _) = ex.kind { Some(label.ident) } else { None } if let hir::ExprKind::Loop(_, Some(label), _) = ex.kind { Some(label.ident) } else { None }
} }

View File

@ -1331,19 +1331,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'_>, err: &mut DiagnosticBuilder<'_>,
msg: &str, msg: &str,
) -> Option<String> { ) -> Option<String> {
let get_name = |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind| -> Option<String> { let get_name =
// Get the local name of this closure. This can be inaccurate because |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option<String> {
// of the possibility of reassignment, but this should be good enough. // Get the local name of this closure. This can be inaccurate because
match &kind { // of the possibility of reassignment, but this should be good enough.
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => { match &kind {
Some(format!("{}", name)) hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
Some(format!("{}", name))
}
_ => {
err.note(&msg);
None
}
} }
_ => { };
err.note(&msg);
None
}
}
};
let hir = self.tcx.hir(); let hir = self.tcx.hir();
let hir_id = hir.as_local_hir_id(def_id)?; let hir_id = hir.as_local_hir_id(def_id)?;

View File

@ -553,11 +553,11 @@ impl<'tcx> TypeckTables<'tcx> {
// Returns the type of a pattern as a monotype. Like @expr_ty, this function // Returns the type of a pattern as a monotype. Like @expr_ty, this function
// doesn't provide type parameter substitutions. // doesn't provide type parameter substitutions.
pub fn pat_ty(&self, pat: &hir::Pat) -> Ty<'tcx> { pub fn pat_ty(&self, pat: &hir::Pat<'_>) -> Ty<'tcx> {
self.node_type(pat.hir_id) self.node_type(pat.hir_id)
} }
pub fn pat_ty_opt(&self, pat: &hir::Pat) -> Option<Ty<'tcx>> { pub fn pat_ty_opt(&self, pat: &hir::Pat<'_>) -> Option<Ty<'tcx>> {
self.node_type_opt(pat.hir_id) self.node_type_opt(pat.hir_id)
} }
@ -571,11 +571,11 @@ impl<'tcx> TypeckTables<'tcx> {
// NB (2): This type doesn't provide type parameter substitutions; e.g., if you // NB (2): This type doesn't provide type parameter substitutions; e.g., if you
// ask for the type of "id" in "id(3)", it will return "fn(&isize) -> isize" // ask for the type of "id" in "id(3)", it will return "fn(&isize) -> isize"
// instead of "fn(ty) -> T with T = isize". // instead of "fn(ty) -> T with T = isize".
pub fn expr_ty(&self, expr: &hir::Expr) -> Ty<'tcx> { pub fn expr_ty(&self, expr: &hir::Expr<'_>) -> Ty<'tcx> {
self.node_type(expr.hir_id) self.node_type(expr.hir_id)
} }
pub fn expr_ty_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> { pub fn expr_ty_opt(&self, expr: &hir::Expr<'_>) -> Option<Ty<'tcx>> {
self.node_type_opt(expr.hir_id) self.node_type_opt(expr.hir_id)
} }
@ -589,22 +589,22 @@ impl<'tcx> TypeckTables<'tcx> {
LocalTableInContextMut { local_id_root: self.local_id_root, data: &mut self.adjustments } LocalTableInContextMut { local_id_root: self.local_id_root, data: &mut self.adjustments }
} }
pub fn expr_adjustments(&self, expr: &hir::Expr) -> &[ty::adjustment::Adjustment<'tcx>] { pub fn expr_adjustments(&self, expr: &hir::Expr<'_>) -> &[ty::adjustment::Adjustment<'tcx>] {
validate_hir_id_for_typeck_tables(self.local_id_root, expr.hir_id, false); validate_hir_id_for_typeck_tables(self.local_id_root, expr.hir_id, false);
self.adjustments.get(&expr.hir_id.local_id).map_or(&[], |a| &a[..]) self.adjustments.get(&expr.hir_id.local_id).map_or(&[], |a| &a[..])
} }
/// Returns the type of `expr`, considering any `Adjustment` /// Returns the type of `expr`, considering any `Adjustment`
/// entry recorded for that expression. /// entry recorded for that expression.
pub fn expr_ty_adjusted(&self, expr: &hir::Expr) -> Ty<'tcx> { pub fn expr_ty_adjusted(&self, expr: &hir::Expr<'_>) -> Ty<'tcx> {
self.expr_adjustments(expr).last().map_or_else(|| self.expr_ty(expr), |adj| adj.target) self.expr_adjustments(expr).last().map_or_else(|| self.expr_ty(expr), |adj| adj.target)
} }
pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr) -> Option<Ty<'tcx>> { pub fn expr_ty_adjusted_opt(&self, expr: &hir::Expr<'_>) -> Option<Ty<'tcx>> {
self.expr_adjustments(expr).last().map(|adj| adj.target).or_else(|| self.expr_ty_opt(expr)) self.expr_adjustments(expr).last().map(|adj| adj.target).or_else(|| self.expr_ty_opt(expr))
} }
pub fn is_method_call(&self, expr: &hir::Expr) -> bool { pub fn is_method_call(&self, expr: &hir::Expr<'_>) -> bool {
// Only paths and method calls/overloaded operators have // Only paths and method calls/overloaded operators have
// entries in type_dependent_defs, ignore the former here. // entries in type_dependent_defs, ignore the former here.
if let hir::ExprKind::Path(_) = expr.kind { if let hir::ExprKind::Path(_) = expr.kind {

View File

@ -150,13 +150,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.delegate.consume(place, mode); self.delegate.consume(place, mode);
} }
fn consume_exprs(&mut self, exprs: &[hir::Expr]) { fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) {
for expr in exprs { for expr in exprs {
self.consume_expr(&expr); self.consume_expr(&expr);
} }
} }
pub fn consume_expr(&mut self, expr: &hir::Expr) { pub fn consume_expr(&mut self, expr: &hir::Expr<'_>) {
debug!("consume_expr(expr={:?})", expr); debug!("consume_expr(expr={:?})", expr);
let place = return_if_err!(self.mc.cat_expr(expr)); let place = return_if_err!(self.mc.cat_expr(expr));
@ -164,13 +164,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.walk_expr(expr); self.walk_expr(expr);
} }
fn mutate_expr(&mut self, expr: &hir::Expr) { fn mutate_expr(&mut self, expr: &hir::Expr<'_>) {
let place = return_if_err!(self.mc.cat_expr(expr)); let place = return_if_err!(self.mc.cat_expr(expr));
self.delegate.mutate(&place); self.delegate.mutate(&place);
self.walk_expr(expr); self.walk_expr(expr);
} }
fn borrow_expr(&mut self, expr: &hir::Expr, bk: ty::BorrowKind) { fn borrow_expr(&mut self, expr: &hir::Expr<'_>, bk: ty::BorrowKind) {
debug!("borrow_expr(expr={:?}, bk={:?})", expr, bk); debug!("borrow_expr(expr={:?}, bk={:?})", expr, bk);
let place = return_if_err!(self.mc.cat_expr(expr)); let place = return_if_err!(self.mc.cat_expr(expr));
@ -179,11 +179,11 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
self.walk_expr(expr) self.walk_expr(expr)
} }
fn select_from_expr(&mut self, expr: &hir::Expr) { fn select_from_expr(&mut self, expr: &hir::Expr<'_>) {
self.walk_expr(expr) self.walk_expr(expr)
} }
pub fn walk_expr(&mut self, expr: &hir::Expr) { pub fn walk_expr(&mut self, expr: &hir::Expr<'_>) {
debug!("walk_expr(expr={:?})", expr); debug!("walk_expr(expr={:?})", expr);
self.walk_adjustment(expr); self.walk_adjustment(expr);
@ -326,7 +326,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
} }
} }
fn walk_callee(&mut self, call: &hir::Expr, callee: &hir::Expr) { fn walk_callee(&mut self, call: &hir::Expr<'_>, callee: &hir::Expr<'_>) {
let callee_ty = return_if_err!(self.mc.expr_ty_adjusted(callee)); let callee_ty = return_if_err!(self.mc.expr_ty_adjusted(callee));
debug!("walk_callee: callee={:?} callee_ty={:?}", callee, callee_ty); debug!("walk_callee: callee={:?} callee_ty={:?}", callee, callee_ty);
match callee_ty.kind { match callee_ty.kind {
@ -354,7 +354,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
} }
} }
fn walk_stmt(&mut self, stmt: &hir::Stmt) { fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) {
match stmt.kind { match stmt.kind {
hir::StmtKind::Local(ref local) => { hir::StmtKind::Local(ref local) => {
self.walk_local(&local); self.walk_local(&local);
@ -371,7 +371,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
} }
} }
fn walk_local(&mut self, local: &hir::Local) { fn walk_local(&mut self, local: &hir::Local<'_>) {
if let Some(ref expr) = local.init { if let Some(ref expr) = local.init {
// Variable declarations with // Variable declarations with
// initializers are considered // initializers are considered
@ -385,7 +385,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// Indicates that the value of `blk` will be consumed, meaning either copied or moved /// Indicates that the value of `blk` will be consumed, meaning either copied or moved
/// depending on its type. /// depending on its type.
fn walk_block(&mut self, blk: &hir::Block) { fn walk_block(&mut self, blk: &hir::Block<'_>) {
debug!("walk_block(blk.hir_id={})", blk.hir_id); debug!("walk_block(blk.hir_id={})", blk.hir_id);
for stmt in &blk.stmts { for stmt in &blk.stmts {
@ -397,7 +397,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
} }
} }
fn walk_struct_expr(&mut self, fields: &[hir::Field], opt_with: &Option<P<hir::Expr>>) { fn walk_struct_expr(&mut self, fields: &[hir::Field<'_>], opt_with: &Option<P<hir::Expr<'_>>>) {
// Consume the expressions supplying values for each field. // Consume the expressions supplying values for each field.
for field in fields { for field in fields {
self.consume_expr(&field.expr); self.consume_expr(&field.expr);
@ -450,7 +450,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
// Invoke the appropriate delegate calls for anything that gets // Invoke the appropriate delegate calls for anything that gets
// consumed or borrowed as part of the automatic adjustment // consumed or borrowed as part of the automatic adjustment
// process. // process.
fn walk_adjustment(&mut self, expr: &hir::Expr) { fn walk_adjustment(&mut self, expr: &hir::Expr<'_>) {
let adjustments = self.mc.tables.expr_adjustments(expr); let adjustments = self.mc.tables.expr_adjustments(expr);
let mut place = return_if_err!(self.mc.cat_expr_unadjusted(expr)); let mut place = return_if_err!(self.mc.cat_expr_unadjusted(expr));
for adjustment in adjustments { for adjustment in adjustments {
@ -487,7 +487,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// after all relevant autoderefs have occurred. /// after all relevant autoderefs have occurred.
fn walk_autoref( fn walk_autoref(
&mut self, &mut self,
expr: &hir::Expr, expr: &hir::Expr<'_>,
base_place: &mc::Place<'tcx>, base_place: &mc::Place<'tcx>,
autoref: &adjustment::AutoBorrow<'tcx>, autoref: &adjustment::AutoBorrow<'tcx>,
) { ) {
@ -509,7 +509,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
} }
} }
fn walk_arm(&mut self, discr_place: &Place<'tcx>, arm: &hir::Arm) { fn walk_arm(&mut self, discr_place: &Place<'tcx>, arm: &hir::Arm<'_>) {
self.walk_pat(discr_place, &arm.pat); self.walk_pat(discr_place, &arm.pat);
if let Some(hir::Guard::If(ref e)) = arm.guard { if let Some(hir::Guard::If(ref e)) = arm.guard {
@ -521,12 +521,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
/// Walks a pat that occurs in isolation (i.e., top-level of fn argument or /// Walks a pat that occurs in isolation (i.e., top-level of fn argument or
/// let binding, and *not* a match arm or nested pat.) /// let binding, and *not* a match arm or nested pat.)
fn walk_irrefutable_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) { fn walk_irrefutable_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat<'_>) {
self.walk_pat(discr_place, pat); self.walk_pat(discr_place, pat);
} }
/// The core driver for walking a pattern /// The core driver for walking a pattern
fn walk_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat) { fn walk_pat(&mut self, discr_place: &Place<'tcx>, pat: &hir::Pat<'_>) {
debug!("walk_pat(discr_place={:?}, pat={:?})", discr_place, pat); debug!("walk_pat(discr_place={:?}, pat={:?})", discr_place, pat);
let tcx = self.tcx(); let tcx = self.tcx();
@ -565,7 +565,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
})); }));
} }
fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) { fn walk_captures(&mut self, closure_expr: &hir::Expr<'_>, fn_decl_span: Span) {
debug!("walk_captures({:?})", closure_expr); debug!("walk_captures({:?})", closure_expr);
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id); let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);