rustc: dismantle hir::util, mostly moving functions to methods.

This commit is contained in:
Eduard Burtescu 2016-03-29 09:32:58 +03:00
parent 8b0937293b
commit ef4c7241f8
27 changed files with 393 additions and 426 deletions

View File

@ -257,7 +257,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
self.match_(expr.id, &discr, &arms, pred)
}
hir::ExprBinary(op, ref l, ref r) if hir::util::lazy_binop(op.node) => {
hir::ExprBinary(op, ref l, ref r) if op.node.is_lazy() => {
//
// [pred]
// |

View File

@ -27,6 +27,7 @@
use syntax::abi::Abi;
use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
use syntax::ast_util;
use syntax::attr::ThinAttributesExt;
use syntax::codemap::Span;
use hir::*;
@ -835,3 +836,185 @@ pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
visitor.visit_expr(&arm.body);
walk_list!(visitor, visit_attribute, &arm.attrs);
}
pub struct IdVisitor<'a, O: 'a> {
operation: &'a mut O,
// In general, the id visitor visits the contents of an item, but
// not including nested trait/impl items, nor other nested items.
// The base visitor itself always skips nested items, but not
// trait/impl items. This means in particular that if you start by
// visiting a trait or an impl, you should not visit the
// trait/impl items respectively. This is handled by setting
// `skip_members` to true when `visit_item` is on the stack. This
// way, if the user begins by calling `visit_trait_item`, we will
// visit the trait item, but if they begin with `visit_item`, we
// won't visit the (nested) trait items.
skip_members: bool,
}
impl<'a, O: ast_util::IdVisitingOperation> IdVisitor<'a, O> {
pub fn new(operation: &'a mut O) -> IdVisitor<'a, O> {
IdVisitor { operation: operation, skip_members: false }
}
fn visit_generics_helper(&mut self, generics: &Generics) {
for type_parameter in generics.ty_params.iter() {
self.operation.visit_id(type_parameter.id)
}
for lifetime in &generics.lifetimes {
self.operation.visit_id(lifetime.lifetime.id)
}
}
}
impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
fn visit_mod(&mut self, module: &Mod, _: Span, node_id: NodeId) {
self.operation.visit_id(node_id);
walk_mod(self, module)
}
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
self.operation.visit_id(foreign_item.id);
walk_foreign_item(self, foreign_item)
}
fn visit_item(&mut self, item: &Item) {
assert!(!self.skip_members);
self.skip_members = true;
self.operation.visit_id(item.id);
match item.node {
ItemUse(ref view_path) => {
match view_path.node {
ViewPathSimple(_, _) |
ViewPathGlob(_) => {}
ViewPathList(_, ref paths) => {
for path in paths {
self.operation.visit_id(path.node.id())
}
}
}
}
_ => {}
}
walk_item(self, item);
self.skip_members = false;
}
fn visit_local(&mut self, local: &Local) {
self.operation.visit_id(local.id);
walk_local(self, local)
}
fn visit_block(&mut self, block: &Block) {
self.operation.visit_id(block.id);
walk_block(self, block)
}
fn visit_stmt(&mut self, statement: &Stmt) {
self.operation.visit_id(statement.node.id());
walk_stmt(self, statement)
}
fn visit_pat(&mut self, pattern: &Pat) {
self.operation.visit_id(pattern.id);
walk_pat(self, pattern)
}
fn visit_expr(&mut self, expression: &Expr) {
self.operation.visit_id(expression.id);
walk_expr(self, expression)
}
fn visit_ty(&mut self, typ: &Ty) {
self.operation.visit_id(typ.id);
walk_ty(self, typ)
}
fn visit_generics(&mut self, generics: &Generics) {
self.visit_generics_helper(generics);
walk_generics(self, generics)
}
fn visit_fn(&mut self,
function_kind: FnKind<'v>,
function_declaration: &'v FnDecl,
block: &'v Block,
span: Span,
node_id: NodeId) {
self.operation.visit_id(node_id);
match function_kind {
FnKind::ItemFn(_, generics, _, _, _, _, _) => {
self.visit_generics_helper(generics)
}
FnKind::Method(_, sig, _, _) => {
self.visit_generics_helper(&sig.generics)
}
FnKind::Closure(_) => {}
}
for argument in &function_declaration.inputs {
self.operation.visit_id(argument.id)
}
walk_fn(self, function_kind, function_declaration, block, span);
}
fn visit_struct_field(&mut self, struct_field: &StructField) {
self.operation.visit_id(struct_field.id);
walk_struct_field(self, struct_field)
}
fn visit_variant_data(&mut self,
struct_def: &VariantData,
_: Name,
_: &Generics,
_: NodeId,
_: Span) {
self.operation.visit_id(struct_def.id());
walk_struct_def(self, struct_def);
}
fn visit_trait_item(&mut self, ti: &TraitItem) {
if !self.skip_members {
self.operation.visit_id(ti.id);
walk_trait_item(self, ti);
}
}
fn visit_impl_item(&mut self, ii: &ImplItem) {
if !self.skip_members {
self.operation.visit_id(ii.id);
walk_impl_item(self, ii);
}
}
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
self.operation.visit_id(lifetime.id);
}
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
self.visit_lifetime(&def.lifetime);
}
fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {
self.operation.visit_id(trait_ref.ref_id);
walk_trait_ref(self, trait_ref);
}
}
/// Computes the id range for a single fn body, ignoring nested items.
pub fn compute_id_range_for_fn_body(fk: FnKind,
decl: &FnDecl,
body: &Block,
sp: Span,
id: NodeId)
-> ast_util::IdRange {
let mut visitor = ast_util::IdRangeComputingVisitor { result: ast_util::IdRange::max() };
let mut id_visitor = IdVisitor::new(&mut visitor);
id_visitor.visit_fn(fk, decl, body, sp, id);
id_visitor.operation.result
}

