[] foreign_item: rustc::hir::ForeignItem<$tcx>,
[] impl_item_ref: rustc::hir::ImplItemRef,
[few] macro_def: rustc::hir::MacroDef<$tcx>,
- [] param: rustc::hir::Param,
+ [] param: rustc::hir::Param<$tcx>,
[] path: rustc::hir::Path,
[] struct_field: rustc::hir::StructField<$tcx>,
[] trait_item_ref: rustc::hir::TraitItemRef,
.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
if let hir::StmtKind::Local(ref l) = stmt.kind {
for attr in l.attrs.iter() {
}
}
- fn check_expr_attributes(&self, expr: &hir::Expr) {
+ fn check_expr_attributes(&self, expr: &hir::Expr<'_>) {
let target = match expr.kind {
hir::ExprKind::Closure(..) => Target::Closure,
_ => Target::Expression,
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);
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);
intravisit::walk_expr(self, expr)
}
}
}
- fn visit_param(&mut self, param: &'v Param) {
+ fn visit_param(&mut self, param: &'v Param<'v>) {
walk_param(self, param)
}
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
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)
}
- fn visit_block(&mut self, b: &'v Block) {
+ fn visit_block(&mut self, b: &'v Block<'v>) {
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)
}
- fn visit_arm(&mut self, a: &'v Arm) {
+ fn visit_arm(&mut self, a: &'v Arm<'v>) {
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)
}
fn visit_anon_const(&mut self, c: &'v AnonConst) {
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)
}
fn visit_ty(&mut self, t: &'v Ty) {
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
// dominates the local's definition.
walk_list!(visitor, visit_expr, &local.init);
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_pat(¶m.pat);
walk_list!(visitor, visit_attribute, ¶m.attrs);
}
}
-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);
match pattern.kind {
PatKind::TupleStruct(ref qpath, ref children, _) => {
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);
walk_list!(visitor, visit_stmt, &block.stmts);
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);
match statement.kind {
StmtKind::Local(ref local) => visitor.visit_local(local),
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);
walk_list!(visitor, visit_attribute, expression.attrs.iter());
match expression.kind {
}
}
-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_pat(&arm.pat);
if let Some(ref g) = arm.guard {
})
}
- 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();
if self.sess.features_untracked().impl_trait_in_bindings {
if let Some(ref ty) = l.ty {
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 expr = None;
/// Lowers a block directly to an expression, presuming that it
/// 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);
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 {
PatKind::Wild => hir::PatKind::Wild,
PatKind::Ident(ref binding_mode, ident, ref sub) => {
&mut self,
pats: &[AstP<Pat>],
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 rest = None;
/// When encountering `($binding_mode $ident @)? ..` (`slice`),
/// this is interpreted as a sub-slice pattern semantically.
/// 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 after = Vec::new();
let mut slice = None;
p: &Pat,
binding_mode: &BindingMode,
ident: Ident,
- lower_sub: impl FnOnce(&mut Self) -> Option<P<hir::Pat>>,
- ) -> hir::PatKind {
+ lower_sub: impl FnOnce(&mut Self) -> Option<P<hir::Pat<'hir>>>,
+ ) -> hir::PatKind<'hir> {
match self.resolver.get_partial_res(p.id).map(|d| d.base_res()) {
// `None` can occur in body-less function signatures
res @ None | res @ Some(Res::Local(_)) => {
}
}
- 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)
}
/// 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 })
}
}
/// 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()
.struct_span_err(sp, "`..` patterns are not allowed here")
.note("only allowed in tuple, tuple struct, and slice patterns")
})
}
- 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 {
StmtKind::Local(ref 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()
.map(|item_id| {
let item_id = hir::ItemId { id: self.lower_node_id(item_id) };
// 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() }
}
- 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)))
}
&mut self,
attrs: AttrVec,
span: Span,
- init: Option<P<hir::Expr>>,
- pat: P<hir::Pat>,
+ init: Option<P<hir::Expr<'hir>>>,
+ pat: P<hir::Pat<'hir>>,
source: hir::LocalSource,
- ) -> hir::Stmt {
+ ) -> hir::Stmt<'hir> {
let local = hir::Local { attrs, hir_id: self.next_id(), init, pat, source, span, ty: None };
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))
}
fn block_all(
&mut self,
span: Span,
- stmts: hir::HirVec<hir::Stmt>,
- expr: Option<P<hir::Expr>>,
- ) -> hir::Block {
+ stmts: hir::HirVec<hir::Stmt<'hir>>,
+ expr: Option<P<hir::Expr<'hir>>>,
+ ) -> hir::Block<'hir> {
hir::Block {
stmts,
expr,
}
/// 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);
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])
}
- 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])
}
- 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])
}
- 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![])
}
&mut self,
span: Span,
components: &[Symbol],
- subpats: hir::HirVec<P<hir::Pat>>,
- ) -> P<hir::Pat> {
+ subpats: hir::HirVec<P<hir::Pat<'hir>>>,
+ ) -> P<hir::Pat<'hir>> {
let path = self.std_path(span, components, None, true);
let qpath = hir::QPath::Resolved(None, P(path));
let pt = if subpats.is_empty() {
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)
}
span: Span,
ident: Ident,
bm: hir::BindingAnnotation,
- ) -> (P<hir::Pat>, hir::HirId) {
+ ) -> (P<hir::Pat<'hir>>, hir::HirId) {
let hir_id = self.next_id();
(
)
}
- 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)
}
- 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 })
}
use rustc_error_codes::*;
-impl LoweringContext<'_, '_> {
- fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr> {
+impl<'hir> LoweringContext<'_, 'hir> {
+ fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> HirVec<hir::Expr<'hir>> {
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 {
ExprKind::Box(ref inner) => hir::ExprKind::Box(P(self.lower_expr(inner))),
ExprKind::Array(ref exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
/// ```rust
/// 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 self.sess.opts.unstable_features.is_nightly_build() {
cond: &Expr,
then: &Block,
else_opt: Option<&Expr>,
- ) -> hir::ExprKind {
+ ) -> hir::ExprKind<'hir> {
// FIXME(#53667): handle lowering of && and parens.
// `_ => else_block` where `else_block` is `{}` if there's `None`:
cond: &Expr,
body: &Block,
opt_label: Option<Label>,
- ) -> hir::ExprKind {
+ ) -> hir::ExprKind<'hir> {
// FIXME(#53667): handle lowering of && and parens.
// Note that the block AND the condition are evaluated in the loop scope.
/// Desugar `try { <stmts>; <expr> }` into `{ <stmts>; ::std::ops::Try::from_ok(<expr>) }`,
/// `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.
- 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| {
let mut block = this.lower_block(body, true).into_inner();
// Final expression of the block (if present) or `()` with span at the end of block
let tail_expr = block.expr.take().map_or_else(
|| 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 =
&mut self,
method: Symbol,
method_span: Span,
- expr: hir::Expr,
+ expr: hir::Expr<'hir>,
overall_span: Span,
- ) -> P<hir::Expr> {
+ ) -> P<hir::Expr<'hir>> {
let path = &[sym::ops, sym::Try, method];
let constructor = P(self.expr_std_path(method_span, path, None, ThinVec::new()));
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_id: self.next_id(),
attrs: self.lower_attrs(&arm.attrs),
ret_ty: Option<AstP<Ty>>,
span: Span,
async_gen_kind: hir::AsyncGeneratorKind,
- body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr,
- ) -> hir::ExprKind {
+ body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
+ ) -> hir::ExprKind<'hir> {
let output = match ret_ty {
Some(ty) => FunctionRetTy::Ty(ty),
None => FunctionRetTy::Default(span),
/// }
/// }
/// ```
- 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 {
Some(hir::GeneratorKind::Async(_)) => {}
Some(hir::GeneratorKind::Gen) | None => {
decl: &FnDecl,
body: &Expr,
fn_decl_span: Span,
- ) -> hir::ExprKind {
+ ) -> hir::ExprKind<'hir> {
// Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = self.lower_fn_decl(decl, None, false, None);
decl: &FnDecl,
body: &Expr,
fn_decl_span: Span,
- ) -> hir::ExprKind {
+ ) -> hir::ExprKind<'hir> {
let outer_decl =
FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span) };
// We need to lower the declaration outside the new scope, because we
}
/// 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 e1 = self.lower_expr(e1);
let e2 = self.lower_expr(e2);
e1: Option<&Expr>,
e2: Option<&Expr>,
lims: RangeLimits,
- ) -> hir::ExprKind {
+ ) -> hir::ExprKind<'hir> {
use syntax::ast::RangeLimits::*;
let path = match (e1, e2, lims) {
let ident = Ident::new(Symbol::intern(s), e.span);
self.field(ident, expr, e.span)
})
- .collect::<P<[hir::Field]>>();
+ .collect::<P<[hir::Field<'hir>]>>();
let is_unit = fields.is_empty();
let struct_path = [sym::ops, path];
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 {
inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
outputs: 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_id: self.next_id(),
ident: f.ident,
}
}
- 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 {
Some(hir::GeneratorKind::Gen) => {}
Some(hir::GeneratorKind::Async(_)) => {
head: &Expr,
body: &Block,
opt_label: Option<Label>,
- ) -> hir::Expr {
+ ) -> hir::Expr<'hir> {
// expand <head>
let mut head = self.lower_expr(head);
let desugared_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
/// 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(
DesugaringKind::QuestionMark,
span,
// =========================================================================
/// 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) };
self.expr(span, hir::ExprKind::Lit(lit), ThinVec::new())
}
pub(super) fn expr_drop_temps(
&mut self,
span: Span,
- expr: P<hir::Expr>,
+ expr: P<hir::Expr<'hir>>,
attrs: AttrVec,
- ) -> hir::Expr {
+ ) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::DropTemps(expr), attrs)
}
fn expr_match(
&mut self,
span: Span,
- arg: P<hir::Expr>,
- arms: hir::HirVec<hir::Arm>,
+ arg: P<hir::Expr<'hir>>,
+ arms: hir::HirVec<hir::Arm<'hir>>,
source: hir::MatchSource,
- ) -> hir::Expr {
+ ) -> hir::Expr<'hir> {
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);
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(
span,
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e),
)
}
- 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![])
}
- 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())
}
fn expr_call(
&mut self,
span: Span,
- e: P<hir::Expr>,
- args: hir::HirVec<hir::Expr>,
- ) -> hir::Expr {
+ e: P<hir::Expr<'hir>>,
+ args: hir::HirVec<hir::Expr<'hir>>,
+ ) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::Call(e, args), ThinVec::new())
}
&mut self,
span: Span,
path_components: &[Symbol],
- args: hir::HirVec<hir::Expr>,
- ) -> hir::Expr {
+ args: hir::HirVec<hir::Expr<'hir>>,
+ ) -> hir::Expr<'hir> {
let path = P(self.expr_std_path(span, path_components, None, ThinVec::new()));
self.expr_call(span, path, args)
}
span: Span,
ty_path_components: &[Symbol],
assoc_fn_name: &str,
- args: hir::HirVec<hir::Expr>,
- ) -> hir::ExprKind {
+ args: hir::HirVec<hir::Expr<'hir>>,
+ ) -> hir::ExprKind<'hir> {
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 fn_seg = P(hir::PathSegment::from_ident(Ident::from_str(assoc_fn_name)));
components: &[Symbol],
params: Option<P<hir::GenericArgs>>,
attrs: AttrVec,
- ) -> hir::Expr {
+ ) -> hir::Expr<'hir> {
let path = self.std_path(span, components, params, true);
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())
}
ident: Ident,
binding: hir::HirId,
attrs: AttrVec,
- ) -> hir::Expr {
+ ) -> hir::Expr<'hir> {
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
None,
P(hir::Path {
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 span = expr.span;
self.expr(
)
}
- 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);
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)
}
- 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 }
}
- 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 }
}
- 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_id: self.next_id(),
attrs: hir_vec![],
}
/// 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())
}
}
}
- 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 id = body.id();
self.bodies.insert(id, body);
fn lower_body(
&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 {
let prev_gen_kind = self.generator_kind.take();
let (parameters, result) = f(self);
body_id
}
- fn lower_param(&mut self, param: &Param) -> hir::Param {
+ fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
hir::Param {
attrs: self.lower_attrs(¶m.attrs),
hir_id: self.lower_node_id(param.id),
pub(super) fn lower_fn_body(
&mut self,
decl: &FnDecl,
- body: impl FnOnce(&mut LoweringContext<'_, '_>) -> hir::Expr,
+ body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
) -> hir::BodyId {
self.lower_body(|this| {
(
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 {
Some(block) => self.lower_block_expr(block),
None => self.expr_err(span),
};
self.lower_body(|this| {
- let mut parameters: Vec<hir::Param> = Vec::new();
- let mut statements: Vec<hir::Stmt> = Vec::new();
+ let mut parameters: Vec<hir::Param<'hir>> = Vec::new();
+ let mut statements: Vec<hir::Stmt<'hir>> = Vec::new();
// 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.
}
}
-impl MaybeFnLike for ast::Expr {
+impl MaybeFnLike for ast::Expr<'_> {
fn is_fn_like(&self) -> bool {
match self.kind {
ast::ExprKind::Closure(..) => true,
#[derive(Copy, Clone)]
pub enum Code<'a> {
FnLike(FnLikeNode<'a>),
- Expr(&'a Expr),
+ Expr(&'a Expr<'a>),
}
impl<'a> Code<'a> {
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);
self.insert(param.pat.span, param.hir_id, node);
self.with_parent(param.hir_id, |this| {
});
}
- fn visit_pat(&mut self, pat: &'hir Pat) {
+ fn visit_pat(&mut self, pat: &'hir Pat<'hir>) {
let node =
if let PatKind::Binding(..) = pat.kind { Node::Binding(pat) } else { Node::Pat(pat) };
self.insert(pat.span, pat.hir_id, node);
});
}
- fn visit_arm(&mut self, arm: &'hir Arm) {
+ fn visit_arm(&mut self, arm: &'hir Arm<'hir>) {
let node = Node::Arm(arm);
self.insert(arm.span, arm.hir_id, node);
});
}
- 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.with_parent(expr.hir_id, |this| {
});
}
- 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.with_parent(stmt.hir_id, |this| {
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.with_parent(block.hir_id, |this| {
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.with_parent(l.hir_id, |this| intravisit::walk_local(this, l))
}
///
/// Used by error reporting when there's a type error in a match arm caused by the `match`
/// 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) {
match node {
Node::Item(_) | Node::ForeignItem(_) | Node::TraitItem(_) | Node::ImplItem(_) => {
}
}
- pub fn expect_expr(&self, id: HirId) -> &'hir Expr {
+ pub fn expect_expr(&self, id: HirId) -> &'hir Expr<'hir> {
match self.find(id) {
// read recorded by find
Some(Node::Expr(expr)) => expr,
/// `targeted_by_break` field will be `true`) and may be `unsafe` by means of
/// the `rules` being anything but `DefaultBlock`.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct Block {
+pub struct Block<'hir> {
/// Statements in a block.
- pub stmts: HirVec<Stmt>,
+ pub stmts: &'hir [Stmt<'hir>],
/// An expression at the end of the block
/// without a semicolon, if any.
- pub expr: Option<P<Expr>>,
+ pub expr: Option<&'hir Expr<'hir>>,
#[stable_hasher(ignore)]
pub hir_id: HirId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
}
#[derive(RustcEncodable, RustcDecodable, HashStable)]
-pub struct Pat {
+pub struct Pat<'hir> {
#[stable_hasher(ignore)]
pub hir_id: HirId,
- pub kind: PatKind,
+ pub kind: PatKind<'hir>,
pub span: Span,
}
-impl fmt::Debug for Pat {
+impl fmt::Debug for Pat<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
}
}
-impl Pat {
+impl Pat<'_> {
// 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) {
return false;
}
/// Note that when visiting e.g. `Tuple(ps)`,
/// if visiting `ps[0]` returns `false`,
/// 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)
}
// 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) {
return;
}
/// Walk the pattern in left-to-right order.
///
/// 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)
}
/// Walk the pattern in left-to-right order.
///
/// 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| {
it(p);
true
/// are treated the same as` x: x, y: ref y, z: ref mut z`,
/// except `is_shorthand` is true.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct FieldPat {
+pub struct FieldPat<'hir> {
#[stable_hasher(ignore)]
pub hir_id: HirId,
/// The identifier for the field.
#[stable_hasher(project(name))]
pub ident: Ident,
/// The pattern the field is destructured to.
- pub pat: P<Pat>,
+ pub pat: &'hir Pat<'hir>,
pub is_shorthand: bool,
pub span: Span,
}
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub enum PatKind {
+pub enum PatKind<'hir> {
/// Represents a wildcard pattern (i.e., `_`).
Wild,
/// 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),
/// 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, ..}`).
/// 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)`.
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `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`.
/// 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.
Path(QPath),
/// A tuple pattern (e.g., `(a, b)`).
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
/// `0 <= position <= subpats.len()`
- Tuple(HirVec<P<Pat>>, Option<usize>),
+ Tuple(&'hir [&'hir Pat<'hir>], Option<usize>),
/// A `box` pattern.
- Box(P<Pat>),
+ Box(&'hir Pat<'hir>),
/// A reference pattern (e.g., `&mut (a, b)`).
- Ref(P<Pat>, Mutability),
+ Ref(&'hir Pat<'hir>, Mutability),
/// A literal.
- Lit(P<Expr>),
+ Lit(&'hir Expr<'hir>),
/// 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)?]`.
///
/// ```
/// 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)]
/// A statement.
#[derive(RustcEncodable, RustcDecodable, HashStable)]
-pub struct Stmt {
+pub struct Stmt<'hir> {
pub hir_id: HirId,
- pub kind: StmtKind,
+ pub kind: StmtKind<'hir>,
pub span: Span,
}
-impl fmt::Debug for Stmt {
+impl fmt::Debug for Stmt<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
/// The contents of a statement.
#[derive(RustcEncodable, RustcDecodable, HashStable)]
-pub enum StmtKind {
+pub enum StmtKind<'hir> {
/// A local (`let`) binding.
- Local(P<Local>),
+ Local(&'hir Local<'hir>),
/// An item binding.
Item(ItemId),
/// 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).
- Semi(P<Expr>),
+ Semi(&'hir Expr<'hir>),
}
-impl StmtKind {
- pub fn attrs(&self) -> &[Attribute] {
+impl StmtKind<'hir> {
+ pub fn attrs(&self) -> &'hir [Attribute] {
match *self {
StmtKind::Local(ref l) => &l.attrs,
StmtKind::Item(_) => &[],
/// Represents a `let` statement (i.e., `let <pat>:<ty> = <expr>;`).
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct Local {
- pub pat: P<Pat>,
+pub struct Local<'hir> {
+ pub pat: &'hir Pat<'hir>,
/// 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.
- pub init: Option<P<Expr>>,
+ pub init: Option<&'hir Expr<'hir>>,
pub hir_id: HirId,
pub span: Span,
pub attrs: AttrVec,
/// Represents a single arm of a `match` expression, e.g.
/// `<pat> (if <guard>) => <body>`.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct Arm {
+pub struct Arm<'hir> {
#[stable_hasher(ignore)]
pub hir_id: HirId,
pub span: Span,
- pub attrs: HirVec<Attribute>,
+ pub attrs: &'hir [Attribute],
/// If this pattern and the optional guard matches, then `body` is evaluated.
- pub pat: P<Pat>,
+ pub pat: &'hir Pat<'hir>,
/// Optional guard clause.
- pub guard: Option<Guard>,
+ pub guard: Option<Guard<'hir>>,
/// The expression the arm evaluates to if this arm matches.
- pub body: P<Expr>,
+ pub body: &'hir Expr<'hir>,
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub enum Guard {
- If(P<Expr>),
+pub enum Guard<'hir> {
+ If(&'hir Expr<'hir>),
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct Field {
+pub struct Field<'hir> {
#[stable_hasher(ignore)]
pub hir_id: HirId,
pub ident: Ident,
- pub expr: P<Expr>,
+ pub expr: &'hir Expr<'hir>,
pub span: Span,
pub is_shorthand: bool,
}
/// map using `body_owner_def_id()`.
#[derive(RustcEncodable, RustcDecodable, Debug)]
pub struct Body<'hir> {
- pub params: &'hir [Param],
- pub value: Expr,
+ pub params: &'hir [Param<'hir>],
+ pub value: Expr<'hir>,
pub generator_kind: Option<GeneratorKind>,
}
/// An expression.
#[derive(RustcEncodable, RustcDecodable)]
-pub struct Expr {
+pub struct Expr<'hir> {
pub hir_id: HirId,
- pub kind: ExprKind,
+ pub kind: ExprKind<'hir>,
pub attrs: AttrVec,
pub span: Span,
}
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[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 {
match self.kind {
ExprKind::Box(_) => ExprPrecedence::Box,
}
}
-impl fmt::Debug for Expr {
+impl fmt::Debug for Expr<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
///
/// 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`.
-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,
// either in std or core, i.e. has either a `::std::ops::Range` or
// `::core::ops::Range` prefix.
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub enum ExprKind {
+pub enum ExprKind<'hir> {
/// A `box x` expression.
- Box(P<Expr>),
+ Box(&'hir Expr<'hir>),
/// An array (e.g., `[a, b, c, d]`).
- Array(HirVec<Expr>),
+ Array(&'hir [Expr<'hir>]),
/// A function call.
///
/// The first field resolves to the function itself (usually an `ExprKind::Path`),
/// and the second field is the list of arguments.
/// This also represents calling the constructor of
/// 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)`).
///
/// The `PathSegment`/`Span` represent the method name and its generic arguments
/// the `hir_id` of the `MethodCall` node itself.
///
/// [`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)`).
- Tup(HirVec<Expr>),
+ Tup(&'hir [Expr<'hir>]),
/// 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`).
- Unary(UnOp, P<Expr>),
+ Unary(UnOp, &'hir Expr<'hir>),
/// A literal (e.g., `1`, `"foo"`).
Lit(Lit),
/// A cast (e.g., `foo as f64`).
- Cast(P<Expr>, P<Ty>),
+ Cast(&'hir Expr<'hir>, &'hir Ty),
/// A type reference (e.g., `Foo`).
- Type(P<Expr>, P<Ty>),
+ Type(&'hir Expr<'hir>, &'hir Ty),
/// Wraps the expression in a terminating scope.
/// This makes it semantically equivalent to `{ let _t = expr; _t }`.
///
/// This construct only exists to tweak the drop order in HIR lowering.
/// 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`).
///
/// 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
/// 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}`).
///
/// The `Span` is the argument block `|...|`.
///
/// This may also be a generator literal or an `async block` as indicated by the
/// `Option<Movability>`.
- Closure(CaptureBy, P<FnDecl>, BodyId, Span, Option<Movability>),
+ Closure(CaptureBy, &'hir FnDecl, BodyId, Span, Option<Movability>),
/// A block (e.g., `'label: { ... }`).
- Block(P<Block>, Option<Label>),
+ Block(&'hir Block<'hir>, Option<Label>),
/// An assignment (e.g., `a = foo()`).
- /// The `Span` argument is the span of the `=` token.
- Assign(P<Expr>, P<Expr>, Span),
+ Assign(&'hir Expr<'hir>, &'hir Expr<'hir>, Span),
/// An assignment with an operator.
///
/// 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.
- Field(P<Expr>, Ident),
+ Field(&'hir Expr<'hir>, Ident),
/// 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(QPath),
- /// A referencing operation (i.e., `&a`, `&mut a`, `&raw const a`, or `&raw mut a`).
- AddrOf(BorrowKind, Mutability, P<Expr>),
+ /// A referencing operation (i.e., `&a` or `&mut a`).
+ AddrOf(BorrowKind, &'hir Expr<'hir>),
/// 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.
Continue(Destination),
/// 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.
- InlineAsm(P<InlineAsm>),
+ InlineAsm(&'hir InlineAsm<'hir>),
/// A struct or struct-like variant literal expression.
///
/// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. base}`,
/// 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.
///
/// E.g., `[1; 5]`. The first expression is the element
/// 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>`).
- Yield(P<Expr>, YieldSource),
+ Yield(&'hir Expr<'hir>, YieldSource),
/// A placeholder for an expression that wasn't syntactically well formed in some way.
Err,
}
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct InlineAsm {
+pub struct InlineAsm<'hir> {
pub inner: InlineAsmInner,
- pub outputs_exprs: HirVec<Expr>,
- pub inputs_exprs: HirVec<Expr>,
+ pub outputs_exprs: &'hir [Expr<'hir>],
+ pub inputs_exprs: &'hir [Expr<'hir>],
}
/// Represents a parameter in a function header.
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
-pub struct Param {
- pub attrs: HirVec<Attribute>,
+pub struct Param<'hir> {
+ pub attrs: &'hir [Attribute],
pub hir_id: HirId,
- pub pat: P<Pat>,
+ pub pat: &'hir Pat<'hir>,
pub span: Span,
}
#[derive(Copy, Clone, Debug)]
pub enum Node<'hir> {
- Param(&'hir Param),
+ Param(&'hir Param<'hir>),
Item(&'hir Item<'hir>),
ForeignItem(&'hir ForeignItem<'hir>),
TraitItem(&'hir TraitItem<'hir>),
Variant(&'hir Variant<'hir>),
Field(&'hir StructField<'hir>),
AnonConst(&'hir AnonConst),
- Expr(&'hir Expr),
- Stmt(&'hir Stmt),
+ Expr(&'hir Expr<'hir>),
+ Stmt(&'hir Stmt<'hir>),
PathSegment(&'hir PathSegment),
Ty(&'hir Ty),
TraitRef(&'hir TraitRef),
- Binding(&'hir Pat),
- Pat(&'hir Pat),
- Arm(&'hir Arm),
- Block(&'hir Block),
- Local(&'hir Local),
+ Binding(&'hir Pat<'hir>),
+ Pat(&'hir Pat<'hir>),
+ Arm(&'hir Arm<'hir>),
+ Block(&'hir Block<'hir>),
+ Local(&'hir Local<'hir>),
MacroDef(&'hir MacroDef<'hir>),
/// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants
}
}
-impl hir::Pat {
+impl hir::Pat<'_> {
pub fn is_refutable(&self) -> bool {
match self.kind {
PatKind::Lit(_)
pub enum AnnNode<'a> {
Name(&'a ast::Name),
- Block(&'a hir::Block),
+ Block(&'a hir::Block<'a>),
Item(&'a hir::Item<'a>),
SubItem(hir::HirId),
- Expr(&'a hir::Expr),
- Pat(&'a hir::Pat),
- Arm(&'a hir::Arm),
+ Expr(&'a hir::Expr<'a>),
+ Pat(&'a hir::Pat<'a>),
+ Arm(&'a hir::Arm<'a>),
}
pub enum Nested {
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.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.ibox(INDENT_UNIT);
self.word_nbsp("let");
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());
match st.kind {
hir::StmtKind::Local(ref loc) => {
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, &[])
}
- 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)
}
- 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)
}
pub fn print_block_maybe_unclosed(
&mut self,
- blk: &hir::Block,
+ blk: &hir::Block<'_>,
attrs: &[ast::Attribute],
close_box: bool,
) {
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.commasep_exprs(Inconsistent, args);
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;
if needs_par {
self.popen();
/// Print an expr using syntax that's acceptable in a condition position, such as the `cond` in
/// `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 {
// These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
}
}
- fn print_expr_vec(&mut self, exprs: &[hir::Expr]) {
+ fn print_expr_vec(&mut self, exprs: &[hir::Expr<'_>]) {
self.ibox(INDENT_UNIT);
self.s.word("[");
self.commasep_exprs(Inconsistent, exprs);
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.s.word("[");
self.print_expr(element);
fn print_expr_struct(
&mut self,
qpath: &hir::QPath,
- fields: &[hir::Field],
- wth: &Option<P<hir::Expr>>,
+ fields: &[hir::Field<'_>],
+ wth: &Option<P<hir::Expr<'_>>>,
) {
self.print_qpath(qpath, true);
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.commasep_exprs(Inconsistent, exprs);
if exprs.len() == 1 {
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 {
hir::ExprKind::Field(..) => parser::PREC_FORCE_PAREN,
_ => parser::PREC_POSTFIX,
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..];
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX);
self.s.word(".");
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 prec = assoc_op.precedence() as i8;
let fixity = assoc_op.fixity();
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.print_expr_maybe_paren(expr, parser::PREC_PREFIX)
}
&mut self,
kind: hir::BorrowKind,
mutability: hir::Mutability,
- expr: &hir::Expr,
+ expr: &hir::Expr<'_>,
) {
self.s.word("&");
match kind {
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.print_outer_attributes(&expr.attrs);
self.ibox(INDENT_UNIT);
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);
if let Some(ref ty) = loc.ty {
self.word_space(":");
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.s.space();
self.word_space("in");
}
}
- 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.ann.pre(self, AnnNode::Pat(pat));
// Pat isn't normalized, but the beauty of it
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_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
// is :(
if arm.attrs.is_empty() {
/// isn't parsed as (if true {...} else {...} | x) | 5
//
// 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 {
hir::ExprKind::Match(..) | hir::ExprKind::Block(..) | hir::ExprKind::Loop(..) => false,
_ => true,
/// This statement requires a semicolon after it.
/// note that in one case (stmt_semi), we've already
/// 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 {
hir::StmtKind::Local(_) => true,
hir::StmtKind::Item(_) => false,
/// 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
/// `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 {
hir::ExprKind::Struct(..) => true,
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 {
self.locals.insert(hir_id);
}
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 {
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
if let Some(upvars) = self.tcx.upvars(closure_def_id) {
}
}
-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) {
hcx.while_hashing_hir_bodies(true, |hcx| {
let hir::Expr { hir_id: _, ref span, ref kind, ref attrs } = *self;
infcx: &'a InferCtxt<'a, 'tcx>,
target_ty: Ty<'tcx>,
hir_map: &'a hir::map::Map<'tcx>,
- found_local_pattern: Option<&'tcx Pat>,
- found_arg_pattern: Option<&'tcx Pat>,
+ found_local_pattern: Option<&'tcx Pat<'tcx>>,
+ found_arg_pattern: Option<&'tcx Pat<'tcx>>,
found_ty: Option<Ty<'tcx>>,
- found_closure: Option<&'tcx ExprKind>,
- found_method_call: Option<&'tcx Expr>,
+ found_closure: Option<&'tcx ExprKind<'tcx>>,
+ found_method_call: Option<&'tcx Expr<'tcx>>,
}
impl<'a, 'tcx> FindLocalByTypeVisitor<'a, 'tcx> {
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)) {
self.found_local_pattern = Some(&*local.pat);
self.found_ty = Some(ty);
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() {
match expr.kind {
ExprKind::Closure(..) => self.found_closure = Some(&expr.kind),
fn annotate_method_call(
&self,
segment: &hir::ptr::P<hir::PathSegment>,
- e: &Expr,
+ e: &Expr<'_>,
err: &mut DiagnosticBuilder<'_>,
) {
if let (Ok(snippet), Some(tables), None) = (
#[derive(Debug)]
pub(super) struct AnonymousParamInfo<'tcx> {
// 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
pub param_ty: Ty<'tcx>,
// the ty::BoundRegion corresponding to the anonymous region
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, ¶m.attrs, |cx| {
lint_callback!(cx, check_param, param);
hir_visit::walk_param(cx, param);
})
}
- 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);
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| {
lint_callback!(cx, check_expr, e);
hir_visit::walk_expr(cx, e);
})
}
- 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
// - item
// - local
}
}
- 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| {
lint_callback!(cx, check_local, 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);
hir_visit::walk_block(self, 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);
hir_visit::walk_arm(self, a);
}
macro_rules! late_lint_methods {
($macro:path, $args:tt, [$hir:tt]) => (
$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_post(a: &$hir hir::Body<$hir>);
fn check_name(a: Span, b: ast::Name);
fn check_foreign_item_post(a: &$hir hir::ForeignItem<$hir>);
fn check_item(a: &$hir hir::Item<$hir>);
fn check_item_post(a: &$hir hir::Item<$hir>);
- fn check_local(a: &$hir hir::Local);
- fn check_block(a: &$hir hir::Block);
- fn check_block_post(a: &$hir hir::Block);
- fn check_stmt(a: &$hir hir::Stmt);
- fn check_arm(a: &$hir hir::Arm);
- fn check_pat(a: &$hir hir::Pat);
- fn check_expr(a: &$hir hir::Expr);
- fn check_expr_post(a: &$hir hir::Expr);
+ fn check_local(a: &$hir hir::Local<$hir>);
+ fn check_block(a: &$hir hir::Block<$hir>);
+ fn check_block_post(a: &$hir hir::Block<$hir>);
+ fn check_stmt(a: &$hir hir::Stmt<$hir>);
+ fn check_arm(a: &$hir hir::Arm<$hir>);
+ fn check_pat(a: &$hir hir::Pat<$hir>);
+ fn check_expr(a: &$hir hir::Expr<$hir>);
+ fn check_expr_post(a: &$hir hir::Expr<$hir>);
fn check_ty(a: &$hir hir::Ty);
fn check_generic_param(a: &$hir hir::GenericParam);
fn check_generics(a: &$hir hir::Generics);
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, ¶m.attrs, |builder| {
intravisit::walk_param(builder, param);
});
})
}
- 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| {
intravisit::walk_expr(builder, e);
})
})
}
- 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| {
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| {
intravisit::walk_arm(builder, a);
})
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 {
hir::ExprKind::Path(ref qpath) => Some(self.tables.qpath_res(qpath, expr.hir_id)),
hir::ExprKind::MethodCall(..) => self
NestedVisitorMap::None
}
- fn visit_pat(&mut self, pat: &'tcx Pat) {
+ fn visit_pat(&mut self, pat: &'tcx Pat<'tcx>) {
intravisit::walk_pat(self, pat);
self.expr_and_pat_count += 1;
}
}
- 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);
intravisit::walk_expr(self, expr);
}
}
-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);
let prev_cx = visitor.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;
visitor.enter_scope(Scope { id: arm.hir_id.local_id, data: ScopeData::Node });
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 });
// If this is a binding then record the lifetime of that binding.
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;
debug!("resolve_stmt(stmt.id={:?})", stmt_id);
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);
let prev_cx = visitor.cx;
fn resolve_local<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>,
- pat: Option<&'tcx hir::Pat>,
- init: Option<&'tcx hir::Expr>,
+ pat: Option<&'tcx hir::Pat<'tcx>>,
+ init: Option<&'tcx hir::Expr<'tcx>>,
) {
debug!("resolve_local(pat={:?}, init={:?})", pat, init);
/// | ( ..., P&, ... )
/// | ... "|" 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
// know about *implicit* refs as introduced in #42640.
//
/// | ( E& )
fn record_rvalue_scope_if_borrow_expr<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>,
- expr: &hir::Expr,
+ expr: &hir::Expr<'_>,
blk_id: Option<Scope>,
) {
match expr.kind {
/// Note: ET is intended to match "rvalues or places based on rvalues".
fn record_rvalue_scope<'tcx>(
visitor: &mut RegionResolutionVisitor<'tcx>,
- expr: &hir::Expr,
+ expr: &hir::Expr<'_>,
blk_scope: Option<Scope>,
) {
let mut expr = expr;
NestedVisitorMap::None
}
- fn visit_block(&mut self, b: &'tcx Block) {
+ fn visit_block(&mut self, b: &'tcx Block<'tcx>) {
resolve_block(self, b);
}
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);
}
- fn visit_pat(&mut self, p: &'tcx Pat) {
+ fn visit_pat(&mut self, p: &'tcx Pat<'tcx>) {
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);
}
- fn visit_expr(&mut self, ex: &'tcx Expr) {
+ fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
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));
}
}
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) {
for prior_label in &self.labels_in_fn[..] {
// FIXME (#24278): non-hygienic comparison
}
}
- 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 }
}
err: &mut DiagnosticBuilder<'_>,
msg: &str,
) -> Option<String> {
- let get_name = |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind| -> Option<String> {
- // Get the local name of this closure. This can be inaccurate because
- // of the possibility of reassignment, but this should be good enough.
- match &kind {
- hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
- Some(format!("{}", name))
- }
- _ => {
- err.note(&msg);
- None
+ let get_name =
+ |err: &mut DiagnosticBuilder<'_>, kind: &hir::PatKind<'_>| -> Option<String> {
+ // Get the local name of this closure. This can be inaccurate because
+ // of the possibility of reassignment, but this should be good enough.
+ match &kind {
+ hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
+ Some(format!("{}", name))
+ }
+ _ => {
+ err.note(&msg);
+ None
+ }
}
- }
- };
+ };
let hir = self.tcx.hir();
let hir_id = hir.as_local_hir_id(def_id)?;
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
// 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)
}
- 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)
}
// 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"
// 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)
}
- 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)
}
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);
self.adjustments.get(&expr.hir_id.local_id).map_or(&[], |a| &a[..])
}
/// Returns the type of `expr`, considering any `Adjustment`
/// 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)
}
- 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))
}
- 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
// entries in type_dependent_defs, ignore the former here.
if let hir::ExprKind::Path(_) = expr.kind {
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 {
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);
let place = return_if_err!(self.mc.cat_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));
self.delegate.mutate(&place);
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);
let place = return_if_err!(self.mc.cat_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)
}
- pub fn walk_expr(&mut self, expr: &hir::Expr) {
+ pub fn walk_expr(&mut self, expr: &hir::Expr<'_>) {
debug!("walk_expr(expr={:?})", expr);
self.walk_adjustment(expr);
}
}
- 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));
debug!("walk_callee: callee={:?} callee_ty={:?}", callee, callee_ty);
match callee_ty.kind {
}
}
- fn walk_stmt(&mut self, stmt: &hir::Stmt) {
+ fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) {
match stmt.kind {
hir::StmtKind::Local(ref local) => {
self.walk_local(&local);
}
}
- fn walk_local(&mut self, local: &hir::Local) {
+ fn walk_local(&mut self, local: &hir::Local<'_>) {
if let Some(ref expr) = local.init {
// Variable declarations with
// initializers are considered
/// Indicates that the value of `blk` will be consumed, meaning either copied or moved
/// 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);
for stmt in &blk.stmts {
}
}
- 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.
for field in fields {
self.consume_expr(&field.expr);
// Invoke the appropriate delegate calls for anything that gets
// consumed or borrowed as part of the automatic adjustment
// 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 mut place = return_if_err!(self.mc.cat_expr_unadjusted(expr));
for adjustment in adjustments {
/// after all relevant autoderefs have occurred.
fn walk_autoref(
&mut self,
- expr: &hir::Expr,
+ expr: &hir::Expr<'_>,
base_place: &mc::Place<'tcx>,
autoref: &adjustment::AutoBorrow<'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);
if let Some(hir::Guard::If(ref e)) = arm.guard {
/// 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.)
- 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);
}
/// 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);
let tcx = self.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);
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);