rustc: avoid use-ing syntax::ast::*.

This commit is contained in:
Eduard Burtescu 2014-09-13 20:10:34 +03:00
parent e09d98603e
commit 21da750663
8 changed files with 458 additions and 449 deletions

View File

@ -32,8 +32,7 @@ use std::cell::RefCell;
use std::hash::Hash;
use std::hash;
use syntax::abi;
use syntax::ast::*;
use syntax::ast;
use syntax::ast::{mod, DefId, NodeId};
use syntax::ast_map::{PathElem, PathElems};
use syntax::ast_map;
use syntax::ast_util::*;
@ -53,8 +52,8 @@ use rbml::io::SeekableMemWriter;
/// A borrowed version of `ast::InlinedItem`.
pub enum InlinedItemRef<'a> {
IIItemRef(&'a ast::Item),
IITraitItemRef(ast::DefId, &'a ast::TraitItem),
IIImplItemRef(ast::DefId, &'a ast::ImplItem),
IITraitItemRef(DefId, &'a ast::TraitItem),
IIImplItemRef(DefId, &'a ast::ImplItem),
IIForeignRef(&'a ast::ForeignItem)
}
@ -87,11 +86,11 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
pub reachable: &'a NodeSet,
}
fn encode_name(rbml_w: &mut Encoder, name: Name) {
fn encode_name(rbml_w: &mut Encoder, name: ast::Name) {
rbml_w.wr_tagged_str(tag_paths_data_name, token::get_name(name).get());
}
fn encode_impl_type_basename(rbml_w: &mut Encoder, name: Ident) {
fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Ident) {
rbml_w.wr_tagged_str(tag_item_impl_type_basename, token::get_ident(name).get());
}
@ -134,7 +133,7 @@ pub fn def_to_string(did: DefId) -> String {
fn encode_item_variances(rbml_w: &mut Encoder,
ecx: &EncodeContext,
id: ast::NodeId) {
id: NodeId) {
let v = ty::item_variances(ecx.tcx, ast_util::local_def(id));
rbml_w.start_tag(tag_item_variances);
v.encode(rbml_w);
@ -310,14 +309,14 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
fn encode_enum_variant_info(ecx: &EncodeContext,
rbml_w: &mut Encoder,
id: NodeId,
variants: &[P<Variant>],
variants: &[P<ast::Variant>],
index: &mut Vec<entry<i64>>) {
debug!("encode_enum_variant_info(id={})", id);
let mut disr_val = 0;
let mut i = 0;
let vi = ty::enum_variants(ecx.tcx,
ast::DefId { krate: LOCAL_CRATE, node: id });
DefId { krate: ast::LOCAL_CRATE, node: id });
for variant in variants.iter() {
let def_id = local_def(variant.node.id);
index.push(entry {
@ -382,7 +381,7 @@ fn encode_path<PI: Iterator<PathElem> + Clone>(rbml_w: &mut Encoder,
fn encode_reexported_static_method(rbml_w: &mut Encoder,
exp: &middle::resolve::Export2,
method_def_id: DefId,
method_name: Name) {
method_name: ast::Name) {
debug!("(encode reexported static method) {}::{}",
exp.name, token::get_name(method_name));
rbml_w.start_tag(tag_items_data_item_reexport);
@ -504,10 +503,10 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
/// * For enums, iterates through the node IDs of the variants.
///
/// * For newtype structs, iterates through the node ID of the constructor.
fn each_auxiliary_node_id(item: &Item, callback: |NodeId| -> bool) -> bool {
fn each_auxiliary_node_id(item: &ast::Item, callback: |NodeId| -> bool) -> bool {
let mut continue_ = true;
match item.node {
ItemEnum(ref enum_def, _) => {
ast::ItemEnum(ref enum_def, _) => {
for variant in enum_def.variants.iter() {
continue_ = callback(variant.node.id);
if !continue_ {
@ -515,7 +514,7 @@ fn each_auxiliary_node_id(item: &Item, callback: |NodeId| -> bool) -> bool {
}
}
}
ItemStruct(ref struct_def, _) => {
ast::ItemStruct(ref struct_def, _) => {
// If this is a newtype struct, return the constructor.
match struct_def.ctor_id {
Some(ctor_id) if struct_def.fields.len() > 0 &&
@ -566,12 +565,12 @@ fn encode_reexports(ecx: &EncodeContext,
fn encode_info_for_mod(ecx: &EncodeContext,
rbml_w: &mut Encoder,
md: &Mod,
attrs: &[Attribute],
md: &ast::Mod,
attrs: &[ast::Attribute],
id: NodeId,
path: PathElems,
name: Ident,
vis: Visibility) {
name: ast::Ident,
vis: ast::Visibility) {
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, local_def(id));
encode_family(rbml_w, 'm');
@ -593,7 +592,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
});
match item.node {
ItemImpl(..) => {
ast::ItemImpl(..) => {
let (ident, did) = (item.ident, item.id);
debug!("(encoding info for module) ... encoding impl {} \
({}/{})",
@ -615,7 +614,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
encode_stability(rbml_w, stab);
// Encode the reexports of this module, if this module is public.
if vis == Public {
if vis == ast::Public {
debug!("(encoding info for module) encoding reexports for {}", id);
encode_reexports(ecx, rbml_w, id, path);
}
@ -625,18 +624,18 @@ fn encode_info_for_mod(ecx: &EncodeContext,
}
fn encode_struct_field_family(rbml_w: &mut Encoder,
visibility: Visibility) {
visibility: ast::Visibility) {
encode_family(rbml_w, match visibility {
Public => 'g',
Inherited => 'N'
ast::Public => 'g',
ast::Inherited => 'N'
});
}
fn encode_visibility(rbml_w: &mut Encoder, visibility: Visibility) {
fn encode_visibility(rbml_w: &mut Encoder, visibility: ast::Visibility) {
rbml_w.start_tag(tag_items_data_item_visibility);
let ch = match visibility {
Public => 'y',
Inherited => 'i',
ast::Public => 'y',
ast::Inherited => 'i',
};
rbml_w.wr_str(ch.to_string().as_slice());
rbml_w.end_tag();
@ -681,8 +680,8 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
fn encode_mutability(rbml_w: &mut Encoder,
m: ast::Mutability) {
match m {
MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); }
MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); }
ast::MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); }
ast::MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); }
}
}
}
@ -854,7 +853,7 @@ fn encode_info_for_method(ecx: &EncodeContext,
impl_path: PathElems,
is_default_impl: bool,
parent_id: NodeId,
ast_item_opt: Option<&ImplItem>) {
ast_item_opt: Option<&ast::ImplItem>) {
debug!("encode_info_for_method: {} {}", m.def_id,
token::get_name(m.name));
@ -948,7 +947,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
fn encode_repr_attrs(rbml_w: &mut Encoder,
ecx: &EncodeContext,
attrs: &[Attribute]) {
attrs: &[ast::Attribute]) {
let mut repr_attrs = Vec::new();
for attr in attrs.iter() {
repr_attrs.extend(attr::find_repr_attrs(ecx.tcx.sess.diagnostic(),
@ -971,7 +970,7 @@ const FN_FAMILY: char = 'f';
const STATIC_METHOD_FAMILY: char = 'F';
const METHOD_FAMILY: char = 'h';
fn should_inline(attrs: &[Attribute]) -> bool {
fn should_inline(attrs: &[ast::Attribute]) -> bool {
use syntax::attr::*;
match find_inline_attr(attrs) {
InlineNone | InlineNever => false,
@ -1021,13 +1020,13 @@ fn encode_stability(rbml_w: &mut Encoder, stab_opt: Option<attr::Stability>) {
fn encode_info_for_item(ecx: &EncodeContext,
rbml_w: &mut Encoder,
item: &Item,
item: &ast::Item,
index: &mut Vec<entry<i64>>,
path: PathElems,
vis: ast::Visibility) {
let tcx = ecx.tcx;
fn add_to_index(item: &Item, rbml_w: &Encoder,
fn add_to_index(item: &ast::Item, rbml_w: &Encoder,
index: &mut Vec<entry<i64>>) {
index.push(entry {
val: item.id as i64,
@ -1042,7 +1041,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
let stab = stability::lookup(tcx, ast_util::local_def(item.id));
match item.node {
ItemStatic(_, m, _) => {
ast::ItemStatic(_, m, _) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
@ -1060,7 +1059,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_attributes(rbml_w, item.attrs.as_slice());
rbml_w.end_tag();
}
ItemConst(_, _) => {
ast::ItemConst(_, _) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
@ -1073,7 +1072,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_stability(rbml_w, stab);
rbml_w.end_tag();
}
ItemFn(ref decl, _, _, ref generics, _) => {
ast::ItemFn(ref decl, _, _, ref generics, _) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
@ -1094,7 +1093,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_method_argument_names(rbml_w, &**decl);
rbml_w.end_tag();
}
ItemMod(ref m) => {
ast::ItemMod(ref m) => {
add_to_index(item, rbml_w, index);
encode_info_for_mod(ecx,
rbml_w,
@ -1105,7 +1104,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
item.ident,
item.vis);
}
ItemForeignMod(ref fm) => {
ast::ItemForeignMod(ref fm) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
@ -1123,7 +1122,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_stability(rbml_w, stab);
rbml_w.end_tag();
}
ItemTy(..) => {
ast::ItemTy(..) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
@ -1135,7 +1134,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_stability(rbml_w, stab);
rbml_w.end_tag();
}
ItemEnum(ref enum_definition, _) => {
ast::ItemEnum(ref enum_definition, _) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
@ -1165,7 +1164,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
(*enum_definition).variants.as_slice(),
index);
}
ItemStruct(ref struct_def, _) => {
ast::ItemStruct(ref struct_def, _) => {
let fields = ty::lookup_struct_fields(tcx, def_id);
/* First, encode the fields
@ -1217,7 +1216,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
None => {}
}
}
ItemImpl(_, ref opt_trait, ref ty, ref ast_items) => {
ast::ItemImpl(_, ref opt_trait, ref ty, ref ast_items) => {
// We need to encode information about the default methods we
// have inherited, so we drive this based on the impl structure.
let impl_items = tcx.impl_items.borrow();
@ -1321,7 +1320,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
}
}
ItemTrait(_, _, _, ref ms) => {
ast::ItemTrait(_, _, _, ref ms) => {
add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
@ -1433,14 +1432,14 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
};
match trait_item {
&RequiredMethod(ref m) => {
&ast::RequiredMethod(ref m) => {
encode_attributes(rbml_w, m.attrs.as_slice());
encode_trait_item(rbml_w);
encode_item_sort(rbml_w, 'r');
encode_method_argument_names(rbml_w, &*m.decl);
}
&ProvidedMethod(ref m) => {
&ast::ProvidedMethod(ref m) => {
encode_attributes(rbml_w, m.attrs.as_slice());
encode_trait_item(rbml_w);
encode_item_sort(rbml_w, 'p');
@ -1448,7 +1447,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
}
&TypeTraitItem(ref associated_type) => {
&ast::TypeTraitItem(ref associated_type) => {
encode_attributes(rbml_w,
associated_type.attrs.as_slice());
encode_item_sort(rbml_w, 't');
@ -1461,7 +1460,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// Encode inherent implementations for this trait.
encode_inherent_implementations(ecx, rbml_w, def_id);
}
ItemMac(..) => {
ast::ItemMac(..) => {
// macros are encoded separately
}
}
@ -1469,7 +1468,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
fn encode_info_for_foreign_item(ecx: &EncodeContext,
rbml_w: &mut Encoder,
nitem: &ForeignItem,
nitem: &ast::ForeignItem,
index: &mut Vec<entry<i64>>,
path: PathElems,
abi: abi::Abi) {
@ -1482,7 +1481,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
encode_def_id(rbml_w, local_def(nitem.id));
encode_visibility(rbml_w, nitem.vis);
match nitem.node {
ForeignItemFn(..) => {
ast::ForeignItemFn(..) => {
encode_family(rbml_w, FN_FAMILY);
encode_bounds_and_type(rbml_w, ecx,
&lookup_item_type(ecx.tcx,local_def(nitem.id)));
@ -1492,7 +1491,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
}
encode_symbol(ecx, rbml_w, nitem.id);
}
ForeignItemStatic(_, mutbl) => {
ast::ForeignItemStatic(_, mutbl) => {
if mutbl {
encode_family(rbml_w, 'b');
} else {
@ -1508,9 +1507,9 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
rbml_w.end_tag();
}
fn my_visit_expr(_e: &Expr) { }
fn my_visit_expr(_e: &ast::Expr) { }
fn my_visit_item(i: &Item,
fn my_visit_item(i: &ast::Item,
rbml_w: &mut Encoder,
ecx: &EncodeContext,
index: &mut Vec<entry<i64>>) {
@ -1519,7 +1518,7 @@ fn my_visit_item(i: &Item,
});
}
fn my_visit_foreign_item(ni: &ForeignItem,
fn my_visit_foreign_item(ni: &ast::ForeignItem,
rbml_w: &mut Encoder,
ecx: &EncodeContext,
index: &mut Vec<entry<i64>>) {
@ -1542,18 +1541,18 @@ struct EncodeVisitor<'a, 'b:'a, 'c:'a, 'tcx:'c> {
}
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for EncodeVisitor<'a, 'b, 'c, 'tcx> {
fn visit_expr(&mut self, ex: &Expr) {
fn visit_expr(&mut self, ex: &ast::Expr) {
visit::walk_expr(self, ex);
my_visit_expr(ex);
}
fn visit_item(&mut self, i: &Item) {
fn visit_item(&mut self, i: &ast::Item) {
visit::walk_item(self, i);
my_visit_item(i,
self.rbml_w_for_visit_item,
self.ecx,
self.index);
}
fn visit_foreign_item(&mut self, ni: &ForeignItem) {
fn visit_foreign_item(&mut self, ni: &ast::ForeignItem) {
visit::walk_foreign_item(self, ni);
my_visit_foreign_item(ni,
self.rbml_w_for_visit_item,
@ -1564,22 +1563,22 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for EncodeVisitor<'a, 'b, 'c, 'tcx> {
fn encode_info_for_items(ecx: &EncodeContext,
rbml_w: &mut Encoder,
krate: &Crate)
krate: &ast::Crate)
-> Vec<entry<i64>> {
let mut index = Vec::new();
rbml_w.start_tag(tag_items_data);
index.push(entry {
val: CRATE_NODE_ID as i64,
val: ast::CRATE_NODE_ID as i64,
pos: rbml_w.writer.tell().unwrap(),
});
encode_info_for_mod(ecx,
rbml_w,
&krate.module,
&[],
CRATE_NODE_ID,
ast::CRATE_NODE_ID,
ast_map::Values([].iter()).chain(None),
syntax::parse::token::special_idents::invalid,
Public);
ast::Public);
visit::walk_crate(&mut EncodeVisitor {
index: &mut index,
@ -1637,18 +1636,18 @@ fn write_i64(writer: &mut SeekableMemWriter, &n: &i64) {
wr.write_be_u32(n as u32);
}
fn encode_meta_item(rbml_w: &mut Encoder, mi: &MetaItem) {
fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
match mi.node {
MetaWord(ref name) => {
ast::MetaWord(ref name) => {
rbml_w.start_tag(tag_meta_item_word);
rbml_w.start_tag(tag_meta_item_name);
rbml_w.writer.write(name.get().as_bytes());
rbml_w.end_tag();
rbml_w.end_tag();
}
MetaNameValue(ref name, ref value) => {
ast::MetaNameValue(ref name, ref value) => {
match value.node {
LitStr(ref value, _) => {
ast::LitStr(ref value, _) => {
rbml_w.start_tag(tag_meta_item_name_value);
rbml_w.start_tag(tag_meta_item_name);
rbml_w.writer.write(name.get().as_bytes());
@ -1661,7 +1660,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &MetaItem) {
_ => {/* FIXME (#623): encode other variants */ }
}
}
MetaList(ref name, ref items) => {
ast::MetaList(ref name, ref items) => {
rbml_w.start_tag(tag_meta_item_list);
rbml_w.start_tag(tag_meta_item_name);
rbml_w.writer.write(name.get().as_bytes());
@ -1674,7 +1673,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &MetaItem) {
}
}
fn encode_attributes(rbml_w: &mut Encoder, attrs: &[Attribute]) {
fn encode_attributes(rbml_w: &mut Encoder, attrs: &[ast::Attribute]) {
rbml_w.start_tag(tag_attributes);
for attr in attrs.iter() {
rbml_w.start_tag(tag_attribute);
@ -1728,7 +1727,7 @@ fn encode_lang_items(ecx: &EncodeContext, rbml_w: &mut Encoder) {
for (i, def_id) in ecx.tcx.lang_items.items() {
for id in def_id.iter() {
if id.krate == LOCAL_CRATE {
if id.krate == ast::LOCAL_CRATE {
rbml_w.start_tag(tag_lang_items_item);
rbml_w.start_tag(tag_lang_items_item_id);
@ -1804,7 +1803,7 @@ fn encode_macro_def(ecx: &EncodeContext,
/// Serialize the text of the exported macros
fn encode_macro_defs(ecx: &EncodeContext,
krate: &Crate,
krate: &ast::Crate,
rbml_w: &mut Encoder) {
rbml_w.start_tag(tag_exported_macros);
for item in krate.exported_macros.iter() {
@ -1821,7 +1820,7 @@ fn encode_unboxed_closures<'a>(
.unboxed_closures
.borrow()
.iter() {
if unboxed_closure_id.krate != LOCAL_CRATE {
if unboxed_closure_id.krate != ast::LOCAL_CRATE {
continue
}
@ -1836,7 +1835,7 @@ fn encode_unboxed_closures<'a>(
rbml_w.end_tag();
}
fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &Crate) {
fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &ast::Crate) {
struct StructFieldVisitor<'a, 'b:'a> {
rbml_w: &'a mut Encoder<'b>,
}
@ -1865,9 +1864,9 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
}
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
fn visit_item(&mut self, item: &Item) {
fn visit_item(&mut self, item: &ast::Item) {
match item.node {
ItemImpl(_, Some(ref trait_ref), _, _) => {
ast::ItemImpl(_, Some(ref trait_ref), _, _) => {
let def_map = &self.ecx.tcx.def_map;
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
let def_id = trait_def.def_id();
@ -1875,7 +1874,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
// Load eagerly if this is an implementation of the Drop trait
// or if the trait is not defined in this crate.
if Some(def_id) == self.ecx.tcx.lang_items.drop_trait() ||
def_id.krate != LOCAL_CRATE {
def_id.krate != ast::LOCAL_CRATE {
self.rbml_w.start_tag(tag_impls_impl);
encode_def_id(self.rbml_w, local_def(item.id));
self.rbml_w.end_tag();
@ -1898,7 +1897,7 @@ impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
///
/// * Implementations of traits not defined in this crate.
fn encode_impls<'a>(ecx: &'a EncodeContext,
krate: &Crate,
krate: &ast::Crate,
rbml_w: &'a mut Encoder) {
rbml_w.start_tag(tag_impls);
@ -1914,7 +1913,7 @@ fn encode_impls<'a>(ecx: &'a EncodeContext,
}
fn encode_misc_info(ecx: &EncodeContext,
krate: &Crate,
krate: &ast::Crate,
rbml_w: &mut Encoder) {
rbml_w.start_tag(tag_misc_info);
rbml_w.start_tag(tag_misc_info_crate_items);
@ -2011,13 +2010,15 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
#[allow(non_upper_case_globals)]
pub const metadata_encoding_version : &'static [u8] = &[b'r', b'u', b's', b't', 0, 0, 0, 1 ];
pub fn encode_metadata(parms: EncodeParams, krate: &Crate) -> Vec<u8> {
pub fn encode_metadata(parms: EncodeParams, krate: &ast::Crate) -> Vec<u8> {
let mut wr = SeekableMemWriter::new();
encode_metadata_inner(&mut wr, parms, krate);
wr.unwrap().into_iter().collect()
}
fn encode_metadata_inner(wr: &mut SeekableMemWriter, parms: EncodeParams, krate: &Crate) {
fn encode_metadata_inner(wr: &mut SeekableMemWriter,
parms: EncodeParams,
krate: &ast::Crate) {
struct Stats {
attr_bytes: u64,
dep_bytes: u64,

View File

@ -27,7 +27,6 @@ use std::str;
use std::string::String;
use syntax::abi;
use syntax::ast;
use syntax::ast::*;
use syntax::parse::token;
// Compact string representation for ty::t values. API ty_str &
@ -525,10 +524,10 @@ fn parse_hex(st: &mut PState) -> uint {
};
}
fn parse_fn_style(c: char) -> FnStyle {
fn parse_fn_style(c: char) -> ast::FnStyle {
match c {
'u' => UnsafeFn,
'n' => NormalFn,
'u' => ast::UnsafeFn,
'n' => ast::NormalFn,
_ => panic!("parse_fn_style: bad fn_style {}", c)
}
}

View File

@ -23,7 +23,6 @@ use util::nodemap::FnvHashMap;
use syntax::abi::Abi;
use syntax::ast;
use syntax::ast::*;
use syntax::diagnostic::SpanHandler;
use syntax::parse::token;
@ -34,7 +33,7 @@ macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) )
pub struct ctxt<'a, 'tcx: 'a> {
pub diag: &'a SpanHandler,
// Def -> str Callback:
pub ds: fn(DefId) -> String,
pub ds: fn(ast::DefId) -> String,
// The type context.
pub tcx: &'a ty::ctxt<'tcx>,
pub abbrevs: &'a abbrev_map
@ -75,8 +74,8 @@ pub fn enc_ty(w: &mut SeekableMemWriter, cx: &ctxt, t: ty::t) {
fn enc_mutability(w: &mut SeekableMemWriter, mt: ast::Mutability) {
match mt {
MutImmutable => (),
MutMutable => mywrite!(w, "m"),
ast::MutImmutable => (),
ast::MutMutable => mywrite!(w, "m"),
}
}
@ -203,26 +202,26 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
ty::ty_char => mywrite!(w, "c"),
ty::ty_int(t) => {
match t {
TyI => mywrite!(w, "i"),
TyI8 => mywrite!(w, "MB"),
TyI16 => mywrite!(w, "MW"),
TyI32 => mywrite!(w, "ML"),
TyI64 => mywrite!(w, "MD")
ast::TyI => mywrite!(w, "i"),
ast::TyI8 => mywrite!(w, "MB"),
ast::TyI16 => mywrite!(w, "MW"),
ast::TyI32 => mywrite!(w, "ML"),
ast::TyI64 => mywrite!(w, "MD")
}
}
ty::ty_uint(t) => {
match t {
TyU => mywrite!(w, "u"),
TyU8 => mywrite!(w, "Mb"),
TyU16 => mywrite!(w, "Mw"),
TyU32 => mywrite!(w, "Ml"),
TyU64 => mywrite!(w, "Md")
ast::TyU => mywrite!(w, "u"),
ast::TyU8 => mywrite!(w, "Mb"),
ast::TyU16 => mywrite!(w, "Mw"),
ast::TyU32 => mywrite!(w, "Ml"),
ast::TyU64 => mywrite!(w, "Md")
}
}
ty::ty_float(t) => {
match t {
TyF32 => mywrite!(w, "Mf"),
TyF64 => mywrite!(w, "MF"),
ast::TyF32 => mywrite!(w, "Mf"),
ast::TyF64 => mywrite!(w, "MF"),
}
}
ty::ty_enum(def, ref substs) => {
@ -295,10 +294,10 @@ fn enc_sty(w: &mut SeekableMemWriter, cx: &ctxt, st: &ty::sty) {
}
}
fn enc_fn_style(w: &mut SeekableMemWriter, p: FnStyle) {
fn enc_fn_style(w: &mut SeekableMemWriter, p: ast::FnStyle) {
match p {
NormalFn => mywrite!(w, "n"),
UnsafeFn => mywrite!(w, "u"),
ast::NormalFn => mywrite!(w, "n"),
ast::UnsafeFn => mywrite!(w, "u"),
}
}
@ -308,10 +307,10 @@ fn enc_abi(w: &mut SeekableMemWriter, abi: Abi) {
mywrite!(w, "]")
}
fn enc_onceness(w: &mut SeekableMemWriter, o: Onceness) {
fn enc_onceness(w: &mut SeekableMemWriter, o: ast::Onceness) {
match o {
Once => mywrite!(w, "o"),
Many => mywrite!(w, "m")
ast::Once => mywrite!(w, "o"),
ast::Many => mywrite!(w, "m")
}
}

View File

@ -14,7 +14,7 @@ use middle::ty;
use middle::typeck;
use util::ppaux;
use syntax::ast::*;
use syntax::ast;
use syntax::ast_util;
use syntax::visit::Visitor;
use syntax::visit;
@ -40,13 +40,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
}
impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &Item) {
fn visit_item(&mut self, i: &ast::Item) {
check_item(self, i);
}
fn visit_pat(&mut self, p: &Pat) {
fn visit_pat(&mut self, p: &ast::Pat) {
check_pat(self, p);
}
fn visit_expr(&mut self, ex: &Expr) {
fn visit_expr(&mut self, ex: &ast::Expr) {
if check_expr(self, ex) {
visit::walk_expr(self, ex);
}
@ -59,13 +59,13 @@ pub fn check_crate(tcx: &ty::ctxt) {
tcx.sess.abort_if_errors();
}
fn check_item(v: &mut CheckCrateVisitor, it: &Item) {
fn check_item(v: &mut CheckCrateVisitor, it: &ast::Item) {
match it.node {
ItemStatic(_, _, ref ex) |
ItemConst(_, ref ex) => {
ast::ItemStatic(_, _, ref ex) |
ast::ItemConst(_, ref ex) => {
v.inside_const(|v| v.visit_expr(&**ex));
}
ItemEnum(ref enum_definition, _) => {
ast::ItemEnum(ref enum_definition, _) => {
for var in (*enum_definition).variants.iter() {
for ex in var.node.disr_expr.iter() {
v.inside_const(|v| v.visit_expr(&**ex));
@ -76,12 +76,12 @@ fn check_item(v: &mut CheckCrateVisitor, it: &Item) {
}
}
fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) {
fn is_str(e: &Expr) -> bool {
fn check_pat(v: &mut CheckCrateVisitor, p: &ast::Pat) {
fn is_str(e: &ast::Expr) -> bool {
match e.node {
ExprBox(_, ref expr) => {
ast::ExprBox(_, ref expr) => {
match expr.node {
ExprLit(ref lit) => ast_util::lit_is_str(&**lit),
ast::ExprLit(ref lit) => ast_util::lit_is_str(&**lit),
_ => false,
}
}
@ -90,8 +90,8 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) {
}
match p.node {
// Let through plain ~-string literals here
PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); },
PatRange(ref a, ref b) => {
ast::PatLit(ref a) => if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); },
ast::PatRange(ref a, ref b) => {
if !is_str(&**a) { v.inside_const(|v| v.visit_expr(&**a)); }
if !is_str(&**b) { v.inside_const(|v| v.visit_expr(&**b)); }
}
@ -99,18 +99,18 @@ fn check_pat(v: &mut CheckCrateVisitor, p: &Pat) {
}
}
fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) -> bool {
if !v.in_const { return true }
match e.node {
ExprUnary(UnDeref, _) => {}
ExprUnary(UnUniq, _) => {
ast::ExprUnary(ast::UnDeref, _) => {}
ast::ExprUnary(ast::UnUniq, _) => {
span_err!(v.tcx.sess, e.span, E0010,
"cannot do allocations in constant expressions");
return false;
}
ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {}
ExprBinary(..) | ExprUnary(..) => {
ast::ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {}
ast::ExprBinary(..) | ast::ExprUnary(..) => {
let method_call = typeck::MethodCall::expr(e.id);
if v.tcx.method_map.borrow().contains_key(&method_call) {
span_err!(v.tcx.sess, e.span, E0011,
@ -118,8 +118,8 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
expressions");
}
}
ExprLit(_) => (),
ExprCast(ref from, _) => {
ast::ExprLit(_) => (),
ast::ExprCast(ref from, _) => {
let toty = ty::expr_ty(v.tcx, e);
let fromty = ty::expr_ty(v.tcx, &**from);
if !ty::type_is_numeric(toty) && !ty::type_is_unsafe_ptr(toty) {
@ -133,7 +133,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
expression");
}
}
ExprPath(ref pth) => {
ast::ExprPath(ref pth) => {
// NB: In the future you might wish to relax this slightly
// to handle on-demand instantiation of functions via
// foo::<bar> in a const. Currently that is only done on
@ -161,7 +161,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
}
}
}
ExprCall(ref callee, _) => {
ast::ExprCall(ref callee, _) => {
match v.tcx.def_map.borrow().get(&callee.id) {
Some(&DefStruct(..)) |
Some(&DefVariant(..)) => {} // OK.
@ -173,7 +173,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
}
}
}
ExprBlock(ref block) => {
ast::ExprBlock(ref block) => {
// Check all statements in the block
for stmt in block.stmts.iter() {
let block_span_err = |span|
@ -181,17 +181,17 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
"blocks in constants are limited to items and \
tail expressions");
match stmt.node {
StmtDecl(ref span, _) => {
ast::StmtDecl(ref span, _) => {
match span.node {
DeclLocal(_) => block_span_err(span.span),
ast::DeclLocal(_) => block_span_err(span.span),
// Item statements are allowed
DeclItem(_) => {}
ast::DeclItem(_) => {}
}
}
StmtExpr(ref expr, _) => block_span_err(expr.span),
StmtSemi(ref semi, _) => block_span_err(semi.span),
StmtMac(..) => {
ast::StmtExpr(ref expr, _) => block_span_err(expr.span),
ast::StmtSemi(ref semi, _) => block_span_err(semi.span),
ast::StmtMac(..) => {
v.tcx.sess.span_bug(e.span, "unexpanded statement \
macro in const?!")
}
@ -202,20 +202,20 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr) -> bool {
None => {}
}
}
ExprVec(_) |
ExprAddrOf(MutImmutable, _) |
ExprParen(..) |
ExprField(..) |
ExprTupField(..) |
ExprIndex(..) |
ExprTup(..) |
ExprRepeat(..) |
ExprStruct(..) => {}
ast::ExprVec(_) |
ast::ExprAddrOf(ast::MutImmutable, _) |
ast::ExprParen(..) |
ast::ExprField(..) |
ast::ExprTupField(..) |
ast::ExprIndex(..) |
ast::ExprTup(..) |
ast::ExprRepeat(..) |
ast::ExprStruct(..) => {}
ExprAddrOf(_, ref inner) => {
ast::ExprAddrOf(_, ref inner) => {
match inner.node {
// Mutable slices are allowed.
ExprVec(_) => {}
ast::ExprVec(_) => {}
_ => span_err!(v.tcx.sess, e.span, E0017,
"references in constants may only refer \
to immutable values")

View File

@ -27,7 +27,7 @@ use std::iter::AdditiveIterator;
use std::iter::range_inclusive;
use std::num::Float;
use std::slice;
use syntax::ast::*;
use syntax::ast::{mod, DUMMY_NODE_ID, NodeId, Pat};
use syntax::ast_util::walk_pat;
use syntax::codemap::{Span, Spanned, DUMMY_SP};
use syntax::fold::{Folder, noop_fold_pat};
@ -39,7 +39,7 @@ use util::ppaux::ty_to_string;
pub const DUMMY_WILD_PAT: &'static Pat = &Pat {
id: DUMMY_NODE_ID,
node: PatWild(PatWildSingle),
node: ast::PatWild(ast::PatWildSingle),
span: DUMMY_SP
};
@ -108,7 +108,7 @@ pub enum Constructor {
/// e.g. struct patterns and fixed-length arrays.
Single,
/// Enum variants.
Variant(DefId),
Variant(ast::DefId),
/// Literal values.
ConstantValue(const_val),
/// Ranges of literal values (2..5).
@ -132,14 +132,14 @@ enum WitnessPreference {
}
impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> {
fn visit_expr(&mut self, ex: &Expr) {
fn visit_expr(&mut self, ex: &ast::Expr) {
check_expr(self, ex);
}
fn visit_local(&mut self, l: &Local) {
fn visit_local(&mut self, l: &ast::Local) {
check_local(self, l);
}
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl,
b: &'v Block, s: Span, n: NodeId) {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v ast::FnDecl,
b: &'v ast::Block, s: Span, n: NodeId) {
check_fn(self, fk, fd, b, s, n);
}
}
@ -149,10 +149,10 @@ pub fn check_crate(tcx: &ty::ctxt) {
tcx.sess.abort_if_errors();
}
fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) {
fn check_expr(cx: &mut MatchCheckCtxt, ex: &ast::Expr) {
visit::walk_expr(cx, ex);
match ex.node {
ExprMatch(ref scrut, ref arms, source) => {
ast::ExprMatch(ref scrut, ref arms, source) => {
// First, check legality of move bindings.
for arm in arms.iter() {
check_legality_of_move_bindings(cx,
@ -177,7 +177,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) {
(arm.pats.iter().map(|pat| {
static_inliner.fold_pat((*pat).clone())
}).collect(), arm.guard.as_ref().map(|e| &**e))
}).collect::<Vec<(Vec<P<Pat>>, Option<&Expr>)>>();
}).collect::<Vec<(Vec<P<Pat>>, Option<&ast::Expr>)>>();
if static_inliner.failed {
return;
@ -214,7 +214,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) {
.collect();
check_exhaustive(cx, ex.span, &matrix);
},
ExprForLoop(ref pat, _, _, _) => {
ast::ExprForLoop(ref pat, _, _, _) => {
let mut static_inliner = StaticInliner::new(cx.tcx);
is_refutable(cx, &*static_inliner.fold_pat((*pat).clone()), |uncovered_pat| {
cx.tcx.sess.span_err(
@ -232,7 +232,7 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &Expr) {
}
}
fn is_expr_const_nan(tcx: &ty::ctxt, expr: &Expr) -> bool {
fn is_expr_const_nan(tcx: &ty::ctxt, expr: &ast::Expr) -> bool {
match eval_const_expr(tcx, expr) {
const_float(f) => f.is_nan(),
_ => false
@ -244,7 +244,7 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pats: &[P<Pat>]) {
for pat in pats.iter() {
walk_pat(&**pat, |p| {
match p.node {
PatLit(ref expr) if is_expr_const_nan(cx.tcx, &**expr) => {
ast::PatLit(ref expr) if is_expr_const_nan(cx.tcx, &**expr) => {
span_warn!(cx.tcx.sess, p.span, E0003,
"unmatchable NaN in pattern, \
use the is_nan method in a guard instead");
@ -257,7 +257,9 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pats: &[P<Pat>]) {
}
// Check for unreachable patterns
fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)], source: MatchSource) {
fn check_arms(cx: &MatchCheckCtxt,
arms: &[(Vec<P<Pat>>, Option<&ast::Expr>)],
source: ast::MatchSource) {
let mut seen = Matrix(vec![]);
let mut printed_if_let_err = false;
for &(ref pats, guard) in arms.iter() {
@ -267,7 +269,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)], source
match is_useful(cx, &seen, v.as_slice(), LeaveOutWitness) {
NotUseful => {
match source {
MatchIfLetDesugar => {
ast::MatchIfLetDesugar => {
if printed_if_let_err {
// we already printed an irrefutable if-let pattern error.
// We don't want two, that's just confusing.
@ -281,7 +283,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)], source
}
},
MatchWhileLetDesugar => {
ast::MatchWhileLetDesugar => {
// find the first arm pattern so we can use its span
let &(ref first_arm_pats, _) = &arms[0];
let first_pat = &first_arm_pats[0];
@ -289,7 +291,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)], source
span_err!(cx.tcx.sess, span, E0165, "irrefutable while-let pattern");
},
MatchNormal => {
ast::MatchNormal => {
span_err!(cx.tcx.sess, pat.span, E0001, "unreachable pattern")
},
}
@ -308,7 +310,7 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[(Vec<P<Pat>>, Option<&Expr>)], source
fn raw_pat<'a>(p: &'a Pat) -> &'a Pat {
match p.node {
PatIdent(_, _, Some(ref s)) => raw_pat(&**s),
ast::PatIdent(_, _, Some(ref s)) => raw_pat(&**s),
_ => p
}
}
@ -333,14 +335,14 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
}
}
fn const_val_to_expr(value: &const_val) -> P<Expr> {
fn const_val_to_expr(value: &const_val) -> P<ast::Expr> {
let node = match value {
&const_bool(b) => LitBool(b),
&const_bool(b) => ast::LitBool(b),
_ => unreachable!()
};
P(Expr {
P(ast::Expr {
id: 0,
node: ExprLit(P(Spanned { node: node, span: DUMMY_SP })),
node: ast::ExprLit(P(Spanned { node: node, span: DUMMY_SP })),
span: DUMMY_SP
})
}
@ -362,7 +364,7 @@ impl<'a, 'tcx> StaticInliner<'a, 'tcx> {
impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
fn fold_pat(&mut self, pat: P<Pat>) -> P<Pat> {
match pat.node {
PatIdent(..) | PatEnum(..) => {
ast::PatIdent(..) | ast::PatEnum(..) => {
let def = self.tcx.def_map.borrow().get(&pat.id).cloned();
match def {
Some(DefConst(did)) => match lookup_const_by_id(self.tcx, did) {
@ -405,7 +407,7 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
let pats_len = pats.len();
let mut pats = pats.into_iter().map(|p| P((*p).clone()));
let pat = match ty::get(left_ty).sty {
ty::ty_tup(_) => PatTup(pats.collect()),
ty::ty_tup(_) => ast::PatTup(pats.collect()),
ty::ty_enum(cid, _) | ty::ty_struct(cid, _) => {
let (vid, is_structure) = match ctor {
@ -417,21 +419,21 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
};
if is_structure {
let fields = ty::lookup_struct_fields(cx.tcx, vid);
let field_pats: Vec<Spanned<FieldPat>> = fields.into_iter()
let field_pats: Vec<_> = fields.into_iter()
.zip(pats)
.filter(|&(_, ref pat)| pat.node != PatWild(PatWildSingle))
.filter(|&(_, ref pat)| pat.node != ast::PatWild(ast::PatWildSingle))
.map(|(field, pat)| Spanned {
span: DUMMY_SP,
node: FieldPat {
ident: Ident::new(field.name),
node: ast::FieldPat {
ident: ast::Ident::new(field.name),
pat: pat,
is_shorthand: false,
}
}).collect();
let has_more_fields = field_pats.len() < pats_len;
PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields)
ast::PatStruct(def_to_path(cx.tcx, vid), field_pats, has_more_fields)
} else {
PatEnum(def_to_path(cx.tcx, vid), Some(pats.collect()))
ast::PatEnum(def_to_path(cx.tcx, vid), Some(pats.collect()))
}
}
@ -440,40 +442,40 @@ fn construct_witness(cx: &MatchCheckCtxt, ctor: &Constructor,
ty::ty_vec(_, Some(n)) => match ctor {
&Single => {
assert_eq!(pats_len, n);
PatVec(pats.collect(), None, vec!())
ast::PatVec(pats.collect(), None, vec!())
},
_ => unreachable!()
},
ty::ty_vec(_, None) => match ctor {
&Slice(n) => {
assert_eq!(pats_len, n);
PatVec(pats.collect(), None, vec!())
ast::PatVec(pats.collect(), None, vec!())
},
_ => unreachable!()
},
ty::ty_str => PatWild(PatWildSingle),
ty::ty_str => ast::PatWild(ast::PatWildSingle),
_ => {
assert_eq!(pats_len, 1);
PatRegion(pats.nth(0).unwrap())
ast::PatRegion(pats.nth(0).unwrap())
}
}
}
ty::ty_vec(_, Some(len)) => {
assert_eq!(pats_len, len);
PatVec(pats.collect(), None, vec![])
ast::PatVec(pats.collect(), None, vec![])
}
_ => {
match *ctor {
ConstantValue(ref v) => PatLit(const_val_to_expr(v)),
_ => PatWild(PatWildSingle),
ConstantValue(ref v) => ast::PatLit(const_val_to_expr(v)),
_ => ast::PatWild(ast::PatWildSingle),
}
}
};
P(Pat {
P(ast::Pat {
id: 0,
node: pat,
span: DUMMY_SP
@ -558,7 +560,7 @@ fn is_useful(cx: &MatchCheckCtxt,
};
let max_slice_length = rows.iter().filter_map(|row| match row[0].node {
PatVec(ref before, _, ref after) => Some(before.len() + after.len()),
ast::PatVec(ref before, _, ref after) => Some(before.len() + after.len()),
_ => None
}).max().map_or(0, |v| v + 1);
@ -639,7 +641,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
left_ty: ty::t, max_slice_length: uint) -> Vec<Constructor> {
let pat = raw_pat(p);
match pat.node {
PatIdent(..) =>
ast::PatIdent(..) =>
match cx.tcx.def_map.borrow().get(&pat.id) {
Some(&DefConst(..)) =>
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
@ -648,7 +650,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
Some(&DefVariant(_, id, _)) => vec!(Variant(id)),
_ => vec!()
},
PatEnum(..) =>
ast::PatEnum(..) =>
match cx.tcx.def_map.borrow().get(&pat.id) {
Some(&DefConst(..)) =>
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
@ -656,7 +658,7 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
Some(&DefVariant(_, id, _)) => vec!(Variant(id)),
_ => vec!(Single)
},
PatStruct(..) =>
ast::PatStruct(..) =>
match cx.tcx.def_map.borrow().get(&pat.id) {
Some(&DefConst(..)) =>
cx.tcx.sess.span_bug(pat.span, "const pattern should've \
@ -664,11 +666,11 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
Some(&DefVariant(_, id, _)) => vec!(Variant(id)),
_ => vec!(Single)
},
PatLit(ref expr) =>
ast::PatLit(ref expr) =>
vec!(ConstantValue(eval_const_expr(cx.tcx, &**expr))),
PatRange(ref lo, ref hi) =>
ast::PatRange(ref lo, ref hi) =>
vec!(ConstantRange(eval_const_expr(cx.tcx, &**lo), eval_const_expr(cx.tcx, &**hi))),
PatVec(ref before, ref slice, ref after) =>
ast::PatVec(ref before, ref slice, ref after) =>
match ty::get(left_ty).sty {
ty::ty_vec(_, Some(_)) => vec!(Single),
_ => if slice.is_some() {
@ -679,11 +681,11 @@ fn pat_constructors(cx: &MatchCheckCtxt, p: &Pat,
vec!(Slice(before.len() + after.len()))
}
},
PatBox(_) | PatTup(_) | PatRegion(..) =>
ast::PatBox(_) | ast::PatTup(_) | ast::PatRegion(..) =>
vec!(Single),
PatWild(_) =>
ast::PatWild(_) =>
vec!(),
PatMac(_) =>
ast::PatMac(_) =>
cx.tcx.sess.bug("unexpanded macro")
}
}
@ -747,12 +749,11 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
let &Pat {
id: pat_id, ref node, span: pat_span
} = raw_pat(r[col]);
let head: Option<Vec<&Pat>> = match node {
&PatWild(_) =>
let head: Option<Vec<&Pat>> = match *node {
ast::PatWild(_) =>
Some(Vec::from_elem(arity, DUMMY_WILD_PAT)),
&PatIdent(_, _, _) => {
ast::PatIdent(_, _, _) => {
let opt_def = cx.tcx.def_map.borrow().get(&pat_id).cloned();
match opt_def {
Some(DefConst(..)) =>
@ -767,7 +768,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
}
}
&PatEnum(_, ref args) => {
ast::PatEnum(_, ref args) => {
let def = cx.tcx.def_map.borrow()[pat_id].clone();
match def {
DefConst(..) =>
@ -784,7 +785,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
}
}
&PatStruct(_, ref pattern_fields, _) => {
ast::PatStruct(_, ref pattern_fields, _) => {
// Is this a struct or an enum variant?
let def = cx.tcx.def_map.borrow()[pat_id].clone();
let class_id = match def {
@ -820,13 +821,13 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
})
}
&PatTup(ref args) =>
ast::PatTup(ref args) =>
Some(args.iter().map(|p| &**p).collect()),
&PatBox(ref inner) | &PatRegion(ref inner) =>
ast::PatBox(ref inner) | ast::PatRegion(ref inner) =>
Some(vec![&**inner]),
&PatLit(ref expr) => {
ast::PatLit(ref expr) => {
let expr_value = eval_const_expr(cx.tcx, &**expr);
match range_covered_by_constructor(constructor, &expr_value, &expr_value) {
Some(true) => Some(vec![]),
@ -838,7 +839,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
}
}
&PatRange(ref from, ref to) => {
ast::PatRange(ref from, ref to) => {
let from_value = eval_const_expr(cx.tcx, &**from);
let to_value = eval_const_expr(cx.tcx, &**to);
match range_covered_by_constructor(constructor, &from_value, &to_value) {
@ -851,7 +852,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
}
}
&PatVec(ref before, ref slice, ref after) => {
ast::PatVec(ref before, ref slice, ref after) => {
match *constructor {
// Fixed-length vectors.
Single => {
@ -883,7 +884,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
}
}
&PatMac(_) => {
ast::PatMac(_) => {
cx.tcx.sess.span_err(pat_span, "unexpanded macro");
None
}
@ -895,12 +896,12 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
})
}
fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) {
fn check_local(cx: &mut MatchCheckCtxt, loc: &ast::Local) {
visit::walk_local(cx, loc);
let name = match loc.source {
LocalLet => "local",
LocalFor => "`for` loop"
ast::LocalLet => "local",
ast::LocalFor => "`for` loop"
};
let mut static_inliner = StaticInliner::new(cx.tcx);
@ -918,8 +919,8 @@ fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) {
fn check_fn(cx: &mut MatchCheckCtxt,
kind: FnKind,
decl: &FnDecl,
body: &Block,
decl: &ast::FnDecl,
body: &ast::Block,
sp: Span,
_: NodeId) {
visit::walk_fn(cx, kind, decl, body, sp);
@ -957,10 +958,10 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
for pat in pats.iter() {
pat_bindings(def_map, &**pat, |bm, _, span, _path| {
match bm {
BindByRef(_) => {
ast::BindByRef(_) => {
by_ref_span = Some(span);
}
BindByValue(_) => {
ast::BindByValue(_) => {
}
}
})
@ -985,13 +986,13 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
walk_pat(&**pat, |p| {
if pat_is_binding(def_map, &*p) {
match p.node {
PatIdent(BindByValue(_), _, ref sub) => {
ast::PatIdent(ast::BindByValue(_), _, ref sub) => {
let pat_ty = ty::node_id_to_type(tcx, p.id);
if ty::type_moves_by_default(tcx, pat_ty) {
check_move(p, sub.as_ref().map(|p| &**p));
}
}
PatIdent(BindByRef(_), _, _) => {
ast::PatIdent(ast::BindByRef(_), _, _) => {
}
_ => {
cx.tcx.sess.span_bug(
@ -1010,7 +1011,8 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
/// Ensures that a pattern guard doesn't borrow by mutable reference or
/// assign.
fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>, guard: &Expr) {
fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
guard: &ast::Expr) {
let mut checker = MutationChecker {
cx: cx,
};
@ -1078,7 +1080,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
}
match pat.node {
PatIdent(_, _, Some(_)) => {
ast::PatIdent(_, _, Some(_)) => {
let bindings_were_allowed = self.bindings_allowed;
self.bindings_allowed = false;
visit::walk_pat(self, pat);

View File

@ -23,12 +23,12 @@ use middle::typeck::astconv;
use middle::typeck::check;
use util::nodemap::{DefIdMap};
use syntax::ast::*;
use syntax::ast::{mod, Expr};
use syntax::parse::token::InternedString;
use syntax::ptr::P;
use syntax::visit::Visitor;
use syntax::visit;
use syntax::{ast, ast_map, ast_util, codemap};
use syntax::{ast_map, ast_util, codemap};
use std::rc::Rc;
use std::collections::hash_map::Vacant;
@ -118,7 +118,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
match tcx.map.find(enum_def.node) {
None => None,
Some(ast_map::NodeItem(it)) => match it.node {
ItemEnum(ast::EnumDef { ref variants }, _) => {
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
variant_expr(variants.as_slice(), variant_def.node)
}
_ => None
@ -136,7 +136,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def,
|a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
csearch::found(&ast::IIItem(ref item)) => match item.node {
ItemEnum(ast::EnumDef { ref variants }, _) => {
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
// NOTE this doesn't do the right thing, it compares inlined
// NodeId's to the original variant_def's NodeId, but they
// come from different crates, so they will likely never match.
@ -158,7 +158,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId)
match tcx.map.find(def_id.node) {
None => None,
Some(ast_map::NodeItem(it)) => match it.node {
ItemConst(_, ref const_expr) => {
ast::ItemConst(_, ref const_expr) => {
Some(&**const_expr)
}
_ => None
@ -176,7 +176,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId)
let expr_id = match csearch::maybe_get_item_ast(tcx, def_id,
|a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
csearch::found(&ast::IIItem(ref item)) => match item.node {
ItemConst(_, ref const_expr) => Some(const_expr.id),
ast::ItemConst(_, ref const_expr) => Some(const_expr.id),
_ => None
},
_ => None
@ -280,9 +280,9 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> {
}
impl<'a, 'tcx, 'v> Visitor<'v> for ConstEvalVisitor<'a, 'tcx> {
fn visit_ty(&mut self, t: &Ty) {
fn visit_ty(&mut self, t: &ast::Ty) {
match t.node {
TyFixedLengthVec(_, ref expr) => {
ast::TyFixedLengthVec(_, ref expr) => {
check::check_const_in_type(self.tcx, &**expr, ty::mk_uint());
}
_ => {}
@ -317,12 +317,12 @@ pub enum const_val {
const_bool(bool)
}
pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<ast::Pat> {
let pat = match expr.node {
ExprTup(ref exprs) =>
PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect()),
ast::ExprTup(ref exprs) =>
ast::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect()),
ExprCall(ref callee, ref args) => {
ast::ExprCall(ref callee, ref args) => {
let def = tcx.def_map.borrow()[callee.id].clone();
match tcx.def_map.borrow_mut().entry(expr.id) {
Vacant(entry) => { entry.set(def); }
@ -334,33 +334,33 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
_ => unreachable!()
};
let pats = args.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect();
PatEnum(path, Some(pats))
ast::PatEnum(path, Some(pats))
}
ExprStruct(ref path, ref fields, None) => {
ast::ExprStruct(ref path, ref fields, None) => {
let field_pats = fields.iter().map(|field| codemap::Spanned {
span: codemap::DUMMY_SP,
node: FieldPat {
node: ast::FieldPat {
ident: field.ident.node,
pat: const_expr_to_pat(tcx, &*field.expr),
is_shorthand: false,
},
}).collect();
PatStruct(path.clone(), field_pats, false)
ast::PatStruct(path.clone(), field_pats, false)
}
ExprVec(ref exprs) => {
ast::ExprVec(ref exprs) => {
let pats = exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr)).collect();
PatVec(pats, None, vec![])
ast::PatVec(pats, None, vec![])
}
ExprPath(ref path) => {
ast::ExprPath(ref path) => {
let opt_def = tcx.def_map.borrow().get(&expr.id).cloned();
match opt_def {
Some(def::DefStruct(..)) =>
PatStruct(path.clone(), vec![], false),
ast::PatStruct(path.clone(), vec![], false),
Some(def::DefVariant(..)) =>
PatEnum(path.clone(), None),
ast::PatEnum(path.clone(), None),
_ => {
match lookup_const(tcx, expr) {
Some(actual) => return const_expr_to_pat(tcx, actual),
@ -370,9 +370,9 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<Pat> {
}
}
_ => PatLit(P(expr.clone()))
_ => ast::PatLit(P(expr.clone()))
};
P(Pat { id: expr.id, node: pat, span: expr.span })
P(ast::Pat { id: expr.id, node: pat, span: expr.span })
}
pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val {
@ -385,7 +385,7 @@ pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val {
pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, String> {
fn fromb(b: bool) -> Result<const_val, String> { Ok(const_int(b as i64)) }
match e.node {
ExprUnary(UnNeg, ref inner) => {
ast::ExprUnary(ast::UnNeg, ref inner) => {
match eval_const_expr_partial(tcx, &**inner) {
Ok(const_float(f)) => Ok(const_float(-f)),
Ok(const_int(i)) => Ok(const_int(-i)),
@ -395,7 +395,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
ref err => ((*err).clone())
}
}
ExprUnary(UnNot, ref inner) => {
ast::ExprUnary(ast::UnNot, ref inner) => {
match eval_const_expr_partial(tcx, &**inner) {
Ok(const_int(i)) => Ok(const_int(!i)),
Ok(const_uint(i)) => Ok(const_uint(!i)),
@ -403,110 +403,110 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
_ => Err("not on float or string".to_string())
}
}
ExprBinary(op, ref a, ref b) => {
ast::ExprBinary(op, ref a, ref b) => {
match (eval_const_expr_partial(tcx, &**a),
eval_const_expr_partial(tcx, &**b)) {
(Ok(const_float(a)), Ok(const_float(b))) => {
match op {
BiAdd => Ok(const_float(a + b)),
BiSub => Ok(const_float(a - b)),
BiMul => Ok(const_float(a * b)),
BiDiv => Ok(const_float(a / b)),
BiRem => Ok(const_float(a % b)),
BiEq => fromb(a == b),
BiLt => fromb(a < b),
BiLe => fromb(a <= b),
BiNe => fromb(a != b),
BiGe => fromb(a >= b),
BiGt => fromb(a > b),
ast::BiAdd => Ok(const_float(a + b)),
ast::BiSub => Ok(const_float(a - b)),
ast::BiMul => Ok(const_float(a * b)),
ast::BiDiv => Ok(const_float(a / b)),
ast::BiRem => Ok(const_float(a % b)),
ast::BiEq => fromb(a == b),
ast::BiLt => fromb(a < b),
ast::BiLe => fromb(a <= b),
ast::BiNe => fromb(a != b),
ast::BiGe => fromb(a >= b),
ast::BiGt => fromb(a > b),
_ => Err("can't do this op on floats".to_string())
}
}
(Ok(const_int(a)), Ok(const_int(b))) => {
match op {
BiAdd => Ok(const_int(a + b)),
BiSub => Ok(const_int(a - b)),
BiMul => Ok(const_int(a * b)),
BiDiv if b == 0 => {
ast::BiAdd => Ok(const_int(a + b)),
ast::BiSub => Ok(const_int(a - b)),
ast::BiMul => Ok(const_int(a * b)),
ast::BiDiv if b == 0 => {
Err("attempted to divide by zero".to_string())
}
BiDiv => Ok(const_int(a / b)),
BiRem if b == 0 => {
ast::BiDiv => Ok(const_int(a / b)),
ast::BiRem if b == 0 => {
Err("attempted remainder with a divisor of \
zero".to_string())
}
BiRem => Ok(const_int(a % b)),
BiAnd | BiBitAnd => Ok(const_int(a & b)),
BiOr | BiBitOr => Ok(const_int(a | b)),
BiBitXor => Ok(const_int(a ^ b)),
BiShl => Ok(const_int(a << b as uint)),
BiShr => Ok(const_int(a >> b as uint)),
BiEq => fromb(a == b),
BiLt => fromb(a < b),
BiLe => fromb(a <= b),
BiNe => fromb(a != b),
BiGe => fromb(a >= b),
BiGt => fromb(a > b)
ast::BiRem => Ok(const_int(a % b)),
ast::BiAnd | ast::BiBitAnd => Ok(const_int(a & b)),
ast::BiOr | ast::BiBitOr => Ok(const_int(a | b)),
ast::BiBitXor => Ok(const_int(a ^ b)),
ast::BiShl => Ok(const_int(a << b as uint)),
ast::BiShr => Ok(const_int(a >> b as uint)),
ast::BiEq => fromb(a == b),
ast::BiLt => fromb(a < b),
ast::BiLe => fromb(a <= b),
ast::BiNe => fromb(a != b),
ast::BiGe => fromb(a >= b),
ast::BiGt => fromb(a > b)
}
}
(Ok(const_uint(a)), Ok(const_uint(b))) => {
match op {
BiAdd => Ok(const_uint(a + b)),
BiSub => Ok(const_uint(a - b)),
BiMul => Ok(const_uint(a * b)),
BiDiv if b == 0 => {
ast::BiAdd => Ok(const_uint(a + b)),
ast::BiSub => Ok(const_uint(a - b)),
ast::BiMul => Ok(const_uint(a * b)),
ast::BiDiv if b == 0 => {
Err("attempted to divide by zero".to_string())
}
BiDiv => Ok(const_uint(a / b)),
BiRem if b == 0 => {
ast::BiDiv => Ok(const_uint(a / b)),
ast::BiRem if b == 0 => {
Err("attempted remainder with a divisor of \
zero".to_string())
}
BiRem => Ok(const_uint(a % b)),
BiAnd | BiBitAnd => Ok(const_uint(a & b)),
BiOr | BiBitOr => Ok(const_uint(a | b)),
BiBitXor => Ok(const_uint(a ^ b)),
BiShl => Ok(const_uint(a << b as uint)),
BiShr => Ok(const_uint(a >> b as uint)),
BiEq => fromb(a == b),
BiLt => fromb(a < b),
BiLe => fromb(a <= b),
BiNe => fromb(a != b),
BiGe => fromb(a >= b),
BiGt => fromb(a > b),
ast::BiRem => Ok(const_uint(a % b)),
ast::BiAnd | ast::BiBitAnd => Ok(const_uint(a & b)),
ast::BiOr | ast::BiBitOr => Ok(const_uint(a | b)),
ast::BiBitXor => Ok(const_uint(a ^ b)),
ast::BiShl => Ok(const_uint(a << b as uint)),
ast::BiShr => Ok(const_uint(a >> b as uint)),
ast::BiEq => fromb(a == b),
ast::BiLt => fromb(a < b),
ast::BiLe => fromb(a <= b),
ast::BiNe => fromb(a != b),
ast::BiGe => fromb(a >= b),
ast::BiGt => fromb(a > b),
}
}
// shifts can have any integral type as their rhs
(Ok(const_int(a)), Ok(const_uint(b))) => {
match op {
BiShl => Ok(const_int(a << b as uint)),
BiShr => Ok(const_int(a >> b as uint)),
ast::BiShl => Ok(const_int(a << b as uint)),
ast::BiShr => Ok(const_int(a >> b as uint)),
_ => Err("can't do this op on an int and uint".to_string())
}
}
(Ok(const_uint(a)), Ok(const_int(b))) => {
match op {
BiShl => Ok(const_uint(a << b as uint)),
BiShr => Ok(const_uint(a >> b as uint)),
ast::BiShl => Ok(const_uint(a << b as uint)),
ast::BiShr => Ok(const_uint(a >> b as uint)),
_ => Err("can't do this op on a uint and int".to_string())
}
}
(Ok(const_bool(a)), Ok(const_bool(b))) => {
Ok(const_bool(match op {
BiAnd => a && b,
BiOr => a || b,
BiBitXor => a ^ b,
BiBitAnd => a & b,
BiBitOr => a | b,
BiEq => a == b,
BiNe => a != b,
ast::BiAnd => a && b,
ast::BiOr => a || b,
ast::BiBitXor => a ^ b,
ast::BiBitAnd => a & b,
ast::BiBitOr => a | b,
ast::BiEq => a == b,
ast::BiNe => a != b,
_ => return Err("can't do this op on bools".to_string())
}))
}
_ => Err("bad operands for binary".to_string())
}
}
ExprCast(ref base, ref target_ty) => {
ast::ExprCast(ref base, ref target_ty) => {
// This tends to get called w/o the type actually having been
// populated in the ctxt, which was causing things to blow up
// (#5900). Fall back to doing a limited lookup to get past it.
@ -556,15 +556,15 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
ty::ty_float(ast::TyF64) => (f64, const_float, f64)
}))
}
ExprPath(_) => {
ast::ExprPath(_) => {
match lookup_const(tcx, e) {
Some(actual_e) => eval_const_expr_partial(tcx, &*actual_e),
None => Err("non-constant path in constant expr".to_string())
}
}
ExprLit(ref lit) => Ok(lit_to_const(&**lit)),
ExprParen(ref e) => eval_const_expr_partial(tcx, &**e),
ExprBlock(ref block) => {
ast::ExprLit(ref lit) => Ok(lit_to_const(&**lit)),
ast::ExprParen(ref e) => eval_const_expr_partial(tcx, &**e),
ast::ExprBlock(ref block) => {
match block.expr {
Some(ref expr) => eval_const_expr_partial(tcx, &**expr),
None => Ok(const_int(0i64))
@ -574,24 +574,24 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
}
}
pub fn lit_to_const(lit: &Lit) -> const_val {
pub fn lit_to_const(lit: &ast::Lit) -> const_val {
match lit.node {
LitStr(ref s, _) => const_str((*s).clone()),
LitBinary(ref data) => {
ast::LitStr(ref s, _) => const_str((*s).clone()),
ast::LitBinary(ref data) => {
const_binary(Rc::new(data.iter().map(|x| *x).collect()))
}
LitByte(n) => const_uint(n as u64),
LitChar(n) => const_uint(n as u64),
LitInt(n, ast::SignedIntLit(_, ast::Plus)) |
LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => const_int(n as i64),
LitInt(n, ast::SignedIntLit(_, ast::Minus)) |
LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => const_int(-(n as i64)),
LitInt(n, ast::UnsignedIntLit(_)) => const_uint(n),
LitFloat(ref n, _) |
LitFloatUnsuffixed(ref n) => {
ast::LitByte(n) => const_uint(n as u64),
ast::LitChar(n) => const_uint(n as u64),
ast::LitInt(n, ast::SignedIntLit(_, ast::Plus)) |
ast::LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => const_int(n as i64),
ast::LitInt(n, ast::SignedIntLit(_, ast::Minus)) |
ast::LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => const_int(-(n as i64)),
ast::LitInt(n, ast::UnsignedIntLit(_)) => const_uint(n),
ast::LitFloat(ref n, _) |
ast::LitFloatUnsuffixed(ref n) => {
const_float(from_str::<f64>(n.get()).unwrap() as f64)
}
LitBool(b) => const_bool(b)
ast::LitBool(b) => const_bool(b)
}
}

View File

@ -123,8 +123,7 @@ use std::fmt;
use std::io;
use std::rc::Rc;
use std::uint;
use syntax::ast;
use syntax::ast::*;
use syntax::ast::{mod, NodeId, Expr};
use syntax::codemap::{BytePos, original_sp, Span};
use syntax::parse::token::special_idents;
use syntax::parse::token;
@ -140,7 +139,7 @@ enum LoopKind<'a> {
/// A `while` loop, with the given expression as condition.
WhileLoop(&'a Expr),
/// A `for` loop, with the given pattern to bind.
ForLoop(&'a Pat),
ForLoop(&'a ast::Pat),
}
#[deriving(PartialEq)]
@ -187,12 +186,13 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, cx: &ty::ctxt) -> String {
}
impl<'a, 'tcx, 'v> Visitor<'v> for IrMaps<'a, 'tcx> {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, id: ast::NodeId) {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v ast::FnDecl,
b: &'v ast::Block, s: Span, id: NodeId) {
visit_fn(self, fk, fd, b, s, id);
}
fn visit_local(&mut self, l: &ast::Local) { visit_local(self, l); }
fn visit_expr(&mut self, ex: &Expr) { visit_expr(self, ex); }
fn visit_arm(&mut self, a: &Arm) { visit_arm(self, a); }
fn visit_arm(&mut self, a: &ast::Arm) { visit_arm(self, a); }
}
pub fn check_crate(tcx: &ty::ctxt) {
@ -250,12 +250,12 @@ struct CaptureInfo {
#[deriving(Show)]
struct LocalInfo {
id: NodeId,
ident: Ident
ident: ast::Ident
}
#[deriving(Show)]
enum VarKind {
Arg(NodeId, Ident),
Arg(NodeId, ast::Ident),
Local(LocalInfo),
ImplicitRet,
CleanExit
@ -354,7 +354,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
}
impl<'a, 'tcx, 'v> Visitor<'v> for Liveness<'a, 'tcx> {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, n: NodeId) {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v ast::FnDecl,
b: &'v ast::Block, s: Span, n: NodeId) {
check_fn(self, fk, fd, b, s, n);
}
fn visit_local(&mut self, l: &ast::Local) {
@ -363,15 +364,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Liveness<'a, 'tcx> {
fn visit_expr(&mut self, ex: &Expr) {
check_expr(self, ex);
}
fn visit_arm(&mut self, a: &Arm) {
fn visit_arm(&mut self, a: &ast::Arm) {
check_arm(self, a);
}
}
fn visit_fn(ir: &mut IrMaps,
fk: FnKind,
decl: &FnDecl,
body: &Block,
decl: &ast::FnDecl,
body: &ast::Block,
sp: Span,
id: ast::NodeId) {
debug!("visit_fn");
@ -429,7 +430,7 @@ fn visit_local(ir: &mut IrMaps, local: &ast::Local) {
visit::walk_local(ir, local);
}
fn visit_arm(ir: &mut IrMaps, arm: &Arm) {
fn visit_arm(ir: &mut IrMaps, arm: &ast::Arm) {
for pat in arm.pats.iter() {
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
debug!("adding local variable {} from match with bm {}",
@ -448,7 +449,7 @@ fn visit_arm(ir: &mut IrMaps, arm: &Arm) {
fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node {
// live nodes required for uses or definitions of variables:
ExprPath(_) => {
ast::ExprPath(_) => {
let def = ir.tcx.def_map.borrow()[expr.id].clone();
debug!("expr {}: path that leads to {}", expr.id, def);
match def {
@ -457,7 +458,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
}
visit::walk_expr(ir, expr);
}
ExprFnBlock(..) | ExprProc(..) | ExprUnboxedFn(..) => {
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) => {
// Interesting control flow (for loops can contain labeled
// breaks or continues)
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@ -485,17 +486,17 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
}
// live nodes required for interesting control flow:
ExprIf(..) | ExprMatch(..) | ExprWhile(..) | ExprLoop(..) => {
ast::ExprIf(..) | ast::ExprMatch(..) | ast::ExprWhile(..) | ast::ExprLoop(..) => {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::walk_expr(ir, expr);
}
ExprIfLet(..) => {
ast::ExprIfLet(..) => {
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ExprWhileLet(..) => {
ast::ExprWhileLet(..) => {
ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
}
ExprForLoop(ref pat, _, _, _) => {
ast::ExprForLoop(ref pat, _, _, _) => {
pat_util::pat_bindings(&ir.tcx.def_map, &**pat, |bm, p_id, sp, path1| {
debug!("adding local variable {} from for loop with bm {}",
p_id, bm);
@ -509,20 +510,21 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::walk_expr(ir, expr);
}
ExprBinary(op, _, _) if ast_util::lazy_binop(op) => {
ast::ExprBinary(op, _, _) if ast_util::lazy_binop(op) => {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
visit::walk_expr(ir, expr);
}
// otherwise, live nodes are not required:
ExprIndex(..) | ExprField(..) | ExprTupField(..) | ExprVec(..) |
ExprCall(..) | ExprMethodCall(..) | ExprTup(..) | ExprSlice(..) |
ExprBinary(..) | ExprAddrOf(..) |
ExprCast(..) | ExprUnary(..) | ExprBreak(_) |
ExprAgain(_) | ExprLit(_) | ExprRet(..) | ExprBlock(..) |
ExprAssign(..) | ExprAssignOp(..) | ExprMac(..) |
ExprStruct(..) | ExprRepeat(..) | ExprParen(..) |
ExprInlineAsm(..) | ExprBox(..) => {
ast::ExprIndex(..) | ast::ExprField(..) | ast::ExprTupField(..) |
ast::ExprVec(..) | ast::ExprCall(..) | ast::ExprMethodCall(..) |
ast::ExprTup(..) | ast::ExprBinary(..) | ast::ExprAddrOf(..) |
ast::ExprCast(..) | ast::ExprUnary(..) | ast::ExprBreak(_) |
ast::ExprAgain(_) | ast::ExprLit(_) | ast::ExprRet(..) |
ast::ExprBlock(..) | ast::ExprAssign(..) | ast::ExprAssignOp(..) |
ast::ExprMac(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) |
ast::ExprParen(..) | ast::ExprInlineAsm(..) | ast::ExprBox(..) |
ast::ExprSlice(..) => {
visit::walk_expr(ir, expr);
}
}
@ -611,7 +613,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
fn pat_bindings(&mut self,
pat: &Pat,
pat: &ast::Pat,
f: |&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId|) {
pat_util::pat_bindings(&self.ir.tcx.def_map, pat, |_bm, p_id, sp, _n| {
let ln = self.live_node(p_id, sp);
@ -621,7 +623,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
fn arm_pats_bindings(&mut self,
pat: Option<&Pat>,
pat: Option<&ast::Pat>,
f: |&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId|) {
match pat {
Some(pat) => {
@ -631,12 +633,12 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
fn define_bindings_in_pat(&mut self, pat: &Pat, succ: LiveNode)
fn define_bindings_in_pat(&mut self, pat: &ast::Pat, succ: LiveNode)
-> LiveNode {
self.define_bindings_in_arm_pats(Some(pat), succ)
}
fn define_bindings_in_arm_pats(&mut self, pat: Option<&Pat>, succ: LiveNode)
fn define_bindings_in_arm_pats(&mut self, pat: Option<&ast::Pat>, succ: LiveNode)
-> LiveNode {
let mut succ = succ;
self.arm_pats_bindings(pat, |this, ln, var, _sp, _id| {
@ -711,7 +713,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
fn find_loop_scope(&self,
opt_label: Option<Ident>,
opt_label: Option<ast::Ident>,
id: NodeId,
sp: Span)
-> NodeId {
@ -846,7 +848,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// _______________________________________________________________________
fn compute(&mut self, decl: &FnDecl, body: &Block) -> LiveNode {
fn compute(&mut self, decl: &ast::FnDecl, body: &ast::Block) -> LiveNode {
// if there is a `break` or `again` at the top level, then it's
// effectively a return---this only occurs in `for` loops,
// where the body is really a closure.
@ -871,7 +873,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
entry_ln
}
fn propagate_through_fn_block(&mut self, _: &FnDecl, blk: &Block)
fn propagate_through_fn_block(&mut self, _: &ast::FnDecl, blk: &ast::Block)
-> LiveNode {
// the fallthrough exit is only for those cases where we do not
// explicitly return:
@ -885,7 +887,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_block(blk, s.fallthrough_ln)
}
fn propagate_through_block(&mut self, blk: &Block, succ: LiveNode)
fn propagate_through_block(&mut self, blk: &ast::Block, succ: LiveNode)
-> LiveNode {
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
blk.stmts.iter().rev().fold(succ, |succ, stmt| {
@ -893,30 +895,30 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
})
}
fn propagate_through_stmt(&mut self, stmt: &Stmt, succ: LiveNode)
fn propagate_through_stmt(&mut self, stmt: &ast::Stmt, succ: LiveNode)
-> LiveNode {
match stmt.node {
StmtDecl(ref decl, _) => {
ast::StmtDecl(ref decl, _) => {
self.propagate_through_decl(&**decl, succ)
}
StmtExpr(ref expr, _) | StmtSemi(ref expr, _) => {
ast::StmtExpr(ref expr, _) | ast::StmtSemi(ref expr, _) => {
self.propagate_through_expr(&**expr, succ)
}
StmtMac(..) => {
ast::StmtMac(..) => {
self.ir.tcx.sess.span_bug(stmt.span, "unexpanded macro");
}
}
}
fn propagate_through_decl(&mut self, decl: &Decl, succ: LiveNode)
fn propagate_through_decl(&mut self, decl: &ast::Decl, succ: LiveNode)
-> LiveNode {
match decl.node {
DeclLocal(ref local) => {
ast::DeclLocal(ref local) => {
self.propagate_through_local(&**local, succ)
}
DeclItem(_) => succ,
ast::DeclItem(_) => succ,
}
}
@ -961,21 +963,21 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
match expr.node {
// Interesting cases with control flow or which gen/kill
ExprPath(_) => {
ast::ExprPath(_) => {
self.access_path(expr, succ, ACC_READ | ACC_USE)
}
ExprField(ref e, _, _) => {
ast::ExprField(ref e, _, _) => {
self.propagate_through_expr(&**e, succ)
}
ExprTupField(ref e, _, _) => {
ast::ExprTupField(ref e, _, _) => {
self.propagate_through_expr(&**e, succ)
}
ExprFnBlock(_, _, ref blk) |
ExprProc(_, ref blk) |
ExprUnboxedFn(_, _, _, ref blk) => {
ast::ExprFnBlock(_, _, ref blk) |
ast::ExprProc(_, ref blk) |
ast::ExprUnboxedFn(_, _, _, ref blk) => {
debug!("{} is an ExprFnBlock, ExprProc, or ExprUnboxedFn",
expr_to_string(expr));
@ -1003,7 +1005,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
})
}
ExprIf(ref cond, ref then, ref els) => {
ast::ExprIf(ref cond, ref then, ref els) => {
//
// (cond)
// |
@ -1025,30 +1027,30 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**cond, ln)
}
ExprIfLet(..) => {
ast::ExprIfLet(..) => {
self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ExprWhile(ref cond, ref blk, _) => {
ast::ExprWhile(ref cond, ref blk, _) => {
self.propagate_through_loop(expr, WhileLoop(&**cond), &**blk, succ)
}
ExprWhileLet(..) => {
ast::ExprWhileLet(..) => {
self.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
}
ExprForLoop(ref pat, ref head, ref blk, _) => {
ast::ExprForLoop(ref pat, ref head, ref blk, _) => {
let ln = self.propagate_through_loop(expr, ForLoop(&**pat), &**blk, succ);
self.propagate_through_expr(&**head, ln)
}
// Note that labels have been resolved, so we don't need to look
// at the label ident
ExprLoop(ref blk, _) => {
ast::ExprLoop(ref blk, _) => {
self.propagate_through_loop(expr, LoopLoop, &**blk, succ)
}
ExprMatch(ref e, ref arms, _) => {
ast::ExprMatch(ref e, ref arms, _) => {
//
// (e)
// |
@ -1083,13 +1085,13 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**e, ln)
}
ExprRet(ref o_e) => {
ast::ExprRet(ref o_e) => {
// ignore succ and subst exit_ln:
let exit_ln = self.s.exit_ln;
self.propagate_through_opt_expr(o_e.as_ref().map(|e| &**e), exit_ln)
}
ExprBreak(opt_label) => {
ast::ExprBreak(opt_label) => {
// Find which label this break jumps to
let sc = self.find_loop_scope(opt_label, expr.id, expr.span);
@ -1103,7 +1105,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
ExprAgain(opt_label) => {
ast::ExprAgain(opt_label) => {
// Find which label this expr continues to
let sc = self.find_loop_scope(opt_label, expr.id, expr.span);
@ -1117,7 +1119,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
ExprAssign(ref l, ref r) => {
ast::ExprAssign(ref l, ref r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
let succ = self.write_lvalue(&**l, succ, ACC_WRITE);
@ -1125,7 +1127,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**r, succ)
}
ExprAssignOp(_, ref l, ref r) => {
ast::ExprAssignOp(_, ref l, ref r) => {
// see comment on lvalues in
// propagate_through_lvalue_components()
let succ = self.write_lvalue(&**l, succ, ACC_WRITE|ACC_READ);
@ -1135,23 +1137,23 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// Uninteresting cases: just propagate in rev exec order
ExprVec(ref exprs) => {
ast::ExprVec(ref exprs) => {
self.propagate_through_exprs(exprs.as_slice(), succ)
}
ExprRepeat(ref element, ref count) => {
ast::ExprRepeat(ref element, ref count) => {
let succ = self.propagate_through_expr(&**count, succ);
self.propagate_through_expr(&**element, succ)
}
ExprStruct(_, ref fields, ref with_expr) => {
ast::ExprStruct(_, ref fields, ref with_expr) => {
let succ = self.propagate_through_opt_expr(with_expr.as_ref().map(|e| &**e), succ);
fields.iter().rev().fold(succ, |succ, field| {
self.propagate_through_expr(&*field.expr, succ)
})
}
ExprCall(ref f, ref args) => {
ast::ExprCall(ref f, ref args) => {
let diverges = !self.ir.tcx.is_method_call(expr.id) && {
let t_ret = ty::ty_fn_ret(ty::expr_ty(self.ir.tcx, &**f));
t_ret == ty::FnDiverging
@ -1165,7 +1167,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**f, succ)
}
ExprMethodCall(_, _, ref args) => {
ast::ExprMethodCall(_, _, ref args) => {
let method_call = typeck::MethodCall::expr(expr.id);
let method_ty = self.ir.tcx.method_map.borrow().get(&method_call).unwrap().ty;
let diverges = ty::ty_fn_ret(method_ty) == ty::FnDiverging;
@ -1177,11 +1179,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_exprs(args.as_slice(), succ)
}
ExprTup(ref exprs) => {
ast::ExprTup(ref exprs) => {
self.propagate_through_exprs(exprs.as_slice(), succ)
}
ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
ast::ExprBinary(op, ref l, ref r) if ast_util::lazy_binop(op) => {
let r_succ = self.propagate_through_expr(&**r, succ);
let ln = self.live_node(expr.id, expr.span);
@ -1191,27 +1193,27 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
self.propagate_through_expr(&**l, ln)
}
ExprIndex(ref l, ref r) |
ExprBinary(_, ref l, ref r) |
ExprBox(ref l, ref r) => {
ast::ExprIndex(ref l, ref r) |
ast::ExprBinary(_, ref l, ref r) |
ast::ExprBox(ref l, ref r) => {
let r_succ = self.propagate_through_expr(&**r, succ);
self.propagate_through_expr(&**l, r_succ)
}
ExprSlice(ref e1, ref e2, ref e3, _) => {
ast::ExprSlice(ref e1, ref e2, ref e3, _) => {
let succ = e3.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ));
let succ = e2.as_ref().map_or(succ, |e| self.propagate_through_expr(&**e, succ));
self.propagate_through_expr(&**e1, succ)
}
ExprAddrOf(_, ref e) |
ExprCast(ref e, _) |
ExprUnary(_, ref e) |
ExprParen(ref e) => {
ast::ExprAddrOf(_, ref e) |
ast::ExprCast(ref e, _) |
ast::ExprUnary(_, ref e) |
ast::ExprParen(ref e) => {
self.propagate_through_expr(&**e, succ)
}
ExprInlineAsm(ref ia) => {
ast::ExprInlineAsm(ref ia) => {
let succ = ia.outputs.iter().rev().fold(succ, |succ, &(_, ref expr, _)| {
// see comment on lvalues
@ -1225,15 +1227,15 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
})
}
ExprLit(..) => {
ast::ExprLit(..) => {
succ
}
ExprBlock(ref blk) => {
ast::ExprBlock(ref blk) => {
self.propagate_through_block(&**blk, succ)
}
ExprMac(..) => {
ast::ExprMac(..) => {
self.ir.tcx.sess.span_bug(expr.span, "unexpanded macro");
}
}
@ -1293,9 +1295,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
// just ignore such cases and treat them as reads.
match expr.node {
ExprPath(_) => succ,
ExprField(ref e, _, _) => self.propagate_through_expr(&**e, succ),
ExprTupField(ref e, _, _) => self.propagate_through_expr(&**e, succ),
ast::ExprPath(_) => succ,
ast::ExprField(ref e, _, _) => self.propagate_through_expr(&**e, succ),
ast::ExprTupField(ref e, _, _) => self.propagate_through_expr(&**e, succ),
_ => self.propagate_through_expr(expr, succ)
}
}
@ -1304,7 +1306,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn write_lvalue(&mut self, expr: &Expr, succ: LiveNode, acc: uint)
-> LiveNode {
match expr.node {
ExprPath(_) => self.access_path(expr, succ, acc),
ast::ExprPath(_) => self.access_path(expr, succ, acc),
// We do not track other lvalues, so just propagate through
// to their subcomponents. Also, it may happen that
@ -1333,7 +1335,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn propagate_through_loop(&mut self,
expr: &Expr,
kind: LoopKind,
body: &Block,
body: &ast::Block,
succ: LiveNode)
-> LiveNode {
@ -1437,7 +1439,7 @@ fn check_local(this: &mut Liveness, local: &ast::Local) {
visit::walk_local(this, local);
}
fn check_arm(this: &mut Liveness, arm: &Arm) {
fn check_arm(this: &mut Liveness, arm: &ast::Arm) {
// only consider the first pattern; any later patterns must have
// the same bindings, and we also consider the first pattern to be
// the "authoritative" set of ids
@ -1449,20 +1451,20 @@ fn check_arm(this: &mut Liveness, arm: &Arm) {
fn check_expr(this: &mut Liveness, expr: &Expr) {
match expr.node {
ExprAssign(ref l, ref r) => {
ast::ExprAssign(ref l, ref r) => {
this.check_lvalue(&**l);
this.visit_expr(&**r);
visit::walk_expr(this, expr);
}
ExprAssignOp(_, ref l, _) => {
ast::ExprAssignOp(_, ref l, _) => {
this.check_lvalue(&**l);
visit::walk_expr(this, expr);
}
ExprInlineAsm(ref ia) => {
ast::ExprInlineAsm(ref ia) => {
for &(_, ref input) in ia.inputs.iter() {
this.visit_expr(&**input);
}
@ -1476,7 +1478,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
visit::walk_expr(this, expr);
}
ExprForLoop(ref pat, _, _, _) => {
ast::ExprForLoop(ref pat, _, _, _) => {
this.pat_bindings(&**pat, |this, ln, var, sp, id| {
this.warn_about_unused(sp, id, ln, var);
});
@ -1485,20 +1487,22 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
}
// no correctness conditions related to liveness
ExprCall(..) | ExprMethodCall(..) | ExprIf(..) | ExprMatch(..) |
ExprWhile(..) | ExprLoop(..) | ExprIndex(..) | ExprField(..) |
ExprTupField(..) | ExprVec(..) | ExprTup(..) | ExprBinary(..) |
ExprCast(..) | ExprUnary(..) | ExprRet(..) | ExprBreak(..) |
ExprAgain(..) | ExprLit(_) | ExprBlock(..) | ExprSlice(..) |
ExprMac(..) | ExprAddrOf(..) | ExprStruct(..) | ExprRepeat(..) |
ExprParen(..) | ExprFnBlock(..) | ExprProc(..) | ExprUnboxedFn(..) |
ExprPath(..) | ExprBox(..) => {
ast::ExprCall(..) | ast::ExprMethodCall(..) | ast::ExprIf(..) |
ast::ExprMatch(..) | ast::ExprWhile(..) | ast::ExprLoop(..) |
ast::ExprIndex(..) | ast::ExprField(..) | ast::ExprTupField(..) |
ast::ExprVec(..) | ast::ExprTup(..) | ast::ExprBinary(..) |
ast::ExprCast(..) | ast::ExprUnary(..) | ast::ExprRet(..) |
ast::ExprBreak(..) | ast::ExprAgain(..) | ast::ExprLit(_) |
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
ast::ExprFnBlock(..) | ast::ExprProc(..) | ast::ExprUnboxedFn(..) |
ast::ExprPath(..) | ast::ExprBox(..) | ast::ExprSlice(..) => {
visit::walk_expr(this, expr);
}
ExprIfLet(..) => {
ast::ExprIfLet(..) => {
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprIfLet");
}
ExprWhileLet(..) => {
ast::ExprWhileLet(..) => {
this.ir.tcx.sess.span_bug(expr.span, "non-desugared ExprWhileLet");
}
}
@ -1506,8 +1510,8 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
fn check_fn(_v: &Liveness,
_fk: FnKind,
_decl: &FnDecl,
_body: &Block,
_decl: &ast::FnDecl,
_body: &ast::Block,
_sp: Span,
_id: NodeId) {
// do not check contents of nested fns
@ -1534,7 +1538,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
sp: Span,
_fk: FnKind,
entry_ln: LiveNode,
body: &Block) {
body: &ast::Block) {
match self.fn_ret(id) {
ty::FnConverging(t_ret)
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
@ -1545,7 +1549,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
let ends_with_stmt = match body.expr {
None if body.stmts.len() > 0 =>
match body.stmts.last().unwrap().node {
StmtSemi(ref e, _) => {
ast::StmtSemi(ref e, _) => {
let t_stmt = ty::expr_ty(self.ir.tcx, &**e);
ty::get(t_stmt).sty == ty::get(t_ret).sty
},
@ -1581,7 +1585,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn check_lvalue(&mut self, expr: &Expr) {
match expr.node {
ExprPath(_) => {
ast::ExprPath(_) => {
match self.ir.tcx.def_map.borrow()[expr.id].clone() {
DefLocal(nid) => {
// Assignment to an immutable variable or argument: only legal
@ -1613,7 +1617,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
fn warn_about_unused_args(&self, decl: &FnDecl, entry_ln: LiveNode) {
fn warn_about_unused_args(&self, decl: &ast::FnDecl, entry_ln: LiveNode) {
for arg in decl.inputs.iter() {
pat_util::pat_bindings(&self.ir.tcx.def_map,
&*arg.pat,
@ -1628,7 +1632,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}
}
fn warn_about_unused_or_dead_vars_in_pat(&mut self, pat: &Pat) {
fn warn_about_unused_or_dead_vars_in_pat(&mut self, pat: &ast::Pat) {
self.pat_bindings(pat, |this, ln, var, sp, id| {
if !this.warn_about_unused(sp, id, ln, var) {
this.warn_about_dead_assign(sp, id, ln, var);

View File

@ -13,15 +13,15 @@ use middle::resolve;
use middle::ty;
use util::nodemap::FnvHashMap;
use syntax::ast::*;
use syntax::ast;
use syntax::ast_util::{walk_pat};
use syntax::codemap::{Span, DUMMY_SP};
pub type PatIdMap = FnvHashMap<Ident, NodeId>;
pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
// This is used because same-named variables in alternative patterns need to
// use the NodeId of their namesake in the first pattern.
pub fn pat_id_map(dm: &resolve::DefMap, pat: &Pat) -> PatIdMap {
pub fn pat_id_map(dm: &resolve::DefMap, pat: &ast::Pat) -> PatIdMap {
let mut map = FnvHashMap::new();
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
map.insert(path1.node, p_id);
@ -29,23 +29,27 @@ pub fn pat_id_map(dm: &resolve::DefMap, pat: &Pat) -> PatIdMap {
map
}
pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
match pat.node {
PatLit(_) | PatRange(_, _) => true,
PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => {
ast::PatLit(_) | ast::PatRange(_, _) => true,
ast::PatEnum(_, _) |
ast::PatIdent(_, _, None) |
ast::PatStruct(..) => {
match dm.borrow().get(&pat.id) {
Some(&DefVariant(..)) => true,
_ => false
}
}
PatVec(_, _, _) => true,
ast::PatVec(_, _, _) => true,
_ => false
}
}
pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
match pat.node {
PatEnum(_, _) | PatIdent(_, _, None) | PatStruct(..) => {
ast::PatEnum(_, _) |
ast::PatIdent(_, _, None) |
ast::PatStruct(..) => {
match dm.borrow().get(&pat.id) {
Some(&DefVariant(..)) | Some(&DefStruct(..)) => true,
_ => false
@ -55,9 +59,9 @@ pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &Pat) -> bool {
}
}
pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_const(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
match pat.node {
PatIdent(_, _, None) | PatEnum(..) => {
ast::PatIdent(_, _, None) | ast::PatEnum(..) => {
match dm.borrow().get(&pat.id) {
Some(&DefConst(..)) => true,
_ => false
@ -67,9 +71,9 @@ pub fn pat_is_const(dm: &resolve::DefMap, pat: &Pat) -> bool {
}
}
pub fn pat_is_binding(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_binding(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
match pat.node {
PatIdent(..) => {
ast::PatIdent(..) => {
!pat_is_variant_or_struct(dm, pat) &&
!pat_is_const(dm, pat)
}
@ -77,10 +81,10 @@ pub fn pat_is_binding(dm: &resolve::DefMap, pat: &Pat) -> bool {
}
}
pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
match pat.node {
PatIdent(..) => pat_is_binding(dm, pat),
PatWild(_) => true,
ast::PatIdent(..) => pat_is_binding(dm, pat),
ast::PatWild(_) => true,
_ => false
}
}
@ -88,11 +92,11 @@ pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &Pat) -> bool {
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
/// `match foo() { Some(a) => (), None => () }`
pub fn pat_bindings(dm: &resolve::DefMap,
pat: &Pat,
it: |BindingMode, NodeId, Span, &SpannedIdent|) {
pat: &ast::Pat,
it: |ast::BindingMode, ast::NodeId, Span, &ast::SpannedIdent|) {
walk_pat(pat, |p| {
match p.node {
PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
ast::PatIdent(binding_mode, ref pth, _) if pat_is_binding(dm, p) => {
it(binding_mode, p.id, p.span, pth);
}
_ => {}
@ -103,7 +107,7 @@ pub fn pat_bindings(dm: &resolve::DefMap,
/// Checks if the pattern contains any patterns that bind something to
/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &Pat) -> bool {
pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
let mut contains_bindings = false;
walk_pat(pat, |p| {
if pat_is_binding(dm, p) {
@ -116,9 +120,9 @@ pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &Pat) -> bool {
contains_bindings
}
pub fn simple_identifier<'a>(pat: &'a Pat) -> Option<&'a Ident> {
pub fn simple_identifier<'a>(pat: &'a ast::Pat) -> Option<&'a ast::Ident> {
match pat.node {
PatIdent(BindByValue(_), ref path1, None) => {
ast::PatIdent(ast::BindByValue(_), ref path1, None) => {
Some(&path1.node)
}
_ => {
@ -127,12 +131,12 @@ pub fn simple_identifier<'a>(pat: &'a Pat) -> Option<&'a Ident> {
}
}
pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
ty::with_path(tcx, id, |mut path| Path {
pub fn def_to_path(tcx: &ty::ctxt, id: ast::DefId) -> ast::Path {
ty::with_path(tcx, id, |mut path| ast::Path {
global: false,
segments: path.last().map(|elem| PathSegment {
identifier: Ident::new(elem.name()),
parameters: PathParameters::none(),
segments: path.last().map(|elem| ast::PathSegment {
identifier: ast::Ident::new(elem.name()),
parameters: ast::PathParameters::none(),
}).into_iter().collect(),
span: DUMMY_SP,
})