View File

@ -304,7 +304,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
}
fn visit_stmt(&mut self, stmt: &'ast Stmt) {
let id = util::stmt_id(stmt);
let id = stmt.node.id();
self.insert(id, NodeStmt(stmt));
let parent_node = self.parent_node;
self.parent_node = id;

View File

@ -59,7 +59,7 @@ macro_rules! hir_vec {
($($x:expr),*) => (
$crate::hir::HirVec::from(vec![$($x),*])
);
($($x:expr,)*) => (vec![$($x),*])
($($x:expr,)*) => (hir_vec![$($x),*])
}
pub mod check_attr;
@ -69,7 +69,6 @@ pub mod lowering;
pub mod map;
pub mod print;
pub mod svh;
pub mod util;
/// Identifier in HIR
#[derive(Clone, Copy, Eq)]
@ -176,6 +175,21 @@ impl fmt::Display for Path {
}
}
impl Path {
/// Convert a span and an identifier to the corresponding
/// 1-segment path.
pub fn from_ident(s: Span, ident: Ident) -> Path {
Path {
span: s,
global: false,
segments: hir_vec![PathSegment {
identifier: ident,
parameters: PathParameters::none()
}],
}
}
}
/// A segment of a path: an identifier, an optional lifetime, and a set of
/// types.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@ -349,12 +363,25 @@ pub struct Generics {
}
impl Generics {
pub fn empty() -> Generics {
Generics {
lifetimes: HirVec::new(),
ty_params: HirVec::new(),
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: HirVec::new(),
},
}
}
pub fn is_lt_parameterized(&self) -> bool {
!self.lifetimes.is_empty()
}
pub fn is_type_parameterized(&self) -> bool {
!self.ty_params.is_empty()
}
pub fn is_parameterized(&self) -> bool {
self.is_lt_parameterized() || self.is_type_parameterized()
}
@ -490,6 +517,50 @@ impl fmt::Debug for Pat {
}
}
impl Pat {
// FIXME(#19596) this is a workaround, but there should be a better way
fn walk_<G>(&self, it: &mut G) -> bool
where G: FnMut(&Pat) -> bool
{
if !it(self) {
return false;
}
match self.node {
PatKind::Ident(_, _, Some(ref p)) => p.walk_(it),
PatKind::Struct(_, ref fields, _) => {
fields.iter().all(|field| field.node.pat.walk_(it))
}
PatKind::TupleStruct(_, Some(ref s)) | PatKind::Tup(ref s) => {
s.iter().all(|p| p.walk_(it))
}
PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
s.walk_(it)
}
PatKind::Vec(ref before, ref slice, ref after) => {
before.iter().all(|p| p.walk_(it)) &&
slice.iter().all(|p| p.walk_(it)) &&
after.iter().all(|p| p.walk_(it))
}
PatKind::Wild |
PatKind::Lit(_) |
PatKind::Range(_, _) |
PatKind::Ident(_, _, _) |
PatKind::TupleStruct(..) |
PatKind::Path(..) |
PatKind::QPath(_, _) => {
true
}
}
}
pub fn walk<F>(&self, mut it: F) -> bool
where F: FnMut(&Pat) -> bool
{
self.walk_(&mut it)
}
}
/// A single field in a struct pattern
///
/// Patterns like the fields of Foo `{ x, ref y, ref mut z }`
@ -604,6 +675,68 @@ pub enum BinOp_ {
BiGt,
}
impl BinOp_ {
pub fn as_str(self) -> &'static str {
match self {
BiAdd => "+",
BiSub => "-",
BiMul => "*",
BiDiv => "/",
BiRem => "%",
BiAnd => "&&",
BiOr => "||",
BiBitXor => "^",
BiBitAnd => "&",
BiBitOr => "|",
BiShl => "<<",
BiShr => ">>",
BiEq => "==",
BiLt => "<",
BiLe => "<=",
BiNe => "!=",
BiGe => ">=",
BiGt => ">",
}
}
pub fn is_lazy(self) -> bool {
match self {
BiAnd | BiOr => true,
_ => false,
}
}
pub fn is_shift(self) -> bool {
match self {
BiShl | BiShr => true,
_ => false,
}
}
pub fn is_comparison(self) -> bool {
match self {
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
BiAnd |
BiOr |
BiAdd |
BiSub |
BiMul |
BiDiv |
BiRem |
BiBitXor |
BiBitAnd |
BiBitOr |
BiShl |
BiShr => false,
}
}
/// Returns `true` if the binary operator takes its arguments by value
pub fn is_by_value(self) -> bool {
!self.is_comparison()
}
}
pub type BinOp = Spanned<BinOp_>;
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
@ -616,6 +749,24 @@ pub enum UnOp {
UnNeg,
}
impl UnOp {
pub fn as_str(self) -> &'static str {
match self {
UnDeref => "*",
UnNot => "!",
UnNeg => "-",
}
}
/// Returns `true` if the unary operator takes its argument by value
pub fn is_by_value(self) -> bool {
match self {
UnNeg | UnNot => true,
_ => false,
}
}
}
/// A statement
pub type Stmt = Spanned<Stmt_>;
@ -625,7 +776,7 @@ impl fmt::Debug for Stmt_ {
let spanned = codemap::dummy_spanned(self.clone());
write!(f,
"stmt({}: {})",
util::stmt_id(&spanned),
spanned.node.id(),
print::stmt_to_string(&spanned))
}
}
@ -650,6 +801,14 @@ impl Stmt_ {
StmtSemi(ref e, _) => e.attrs.as_attr_slice(),
}
}
pub fn id(&self) -> NodeId {
match *self {
StmtDecl(_, id) => id,
StmtExpr(_, id) => id,
StmtSemi(_, id) => id,
}
}
}
// FIXME (pending discussion of #1697, #2178...): local should really be

View File

@ -950,7 +950,7 @@ impl<'a> State<'a> {
pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
self.head("")?;
let generics = hir::util::empty_generics();
let generics = hir::Generics::empty();
self.print_struct(&v.node.data, &generics, v.node.name, v.span, false)?;
match v.node.disr_expr {
Some(ref d) => {
@ -1285,12 +1285,12 @@ impl<'a> State<'a> {
-> io::Result<()> {
self.print_expr(lhs)?;
space(&mut self.s)?;
self.word_space(hir::util::binop_to_string(op.node))?;
self.word_space(op.node.as_str())?;
self.print_expr(rhs)
}
fn print_expr_unary(&mut self, op: hir::UnOp, expr: &hir::Expr) -> io::Result<()> {
word(&mut self.s, hir::util::unop_to_string(op))?;
word(&mut self.s, op.as_str())?;
self.print_expr_maybe_paren(expr)
}
@ -1434,7 +1434,7 @@ impl<'a> State<'a> {
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
self.print_expr(&lhs)?;
space(&mut self.s)?;
word(&mut self.s, hir::util::binop_to_string(op.node))?;
word(&mut self.s, op.node.as_str())?;
self.word_space("=")?;
self.print_expr(&rhs)?;
}

View File

@ -1,362 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use hir;
use hir::*;
use hir::intravisit::{Visitor, FnKind};
use syntax::ast_util;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID};
use syntax::codemap::Span;
use syntax::ptr::P;
pub fn walk_pat<F>(pat: &Pat, mut it: F) -> bool
where F: FnMut(&Pat) -> bool
{
// FIXME(#19596) this is a workaround, but there should be a better way
fn walk_pat_<G>(pat: &Pat, it: &mut G) -> bool
where G: FnMut(&Pat) -> bool
{
if !it(pat) {
return false;
}
match pat.node {
PatKind::Ident(_, _, Some(ref p)) => walk_pat_(&p, it),
PatKind::Struct(_, ref fields, _) => {
fields.iter().all(|field| walk_pat_(&field.node.pat, it))
}
PatKind::TupleStruct(_, Some(ref s)) | PatKind::Tup(ref s) => {
s.iter().all(|p| walk_pat_(&p, it))
}
PatKind::Box(ref s) | PatKind::Ref(ref s, _) => {
walk_pat_(&s, it)
}
PatKind::Vec(ref before, ref slice, ref after) => {
before.iter().all(|p| walk_pat_(&p, it)) &&
slice.iter().all(|p| walk_pat_(&p, it)) &&
after.iter().all(|p| walk_pat_(&p, it))
}
PatKind::Wild |
PatKind::Lit(_) |
PatKind::Range(_, _) |
PatKind::Ident(_, _, _) |
PatKind::TupleStruct(..) |
PatKind::Path(..) |
PatKind::QPath(_, _) => {
true
}
}
}
walk_pat_(pat, &mut it)
}
pub fn binop_to_string(op: BinOp_) -> &'static str {
match op {
BiAdd => "+",
BiSub => "-",
BiMul => "*",
BiDiv => "/",
BiRem => "%",
BiAnd => "&&",
BiOr => "||",
BiBitXor => "^",
BiBitAnd => "&",
BiBitOr => "|",
BiShl => "<<",
BiShr => ">>",
BiEq => "==",
BiLt => "<",
BiLe => "<=",
BiNe => "!=",
BiGe => ">=",
BiGt => ">",
}
}
pub fn stmt_id(s: &Stmt) -> NodeId {
match s.node {
StmtDecl(_, id) => id,
StmtExpr(_, id) => id,
StmtSemi(_, id) => id,
}
}
pub fn lazy_binop(b: BinOp_) -> bool {
match b {
BiAnd => true,
BiOr => true,
_ => false,
}
}
pub fn is_shift_binop(b: BinOp_) -> bool {
match b {
BiShl => true,
BiShr => true,
_ => false,
}
}
pub fn is_comparison_binop(b: BinOp_) -> bool {
match b {
BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => true,
BiAnd |
BiOr |
BiAdd |
BiSub |
BiMul |
BiDiv |
BiRem |
BiBitXor |
BiBitAnd |
BiBitOr |
BiShl |
BiShr => false,
}
}
/// Returns `true` if the binary operator takes its arguments by value
pub fn is_by_value_binop(b: BinOp_) -> bool {
!is_comparison_binop(b)
}
/// Returns `true` if the unary operator takes its argument by value
pub fn is_by_value_unop(u: UnOp) -> bool {
match u {
UnNeg | UnNot => true,
_ => false,
}
}
pub fn unop_to_string(op: UnOp) -> &'static str {
match op {
UnDeref => "*",
UnNot => "!",
UnNeg => "-",
}
}
pub struct IdVisitor<'a, O: 'a> {
operation: &'a mut O,
// In general, the id visitor visits the contents of an item, but
// not including nested trait/impl items, nor other nested items.
// The base visitor itself always skips nested items, but not
// trait/impl items. This means in particular that if you start by
// visiting a trait or an impl, you should not visit the
// trait/impl items respectively. This is handled by setting
// `skip_members` to true when `visit_item` is on the stack. This
// way, if the user begins by calling `visit_trait_item`, we will
// visit the trait item, but if they begin with `visit_item`, we
// won't visit the (nested) trait items.
skip_members: bool,
}
impl<'a, O: ast_util::IdVisitingOperation> IdVisitor<'a, O> {
pub fn new(operation: &'a mut O) -> IdVisitor<'a, O> {
IdVisitor { operation: operation, skip_members: false }
}
fn visit_generics_helper(&mut self, generics: &Generics) {
for type_parameter in generics.ty_params.iter() {
self.operation.visit_id(type_parameter.id)
}
for lifetime in &generics.lifetimes {
self.operation.visit_id(lifetime.lifetime.id)
}
}
}
impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
fn visit_mod(&mut self, module: &Mod, _: Span, node_id: NodeId) {
self.operation.visit_id(node_id);
intravisit::walk_mod(self, module)
}
fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) {
self.operation.visit_id(foreign_item.id);
intravisit::walk_foreign_item(self, foreign_item)
}
fn visit_item(&mut self, item: &Item) {
assert!(!self.skip_members);
self.skip_members = true;
self.operation.visit_id(item.id);
match item.node {
ItemUse(ref view_path) => {
match view_path.node {
ViewPathSimple(_, _) |
ViewPathGlob(_) => {}
ViewPathList(_, ref paths) => {
for path in paths {
self.operation.visit_id(path.node.id())
}
}
}
}
_ => {}
}
intravisit::walk_item(self, item);
self.skip_members = false;
}
fn visit_local(&mut self, local: &Local) {
self.operation.visit_id(local.id);
intravisit::walk_local(self, local)
}
fn visit_block(&mut self, block: &Block) {
self.operation.visit_id(block.id);
intravisit::walk_block(self, block)
}
fn visit_stmt(&mut self, statement: &Stmt) {
self.operation.visit_id(stmt_id(statement));
intravisit::walk_stmt(self, statement)
}
fn visit_pat(&mut self, pattern: &Pat) {
self.operation.visit_id(pattern.id);
intravisit::walk_pat(self, pattern)
}
fn visit_expr(&mut self, expression: &Expr) {
self.operation.visit_id(expression.id);
intravisit::walk_expr(self, expression)
}
fn visit_ty(&mut self, typ: &Ty) {
self.operation.visit_id(typ.id);
intravisit::walk_ty(self, typ)
}
fn visit_generics(&mut self, generics: &Generics) {
self.visit_generics_helper(generics);
intravisit::walk_generics(self, generics)
}
fn visit_fn(&mut self,
function_kind: FnKind<'v>,
function_declaration: &'v FnDecl,
block: &'v Block,
span: Span,
node_id: NodeId) {
self.operation.visit_id(node_id);
match function_kind {
FnKind::ItemFn(_, generics, _, _, _, _, _) => {
self.visit_generics_helper(generics)
}
FnKind::Method(_, sig, _, _) => {
self.visit_generics_helper(&sig.generics)
}
FnKind::Closure(_) => {}
}
for argument in &function_declaration.inputs {
self.operation.visit_id(argument.id)
}
intravisit::walk_fn(self, function_kind, function_declaration, block, span);
}
fn visit_struct_field(&mut self, struct_field: &StructField) {
self.operation.visit_id(struct_field.id);
intravisit::walk_struct_field(self, struct_field)
}
fn visit_variant_data(&mut self,
struct_def: &VariantData,
_: Name,
_: &hir::Generics,
_: NodeId,
_: Span) {
self.operation.visit_id(struct_def.id());
intravisit::walk_struct_def(self, struct_def);
}
fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
if !self.skip_members {
self.operation.visit_id(ti.id);
intravisit::walk_trait_item(self, ti);
}
}
fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
if !self.skip_members {
self.operation.visit_id(ii.id);
intravisit::walk_impl_item(self, ii);
}
}
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
self.operation.visit_id(lifetime.id);
}
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
self.visit_lifetime(&def.lifetime);
}
fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {
self.operation.visit_id(trait_ref.ref_id);
intravisit::walk_trait_ref(self, trait_ref);
}
}
/// Computes the id range for a single fn body, ignoring nested items.
pub fn compute_id_range_for_fn_body(fk: FnKind,
decl: &FnDecl,
body: &Block,
sp: Span,
id: NodeId)
-> ast_util::IdRange {
let mut visitor = ast_util::IdRangeComputingVisitor { result: ast_util::IdRange::max() };
let mut id_visitor = IdVisitor::new(&mut visitor);
id_visitor.visit_fn(fk, decl, body, sp, id);
id_visitor.operation.result
}
pub fn is_path(e: P<Expr>) -> bool {
match e.node {
ExprPath(..) => true,
_ => false,
}
}
pub fn empty_generics() -> Generics {
Generics {
lifetimes: HirVec::new(),
ty_params: HirVec::new(),
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: HirVec::new(),
},
}
}
// convert a span and an identifier to the corresponding
// 1-segment path
pub fn ident_to_path(s: Span, ident: Ident) -> Path {
hir::Path {
span: s,
global: false,
segments: hir_vec![hir::PathSegment {
identifier: ident,
parameters: hir::AngleBracketedParameters(hir::AngleBracketedParameterData {
lifetimes: HirVec::new(),
types: HirVec::new(),
bindings: HirVec::new(),
}),
}],
}
}

View File

@ -47,8 +47,8 @@ use syntax::parse::token::InternedString;
use syntax::ast;
use syntax::attr::ThinAttributesExt;
use hir;
use hir::util;
use hir::intravisit as hir_visit;
use hir::intravisit::IdVisitor;
use syntax::visit as ast_visit;
/// Information about the registered lints.
@ -685,9 +685,9 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
}
fn visit_ids<F>(&mut self, f: F)
where F: FnOnce(&mut util::IdVisitor<LateContext>)
where F: FnOnce(&mut IdVisitor<LateContext>)
{
let mut v = util::IdVisitor::new(self);
let mut v = IdVisitor::new(self);
f(&mut v);
}
}

View File

@ -45,8 +45,7 @@ use syntax::ptr::P;
use syntax::parse::token::InternedString;
use rustc_back::target::Target;
use hir;
use hir::intravisit::Visitor;
use hir::util::IdVisitor;
use hir::intravisit::{IdVisitor, Visitor};
pub use self::DefLike::{DlDef, DlField, DlImpl};
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};

View File

@ -479,7 +479,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
}
hir::ExprUnary(op, ref lhs) => {
let pass_args = if hir::util::is_by_value_unop(op) {
let pass_args = if op.is_by_value() {
PassArgs::ByValue
} else {
PassArgs::ByRef
@ -491,7 +491,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
}
hir::ExprBinary(op, ref lhs, ref rhs) => {
let pass_args = if hir::util::is_by_value_binop(op.node) {
let pass_args = if op.node.is_by_value() {
PassArgs::ByValue
} else {
PassArgs::ByRef
@ -524,7 +524,7 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
// NB All our assignment operations take the RHS by value
assert!(hir::util::is_by_value_binop(op.node));
assert!(op.node.is_by_value());
if !self.walk_overloaded_operator(expr, lhs, vec![rhs], PassArgs::ByValue) {
self.mutate_expr(expr, &lhs, MutateMode::WriteAndRead);

View File

@ -484,7 +484,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
intravisit::walk_expr(ir, expr);
}
hir::ExprBinary(op, _, _) if hir::util::lazy_binop(op.node) => {
hir::ExprBinary(op, _, _) if op.node.is_lazy() => {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
intravisit::walk_expr(ir, expr);
}
@ -1142,7 +1142,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_exprs(&exprs[..], succ)
}
hir::ExprBinary(op, ref l, ref r) if hir::util::lazy_binop(op.node) => {
hir::ExprBinary(op, ref l, ref r) if op.node.is_lazy() => {
let r_succ = self.propagate_through_expr(&r, succ);
let ln = self.live_node(expr.id, expr.span);

View File

@ -15,7 +15,6 @@ use util::nodemap::FnvHashMap;
use syntax::ast;
use hir::{self, PatKind};
use hir::util::walk_pat;
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
use std::cell::RefCell;
@ -115,7 +114,7 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Name>),
{
walk_pat(pat, |p| {
pat.walk(|p| {
match p.node {
PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node.name));
@ -128,7 +127,7 @@ pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
pub fn pat_bindings_ident<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<hir::Ident>),
{
walk_pat(pat, |p| {
pat.walk(|p| {
match p.node {
PatKind::Ident(binding_mode, ref pth, _) if pat_is_binding(&dm.borrow(), p) => {
it(binding_mode, p.id, p.span, &respan(pth.span, pth.node));
@ -143,7 +142,7 @@ pub fn pat_bindings_ident<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) wh
/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
let mut contains_bindings = false;
walk_pat(pat, |p| {
pat.walk(|p| {
if pat_is_binding(dm, p) {
contains_bindings = true;
false // there's at least one binding, can short circuit now.
@ -188,7 +187,7 @@ pub fn arm_contains_ref_binding(dm: &RefCell<DefMap>, arm: &hir::Arm) -> Option<
/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`,
pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
let mut contains_bindings = false;
walk_pat(pat, |p| {
pat.walk(|p| {
if pat_is_binding_or_wild(dm, p) {
contains_bindings = true;
false // there's at least one binding/wildcard, can short circuit now.
@ -224,7 +223,7 @@ pub fn def_to_path(tcx: &TyCtxt, id: DefId) -> hir::Path {
/// Return variants that are necessary to exist for the pattern to match.
pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
let mut variants = vec![];
walk_pat(pat, |p| {
pat.walk(|p| {
match p.node {
PatKind::TupleStruct(..) |
PatKind::Path(..) |

View File

@ -33,7 +33,6 @@ use syntax::ast::{self, NodeId};
use hir;
use hir::intravisit::{self, Visitor, FnKind};
use hir::{Block, Item, FnDecl, Arm, Pat, PatKind, Stmt, Expr, Local};
use hir::util::stmt_id;
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
RustcDecodable, Copy)]
@ -765,7 +764,7 @@ fn resolve_pat(visitor: &mut RegionResolutionVisitor, pat: &hir::Pat) {
}
fn resolve_stmt(visitor: &mut RegionResolutionVisitor, stmt: &hir::Stmt) {
let stmt_id = stmt_id(stmt);
let stmt_id = stmt.node.id();
debug!("resolve_stmt(stmt.id={:?})", stmt_id);
// Every statement will clean up the temporaries created during

View File

@ -48,7 +48,6 @@ use rustc::hir;
use rustc::hir::{FnDecl, Block};
use rustc::hir::intravisit;
use rustc::hir::intravisit::{Visitor, FnKind};
use rustc::hir::util as hir_util;
use rustc::mir::mir_map::MirMap;
@ -210,7 +209,7 @@ fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
{
// Check the body of fn items.
let tcx = this.tcx;
let id_range = hir_util::compute_id_range_for_fn_body(fk, decl, body, sp, id);
let id_range = intravisit::compute_id_range_for_fn_body(fk, decl, body, sp, id);
let (all_loans, move_data) =
gather_loans::gather_loans_in_fn(this, id, decl, body);

View File

@ -34,8 +34,7 @@ use std::iter::{FromIterator, IntoIterator, repeat};
use rustc::hir;
use rustc::hir::{Pat, PatKind};
use rustc::hir::intravisit::{self, Visitor, FnKind};
use rustc::hir::util as front_util;
use rustc::hir::intravisit::{self, IdVisitor, Visitor, FnKind};
use rustc_back::slice;
use syntax::ast::{self, DUMMY_NODE_ID, NodeId};
@ -241,7 +240,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
}
fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat) {
front_util::walk_pat(pat, |p| {
pat.walk(|p| {
match p.node {
PatKind::Ident(hir::BindByValue(hir::MutImmutable), ident, None) => {
let pat_ty = cx.tcx.pat_ty(p);
@ -274,7 +273,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
// Check that we do not match against a static NaN (#6804)
fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
front_util::walk_pat(pat, |p| {
pat.walk(|p| {
if let PatKind::Lit(ref expr) = p.node {
match eval_const_expr_partial(cx.tcx, &expr, ExprTypeChecked, None) {
Ok(ConstVal::Float(f)) if f.is_nan() => {
@ -518,7 +517,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
renaming_map: renaming_map,
};
let mut id_visitor = front_util::IdVisitor::new(&mut renaming_recorder);
let mut id_visitor = IdVisitor::new(&mut renaming_recorder);
id_visitor.visit_expr(const_expr);
}
@ -1100,7 +1099,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
};
for pat in pats {
front_util::walk_pat(&pat, |p| {
pat.walk(|p| {
if pat_is_binding(&def_map.borrow(), &p) {
match p.node {
PatKind::Ident(hir::BindByValue(_), _, ref sub) => {

View File

@ -30,7 +30,6 @@ use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::{self, Span};
use rustc::hir;
use rustc::hir::util::is_shift_binop;
register_long_diagnostics! {
E0519: r##"
@ -130,7 +129,7 @@ impl LateLintPass for TypeLimits {
"comparison is useless due to type limits");
}
if is_shift_binop(binop.node) {
if binop.node.is_shift() {
let opt_ty_bits = match cx.tcx.node_id_to_type(l.id).sty {
ty::TyInt(t) => Some(int_ty_bits(t, cx.sess().target.int_type)),
ty::TyUint(t) => Some(uint_ty_bits(t, cx.sess().target.uint_type)),

View File

@ -23,7 +23,6 @@ use rustc::middle::pat_util;
use rustc::ty::{self, VariantDef, Ty};
use rustc::mir::repr::*;
use rustc::hir;
use rustc::hir::util as hir_util;
use syntax::ptr::P;
impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
@ -150,7 +149,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
if cx.tcx.is_method_call(self.id) {
let pass_args = if hir_util::is_by_value_binop(op.node) {
let pass_args = if op.node.is_by_value() {
PassArgs::ByValue
} else {
PassArgs::ByRef
@ -172,7 +171,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
hir::ExprBinary(op, ref lhs, ref rhs) => {
if cx.tcx.is_method_call(self.id) {
let pass_args = if hir_util::is_by_value_binop(op.node) {
let pass_args = if op.node.is_by_value() {
PassArgs::ByValue
} else {
PassArgs::ByRef

View File

@ -84,7 +84,6 @@ use rustc::hir::{PathSegment, PathParameters};
use rustc::hir::HirVec;
use rustc::hir::{TraitRef, Ty, TyBool, TyChar, TyFloat, TyInt};
use rustc::hir::{TyRptr, TyStr, TyUint, TyPath, TyPtr};
use rustc::hir::util::walk_pat;
use std::collections::{HashMap, HashSet};
use std::cell::{Cell, RefCell};
@ -2244,7 +2243,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// pattern that binds them
bindings_list: &mut HashMap<Name, NodeId>) {
let pat_id = pattern.id;
walk_pat(pattern, |pattern| {
pattern.walk(|pattern| {
match pattern.node {
PatKind::Ident(binding_mode, ref path1, ref at_rhs) => {
// The meaning of PatKind::Ident with no type parameters

View File

@ -712,7 +712,7 @@ fn cast_shift_rhs<F, G>(op: hir::BinOp_,
G: FnOnce(ValueRef, Type) -> ValueRef
{
// Shifts may have any size int on the rhs
if hir::util::is_shift_binop(op) {
if op.is_shift() {
let mut rhs_llty = val_ty(rhs);
let mut lhs_llty = val_ty(lhs);
if rhs_llty.kind() == Vector {

View File

@ -26,7 +26,6 @@ use expr;
use machine;
use rustc::hir;
use rustc::hir::util as ast_util;
use syntax::ast;
use syntax::parse::token::InternedString;
@ -49,7 +48,7 @@ pub fn trans_stmt<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
let mut bcx = cx;
let id = ast_util::stmt_id(s);
let id = s.node.id();
let cleanup_debug_loc =
debuginfo::get_cleanup_debug_loc_for_ast_node(bcx.ccx(), id, s.span, false);
fcx.push_ast_cleanup_scope(cleanup_debug_loc);
@ -70,7 +69,7 @@ pub fn trans_stmt<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
}
}
bcx = fcx.pop_and_trans_ast_cleanup_scope(bcx, ast_util::stmt_id(s));
bcx = fcx.pop_and_trans_ast_cleanup_scope(bcx, s.node.id());
return bcx;
}

View File

@ -116,7 +116,7 @@ fn walk_block(cx: &CrateContext,
// The interesting things here are statements and the concluding expression.
for statement in &block.stmts {
scope_map.insert(hir::util::stmt_id(statement),
scope_map.insert(statement.node.id(),
scope_stack.last().unwrap().scope_metadata);
match statement.node {

View File

@ -238,7 +238,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
return FunctionDebugContext::FunctionWithoutDebugInfo;
}
let empty_generics = hir::util::empty_generics();
let empty_generics = hir::Generics::empty();
let fnitem = cx.tcx().map.get(fn_ast_id);

View File

@ -1180,7 +1180,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// if not overloaded, would be RvalueDatumExpr
let lhs = unpack_datum!(bcx, trans(bcx, &lhs));
let mut rhs = unpack_datum!(bcx, trans(bcx, &rhs_expr));
if !hir::util::is_by_value_binop(op.node) {
if !op.node.is_by_value() {
rhs = unpack_datum!(bcx, auto_ref(bcx, rhs, rhs_expr));
}
@ -1204,7 +1204,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
span_bug!(
expr.span,
"augmented assignment `{}=` should always be a rvalue_stmt",
hir::util::binop_to_string(op.node))
op.node.as_str())
}
_ => {
span_bug!(

View File

@ -32,7 +32,6 @@ use syntax::ptr::P;
use rustc::hir::{self, PatKind};
use rustc::hir::print as pprust;
use rustc::hir::util as hir_util;
pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
pat: &'tcx hir::Pat,
@ -197,7 +196,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
}
}
PatKind::Ident(_, ref path, _) => {
let path = hir_util::ident_to_path(path.span, path.node);
let path = hir::Path::from_ident(path.span, path.node);
check_pat_enum(pcx, pat, &path, Some(&[]), expected, false);
}
PatKind::TupleStruct(ref path, ref subpats) => {

View File

@ -3987,7 +3987,7 @@ fn check_block_with_expected<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let mut any_err = false;
for s in &blk.stmts {
check_stmt(fcx, s);
let s_id = hir::util::stmt_id(s);
let s_id = s.node.id();
let s_ty = fcx.node_ty(s_id);
if any_diverges && !warned && match s.node {
hir::StmtDecl(ref decl, _) => {

View File

@ -23,7 +23,6 @@ use rustc::ty::{Ty, TypeFoldable, PreferMutLvalue};
use syntax::ast;
use syntax::parse::token;
use rustc::hir;
use rustc::hir::util as hir_util;
/// Check a `a <op>= b`
pub fn check_binop_assign<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
@ -184,12 +183,12 @@ fn check_overloaded_binop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
if let IsAssign::Yes = is_assign {
span_err!(fcx.tcx().sess, lhs_expr.span, E0368,
"binary assignment operation `{}=` cannot be applied to type `{}`",
hir_util::binop_to_string(op.node),
op.node.as_str(),
lhs_ty);
} else {
let mut err = struct_span_err!(fcx.tcx().sess, lhs_expr.span, E0369,
"binary operation `{}` cannot be applied to type `{}`",
hir_util::binop_to_string(op.node),
op.node.as_str(),
lhs_ty);
let missing_trait = match op.node {
hir::BiAdd => Some("std::ops::Add"),
@ -235,7 +234,7 @@ pub fn check_user_unop<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
op: hir::UnOp)
-> Ty<'tcx>
{
assert!(hir_util::is_by_value_unop(op));
assert!(op.is_by_value());
match lookup_op_method(fcx, ex, operand_ty, vec![],
token::intern(mname), trait_did,
operand_expr) {
@ -272,7 +271,7 @@ fn name_and_trait_def_id(fcx: &FnCtxt,
hir::BiOr => {
span_bug!(op.span,
"impossible assignment operation: {}=",
hir_util::binop_to_string(op.node))
op.node.as_str())
}
}
} else {

View File

@ -102,7 +102,6 @@ use syntax::ast;
use syntax::codemap::Span;
use rustc::hir::intravisit::{self, Visitor};
use rustc::hir::{self, PatKind};
use rustc::hir::util as hir_util;
use self::SubjectNode::Subject;
@ -689,7 +688,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &hir::Expr) {
},
hir::ExprBinary(op, ref lhs, ref rhs) if has_method_map => {
let implicitly_ref_args = !hir_util::is_by_value_binop(op.node);
let implicitly_ref_args = !op.node.is_by_value();
// As `expr_method_call`, but the call is via an
// overloaded op. Note that we (sadly) currently use an
@ -716,7 +715,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &hir::Expr) {
}
hir::ExprUnary(op, ref lhs) if has_method_map => {
let implicitly_ref_args = !hir_util::is_by_value_unop(op);
let implicitly_ref_args = !op.is_by_value();
// As above.
constrain_call(rcx, expr, Some(&lhs),

View File

@ -30,7 +30,6 @@ use syntax::ast;
use syntax::codemap::{DUMMY_SP, Span};
use rustc::hir::print::pat_to_string;
use rustc::hir::intravisit::{self, Visitor};
use rustc::hir::util as hir_util;
use rustc::hir;
///////////////////////////////////////////////////////////////////////////
@ -112,7 +111,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
// system.
match e.node {
hir::ExprBinary(..) => {
if !hir_util::is_by_value_binop(op.node) {
if !op.node.is_by_value() {
self.fcx.inh.tables.borrow_mut().adjustments.remove(&lhs.id);
}
},
@ -142,7 +141,7 @@ impl<'cx, 'tcx, 'v> Visitor<'v> for WritebackCx<'cx, 'tcx> {
return;
}
self.visit_node_id(ResolvingExpr(s.span), hir_util::stmt_id(s));
self.visit_node_id(ResolvingExpr(s.span), s.node.id());
intravisit::walk_stmt(self, s);
}