mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-01 09:33:26 +00:00
Auto merge of #28399 - nrc:attrs, r=nikomatsakis
This could be a [breaking-change] if your lint or syntax extension (is that even possible?) uses HIR attributes or literals.
This commit is contained in:
commit
fc4d566b43
@ -17,7 +17,7 @@ use metadata::inline::InlinedItem as II;
|
||||
use middle::def_id::DefId;
|
||||
|
||||
use syntax::abi;
|
||||
use syntax::ast::{Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
|
||||
use syntax::ast::{self, Name, NodeId, Ident, CRATE_NODE_ID, DUMMY_NODE_ID};
|
||||
use syntax::codemap::{Span, Spanned};
|
||||
use syntax::parse::token;
|
||||
|
||||
@ -538,7 +538,7 @@ impl<'ast> Map<'ast> {
|
||||
|
||||
/// Given a node ID, get a list of of attributes associated with the AST
|
||||
/// corresponding to the Node ID
|
||||
pub fn attrs(&self, id: NodeId) -> &'ast [Attribute] {
|
||||
pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] {
|
||||
let attrs = match self.find(id) {
|
||||
Some(NodeItem(i)) => Some(&i.attrs[..]),
|
||||
Some(NodeForeignItem(fi)) => Some(&fi.attrs[..]),
|
||||
|
@ -37,13 +37,13 @@ use std::cell::RefCell;
|
||||
use std::cmp;
|
||||
use std::mem;
|
||||
use syntax::ast_util::IdVisitingOperation;
|
||||
use rustc_front::attr::{self, AttrMetaMethods};
|
||||
use rustc_front::util;
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit::{self, Visitor, FnKind};
|
||||
use rustc_front::util;
|
||||
use syntax::visit::Visitor as SyntaxVisitor;
|
||||
use syntax::diagnostic;
|
||||
|
||||
@ -286,7 +286,7 @@ macro_rules! run_lints { ($cx:expr, $f:ident, $($args:expr),*) => ({
|
||||
/// Parse the lint attributes into a vector, with `Err`s for malformed lint
|
||||
/// attributes. Writing this as an iterator is an enormous mess.
|
||||
// See also the hir version just below.
|
||||
pub fn gather_attrs(attrs: &[hir::Attribute])
|
||||
pub fn gather_attrs(attrs: &[ast::Attribute])
|
||||
-> Vec<Result<(InternedString, Level, Span), Span>> {
|
||||
let mut out = vec!();
|
||||
for attr in attrs {
|
||||
@ -299,7 +299,7 @@ pub fn gather_attrs(attrs: &[hir::Attribute])
|
||||
|
||||
let meta = &attr.node.value;
|
||||
let metas = match meta.node {
|
||||
hir::MetaList(_, ref metas) => metas,
|
||||
ast::MetaList(_, ref metas) => metas,
|
||||
_ => {
|
||||
out.push(Err(meta.span));
|
||||
continue;
|
||||
@ -308,41 +308,7 @@ pub fn gather_attrs(attrs: &[hir::Attribute])
|
||||
|
||||
for meta in metas {
|
||||
out.push(match meta.node {
|
||||
hir::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
|
||||
_ => Err(meta.span),
|
||||
});
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
// Copy-pasted from the above function :-(
|
||||
pub fn gather_attrs_from_hir(attrs: &[::rustc_front::hir::Attribute])
|
||||
-> Vec<Result<(InternedString, Level, Span), Span>> {
|
||||
use ::rustc_front::attr::AttrMetaMethods;
|
||||
|
||||
let mut out = vec!();
|
||||
for attr in attrs {
|
||||
let level = match Level::from_str(&attr.name()) {
|
||||
None => continue,
|
||||
Some(lvl) => lvl,
|
||||
};
|
||||
|
||||
::rustc_front::attr::mark_used(attr);
|
||||
|
||||
let meta = &attr.node.value;
|
||||
let metas = match meta.node {
|
||||
::rustc_front::hir::MetaList(_, ref metas) => metas,
|
||||
_ => {
|
||||
out.push(Err(meta.span));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
for meta in metas {
|
||||
out.push(match meta.node {
|
||||
::rustc_front::hir::MetaWord(ref lint_name) => {
|
||||
Ok((lint_name.clone(), level, meta.span))
|
||||
}
|
||||
ast::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)),
|
||||
_ => Err(meta.span),
|
||||
});
|
||||
}
|
||||
@ -454,7 +420,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
|
||||
/// current lint context, call the provided function, then reset the
|
||||
/// lints in effect to their previous state.
|
||||
fn with_lint_attrs<F>(&mut self,
|
||||
attrs: &[hir::Attribute],
|
||||
attrs: &[ast::Attribute],
|
||||
f: F) where
|
||||
F: FnOnce(&mut Context),
|
||||
{
|
||||
@ -675,7 +641,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
|
||||
visit::walk_path(self, p);
|
||||
}
|
||||
|
||||
fn visit_attribute(&mut self, attr: &hir::Attribute) {
|
||||
fn visit_attribute(&mut self, attr: &ast::Attribute) {
|
||||
run_lints!(self, check_attribute, attr);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
|
||||
pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs,
|
||||
gather_attrs_from_hir, GatherNodeLevels};
|
||||
GatherNodeLevels};
|
||||
|
||||
/// Specification of a single lint.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@ -158,14 +158,14 @@ pub trait LintPass {
|
||||
fn check_explicit_self(&mut self, _: &Context, _: &hir::ExplicitSelf) { }
|
||||
fn check_mac(&mut self, _: &Context, _: &ast::Mac) { }
|
||||
fn check_path(&mut self, _: &Context, _: &hir::Path, _: ast::NodeId) { }
|
||||
fn check_attribute(&mut self, _: &Context, _: &hir::Attribute) { }
|
||||
fn check_attribute(&mut self, _: &Context, _: &ast::Attribute) { }
|
||||
|
||||
/// Called when entering a syntax node that can have lint attributes such
|
||||
/// as `#[allow(...)]`. Called with *all* the attributes of that node.
|
||||
fn enter_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
|
||||
fn enter_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
|
||||
|
||||
/// Counterpart to `enter_lint_attrs`.
|
||||
fn exit_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) { }
|
||||
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) { }
|
||||
}
|
||||
|
||||
/// A lint pass boxed up as a trait object.
|
||||
|
@ -33,13 +33,11 @@ use syntax::abi;
|
||||
use syntax::codemap::{self, Span, mk_sp, Pos};
|
||||
use syntax::parse;
|
||||
use syntax::attr;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::util::small_vector::SmallVector;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr as attr_front;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use rustc_front::lowering::unlower_attribute;
|
||||
use log;
|
||||
|
||||
pub struct LocalCrateReader<'a, 'b:'a> {
|
||||
@ -79,10 +77,9 @@ fn dump_crates(cstore: &CStore) {
|
||||
fn should_link(i: &ast::Item) -> bool {
|
||||
!attr::contains_name(&i.attrs, "no_link")
|
||||
}
|
||||
|
||||
// Dup for the hir
|
||||
fn should_link_hir(i: &hir::Item) -> bool {
|
||||
!attr_front::contains_name(&i.attrs, "no_link")
|
||||
!attr::contains_name(&i.attrs, "no_link")
|
||||
}
|
||||
|
||||
struct CrateInfo {
|
||||
@ -329,7 +326,7 @@ impl<'a> CrateReader<'a> {
|
||||
let attrs = decoder::get_crate_attributes(data);
|
||||
for attr in &attrs {
|
||||
if &attr.name()[..] == "staged_api" {
|
||||
match attr.node.value.node { hir::MetaWord(_) => return true, _ => (/*pass*/) }
|
||||
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -483,7 +480,7 @@ impl<'a> CrateReader<'a> {
|
||||
p.abort_if_errors();
|
||||
macros.push(ast::MacroDef {
|
||||
ident: name.ident(),
|
||||
attrs: attrs.iter().map(|a| unlower_attribute(a)).collect(),
|
||||
attrs: attrs,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: span,
|
||||
imported_from: Some(item.ident),
|
||||
|
@ -21,7 +21,7 @@ use util::nodemap::FnvHashMap;
|
||||
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
use rustc_front::attr;
|
||||
use syntax::attr;
|
||||
use rustc_front::hir;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -186,7 +186,7 @@ pub fn get_methods_if_impl(cstore: &cstore::CStore,
|
||||
|
||||
pub fn get_item_attrs(cstore: &cstore::CStore,
|
||||
def_id: DefId)
|
||||
-> Vec<hir::Attribute> {
|
||||
-> Vec<ast::Attribute> {
|
||||
let cdata = cstore.get_crate_data(def_id.krate);
|
||||
decoder::get_item_attrs(&*cdata, def_id.node)
|
||||
}
|
||||
@ -197,7 +197,7 @@ pub fn get_struct_field_names(cstore: &cstore::CStore, def: DefId) -> Vec<ast::N
|
||||
}
|
||||
|
||||
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: DefId) -> FnvHashMap<ast::NodeId,
|
||||
Vec<hir::Attribute>> {
|
||||
Vec<ast::Attribute>> {
|
||||
let cdata = cstore.get_crate_data(def.krate);
|
||||
decoder::get_struct_field_attrs(&*cdata)
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use std::rc::Rc;
|
||||
use std::path::PathBuf;
|
||||
use flate::Bytes;
|
||||
use syntax::ast;
|
||||
use rustc_front::attr;
|
||||
use syntax::attr;
|
||||
use syntax::codemap;
|
||||
use syntax::parse::token;
|
||||
use syntax::parse::token::IdentInterner;
|
||||
|
@ -16,7 +16,6 @@ pub use self::DefLike::*;
|
||||
use self::Family::*;
|
||||
|
||||
use front::map as ast_map;
|
||||
use rustc_front::print::pprust;
|
||||
use rustc_front::hir;
|
||||
|
||||
use back::svh::Svh;
|
||||
@ -46,12 +45,13 @@ use std::str;
|
||||
use rbml::reader;
|
||||
use rbml;
|
||||
use serialize::Decodable;
|
||||
use rustc_front::attr;
|
||||
use syntax::attr;
|
||||
use syntax::parse::token::{IdentInterner, special_idents};
|
||||
use syntax::parse::token;
|
||||
use syntax::ast;
|
||||
use syntax::abi;
|
||||
use syntax::codemap;
|
||||
use syntax::print::pprust;
|
||||
use syntax::ptr::P;
|
||||
|
||||
|
||||
@ -1041,7 +1041,7 @@ pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
|
||||
|
||||
pub fn get_item_attrs(cdata: Cmd,
|
||||
orig_node_id: ast::NodeId)
|
||||
-> Vec<hir::Attribute> {
|
||||
-> Vec<ast::Attribute> {
|
||||
// The attributes for a tuple struct are attached to the definition, not the ctor;
|
||||
// we assume that someone passing in a tuple struct ctor is actually wanting to
|
||||
// look at the definition
|
||||
@ -1051,7 +1051,7 @@ pub fn get_item_attrs(cdata: Cmd,
|
||||
get_attributes(item)
|
||||
}
|
||||
|
||||
pub fn get_struct_field_attrs(cdata: Cmd) -> FnvHashMap<ast::NodeId, Vec<hir::Attribute>> {
|
||||
pub fn get_struct_field_attrs(cdata: Cmd) -> FnvHashMap<ast::NodeId, Vec<ast::Attribute>> {
|
||||
let data = rbml::Doc::new(cdata.data());
|
||||
let fields = reader::get_doc(data, tag_struct_fields);
|
||||
reader::tagged_docs(fields, tag_struct_field).map(|field| {
|
||||
@ -1079,7 +1079,7 @@ pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId)
|
||||
})).collect()
|
||||
}
|
||||
|
||||
fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::MetaItem>> {
|
||||
fn get_meta_items(md: rbml::Doc) -> Vec<P<ast::MetaItem>> {
|
||||
reader::tagged_docs(md, tag_meta_item_word).map(|meta_item_doc| {
|
||||
let nd = reader::get_doc(meta_item_doc, tag_meta_item_name);
|
||||
let n = token::intern_and_get_ident(nd.as_str_slice());
|
||||
@ -1100,7 +1100,7 @@ fn get_meta_items(md: rbml::Doc) -> Vec<P<hir::MetaItem>> {
|
||||
})).collect()
|
||||
}
|
||||
|
||||
fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> {
|
||||
fn get_attributes(md: rbml::Doc) -> Vec<ast::Attribute> {
|
||||
match reader::maybe_get_doc(md, tag_attributes) {
|
||||
Some(attrs_d) => {
|
||||
reader::tagged_docs(attrs_d, tag_attribute).map(|attr_doc| {
|
||||
@ -1113,9 +1113,9 @@ fn get_attributes(md: rbml::Doc) -> Vec<hir::Attribute> {
|
||||
assert_eq!(meta_items.len(), 1);
|
||||
let meta_item = meta_items.into_iter().nth(0).unwrap();
|
||||
codemap::Spanned {
|
||||
node: hir::Attribute_ {
|
||||
node: ast::Attribute_ {
|
||||
id: attr::mk_attr_id(),
|
||||
style: hir::AttrOuter,
|
||||
style: ast::AttrOuter,
|
||||
value: meta_item,
|
||||
is_sugared_doc: is_sugared_doc,
|
||||
},
|
||||
@ -1139,7 +1139,7 @@ fn list_crate_attributes(md: rbml::Doc, hash: &Svh,
|
||||
write!(out, "\n\n")
|
||||
}
|
||||
|
||||
pub fn get_crate_attributes(data: &[u8]) -> Vec<hir::Attribute> {
|
||||
pub fn get_crate_attributes(data: &[u8]) -> Vec<ast::Attribute> {
|
||||
get_attributes(rbml::Doc::new(data))
|
||||
}
|
||||
|
||||
@ -1337,7 +1337,7 @@ pub fn get_plugin_registrar_fn(data: &[u8]) -> Option<ast::NodeId> {
|
||||
}
|
||||
|
||||
pub fn each_exported_macro<F>(data: &[u8], intr: &IdentInterner, mut f: F) where
|
||||
F: FnMut(ast::Name, Vec<hir::Attribute>, String) -> bool,
|
||||
F: FnMut(ast::Name, Vec<ast::Attribute>, String) -> bool,
|
||||
{
|
||||
let macros = reader::get_doc(rbml::Doc::new(data), tag_macro_defs);
|
||||
for macro_doc in reader::tagged_docs(macros, tag_macro_def) {
|
||||
|
@ -34,17 +34,17 @@ use std::io::prelude::*;
|
||||
use std::io::{Cursor, SeekFrom};
|
||||
use std::rc::Rc;
|
||||
use syntax::abi;
|
||||
use syntax::ast::{NodeId, Name, CRATE_NODE_ID, CrateNum};
|
||||
use syntax::ast::{self, NodeId, Name, CRATE_NODE_ID, CrateNum};
|
||||
use syntax::attr;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::diagnostic::SpanHandler;
|
||||
use syntax::parse::token::special_idents;
|
||||
use syntax;
|
||||
use rbml::writer::Encoder;
|
||||
|
||||
use rustc_front::hir as ast;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use front::map::{LinkedPath, PathElem, PathElems};
|
||||
use front::map as ast_map;
|
||||
|
||||
@ -272,7 +272,7 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
|
||||
fn encode_enum_variant_info(ecx: &EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
id: NodeId,
|
||||
vis: ast::Visibility,
|
||||
vis: hir::Visibility,
|
||||
index: &mut Vec<IndexEntry>) {
|
||||
debug!("encode_enum_variant_info(id={})", id);
|
||||
|
||||
@ -445,12 +445,12 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
|
||||
/// top-level items that are sub-items of the given item. Specifically:
|
||||
///
|
||||
/// * For newtype structs, iterates through the node ID of the constructor.
|
||||
fn each_auxiliary_node_id<F>(item: &ast::Item, callback: F) -> bool where
|
||||
fn each_auxiliary_node_id<F>(item: &hir::Item, callback: F) -> bool where
|
||||
F: FnOnce(NodeId) -> bool,
|
||||
{
|
||||
let mut continue_ = true;
|
||||
match item.node {
|
||||
ast::ItemStruct(ref struct_def, _) => {
|
||||
hir::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.is_empty() &&
|
||||
@ -496,12 +496,12 @@ fn encode_reexports(ecx: &EncodeContext,
|
||||
|
||||
fn encode_info_for_mod(ecx: &EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
md: &ast::Mod,
|
||||
md: &hir::Mod,
|
||||
attrs: &[ast::Attribute],
|
||||
id: NodeId,
|
||||
path: PathElems,
|
||||
name: Name,
|
||||
vis: ast::Visibility) {
|
||||
vis: hir::Visibility) {
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(rbml_w, DefId::local(id));
|
||||
encode_family(rbml_w, 'm');
|
||||
@ -519,7 +519,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
|
||||
true
|
||||
});
|
||||
|
||||
if let ast::ItemImpl(..) = item.node {
|
||||
if let hir::ItemImpl(..) = item.node {
|
||||
let (ident, did) = (item.ident, item.id);
|
||||
debug!("(encoding info for module) ... encoding impl {} ({}/{})",
|
||||
ident,
|
||||
@ -536,7 +536,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 == ast::Public {
|
||||
if vis == hir::Public {
|
||||
debug!("(encoding info for module) encoding reexports for {}", id);
|
||||
encode_reexports(ecx, rbml_w, id, path);
|
||||
}
|
||||
@ -546,26 +546,26 @@ fn encode_info_for_mod(ecx: &EncodeContext,
|
||||
}
|
||||
|
||||
fn encode_struct_field_family(rbml_w: &mut Encoder,
|
||||
visibility: ast::Visibility) {
|
||||
visibility: hir::Visibility) {
|
||||
encode_family(rbml_w, match visibility {
|
||||
ast::Public => 'g',
|
||||
ast::Inherited => 'N'
|
||||
hir::Public => 'g',
|
||||
hir::Inherited => 'N'
|
||||
});
|
||||
}
|
||||
|
||||
fn encode_visibility(rbml_w: &mut Encoder, visibility: ast::Visibility) {
|
||||
fn encode_visibility(rbml_w: &mut Encoder, visibility: hir::Visibility) {
|
||||
let ch = match visibility {
|
||||
ast::Public => 'y',
|
||||
ast::Inherited => 'i',
|
||||
hir::Public => 'y',
|
||||
hir::Inherited => 'i',
|
||||
};
|
||||
rbml_w.wr_tagged_u8(tag_items_data_item_visibility, ch as u8);
|
||||
}
|
||||
|
||||
fn encode_constness(rbml_w: &mut Encoder, constness: ast::Constness) {
|
||||
fn encode_constness(rbml_w: &mut Encoder, constness: hir::Constness) {
|
||||
rbml_w.start_tag(tag_items_data_item_constness);
|
||||
let ch = match constness {
|
||||
ast::Constness::Const => 'c',
|
||||
ast::Constness::NotConst => 'n',
|
||||
hir::Constness::Const => 'c',
|
||||
hir::Constness::NotConst => 'n',
|
||||
};
|
||||
rbml_w.wr_str(&ch.to_string());
|
||||
rbml_w.end_tag();
|
||||
@ -593,10 +593,10 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_mutability(m: ast::Mutability) -> u8 {
|
||||
fn encode_mutability(m: hir::Mutability) -> u8 {
|
||||
match m {
|
||||
ast::MutImmutable => 'i' as u8,
|
||||
ast::MutMutable => 'm' as u8,
|
||||
hir::MutImmutable => 'i' as u8,
|
||||
hir::MutMutable => 'm' as u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -784,7 +784,7 @@ fn encode_info_for_associated_const(ecx: &EncodeContext,
|
||||
associated_const: &ty::AssociatedConst,
|
||||
impl_path: PathElems,
|
||||
parent_id: NodeId,
|
||||
impl_item_opt: Option<&ast::ImplItem>) {
|
||||
impl_item_opt: Option<&hir::ImplItem>) {
|
||||
debug!("encode_info_for_associated_const({:?},{:?})",
|
||||
associated_const.def_id,
|
||||
associated_const.name);
|
||||
@ -822,7 +822,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
impl_path: PathElems,
|
||||
is_default_impl: bool,
|
||||
parent_id: NodeId,
|
||||
impl_item_opt: Option<&ast::ImplItem>) {
|
||||
impl_item_opt: Option<&hir::ImplItem>) {
|
||||
|
||||
debug!("encode_info_for_method: {:?} {:?}", m.def_id,
|
||||
m.name);
|
||||
@ -841,13 +841,13 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
let elem = ast_map::PathName(m.name);
|
||||
encode_path(rbml_w, impl_path.chain(Some(elem)));
|
||||
if let Some(impl_item) = impl_item_opt {
|
||||
if let ast::MethodImplItem(ref sig, _) = impl_item.node {
|
||||
if let hir::MethodImplItem(ref sig, _) = impl_item.node {
|
||||
encode_attributes(rbml_w, &impl_item.attrs);
|
||||
let scheme = ecx.tcx.lookup_item_type(m.def_id);
|
||||
let any_types = !scheme.generics.types.is_empty();
|
||||
let needs_inline = any_types || is_default_impl ||
|
||||
attr::requests_inline(&impl_item.attrs);
|
||||
if needs_inline || sig.constness == ast::Constness::Const {
|
||||
if needs_inline || sig.constness == hir::Constness::Const {
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(DefId::local(parent_id),
|
||||
impl_item));
|
||||
}
|
||||
@ -867,7 +867,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
associated_type: &ty::AssociatedType<'tcx>,
|
||||
impl_path: PathElems,
|
||||
parent_id: NodeId,
|
||||
impl_item_opt: Option<&ast::ImplItem>) {
|
||||
impl_item_opt: Option<&hir::ImplItem>) {
|
||||
debug!("encode_info_for_associated_type({:?},{:?})",
|
||||
associated_type.def_id,
|
||||
associated_type.name);
|
||||
@ -903,11 +903,11 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
fn encode_method_argument_names(rbml_w: &mut Encoder,
|
||||
decl: &ast::FnDecl) {
|
||||
decl: &hir::FnDecl) {
|
||||
rbml_w.start_tag(tag_method_argument_names);
|
||||
for arg in &decl.inputs {
|
||||
let tag = tag_method_argument_name;
|
||||
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
|
||||
if let hir::PatIdent(_, ref path1, _) = arg.pat.node {
|
||||
let name = path1.node.name.as_str();
|
||||
rbml_w.wr_tagged_bytes(tag, name.as_bytes());
|
||||
} else {
|
||||
@ -982,13 +982,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: &ast::Item,
|
||||
item: &hir::Item,
|
||||
index: &mut Vec<IndexEntry>,
|
||||
path: PathElems,
|
||||
vis: ast::Visibility) {
|
||||
vis: hir::Visibility) {
|
||||
let tcx = ecx.tcx;
|
||||
|
||||
fn add_to_index(item: &ast::Item, rbml_w: &mut Encoder,
|
||||
fn add_to_index(item: &hir::Item, rbml_w: &mut Encoder,
|
||||
index: &mut Vec<IndexEntry>) {
|
||||
index.push(IndexEntry {
|
||||
node: item.id,
|
||||
@ -1003,11 +1003,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
let stab = stability::lookup(tcx, DefId::local(item.id));
|
||||
|
||||
match item.node {
|
||||
ast::ItemStatic(_, m, _) => {
|
||||
hir::ItemStatic(_, m, _) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(rbml_w, def_id);
|
||||
if m == ast::MutMutable {
|
||||
if m == hir::MutMutable {
|
||||
encode_family(rbml_w, 'b');
|
||||
} else {
|
||||
encode_family(rbml_w, 'c');
|
||||
@ -1021,7 +1021,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_attributes(rbml_w, &item.attrs);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemConst(_, _) => {
|
||||
hir::ItemConst(_, _) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(rbml_w, def_id);
|
||||
@ -1035,7 +1035,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_stability(rbml_w, stab);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemFn(ref decl, _, constness, _, ref generics, _) => {
|
||||
hir::ItemFn(ref decl, _, constness, _, ref generics, _) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(rbml_w, def_id);
|
||||
@ -1046,7 +1046,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_path(rbml_w, path);
|
||||
encode_attributes(rbml_w, &item.attrs);
|
||||
let needs_inline = tps_len > 0 || attr::requests_inline(&item.attrs);
|
||||
if needs_inline || constness == ast::Constness::Const {
|
||||
if needs_inline || constness == hir::Constness::Const {
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
}
|
||||
if tps_len == 0 {
|
||||
@ -1058,7 +1058,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_method_argument_names(rbml_w, &**decl);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemMod(ref m) => {
|
||||
hir::ItemMod(ref m) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
encode_info_for_mod(ecx,
|
||||
rbml_w,
|
||||
@ -1069,7 +1069,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
item.ident.name,
|
||||
item.vis);
|
||||
}
|
||||
ast::ItemForeignMod(ref fm) => {
|
||||
hir::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);
|
||||
@ -1086,7 +1086,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_stability(rbml_w, stab);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemTy(..) => {
|
||||
hir::ItemTy(..) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(rbml_w, def_id);
|
||||
@ -1098,7 +1098,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_stability(rbml_w, stab);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemEnum(ref enum_definition, _) => {
|
||||
hir::ItemEnum(ref enum_definition, _) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
@ -1128,7 +1128,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
vis,
|
||||
index);
|
||||
}
|
||||
ast::ItemStruct(ref struct_def, _) => {
|
||||
hir::ItemStruct(ref struct_def, _) => {
|
||||
let def = ecx.tcx.lookup_adt_def(def_id);
|
||||
let variant = def.struct_variant();
|
||||
|
||||
@ -1174,7 +1174,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
ast::ItemDefaultImpl(unsafety, _) => {
|
||||
hir::ItemDefaultImpl(unsafety, _) => {
|
||||
add_to_index(item, rbml_w, index);
|
||||
rbml_w.start_tag(tag_items_data_item);
|
||||
encode_def_id(rbml_w, def_id);
|
||||
@ -1186,7 +1186,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
ast::ItemImpl(unsafety, polarity, _, _, ref ty, ref ast_items) => {
|
||||
hir::ItemImpl(unsafety, polarity, _, _, 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();
|
||||
@ -1212,7 +1212,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
}
|
||||
|
||||
match ty.node {
|
||||
ast::TyPath(None, ref path) if path.segments.len() == 1 => {
|
||||
hir::TyPath(None, ref path) if path.segments.len() == 1 => {
|
||||
let name = path.segments.last().unwrap().identifier.name;
|
||||
encode_impl_type_basename(rbml_w, name);
|
||||
}
|
||||
@ -1289,7 +1289,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::ItemTrait(_, _, _, ref ms) => {
|
||||
hir::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);
|
||||
@ -1429,11 +1429,11 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
let trait_item = &*ms[i];
|
||||
encode_attributes(rbml_w, &trait_item.attrs);
|
||||
match trait_item.node {
|
||||
ast::ConstTraitItem(_, _) => {
|
||||
hir::ConstTraitItem(_, _) => {
|
||||
encode_inlined_item(ecx, rbml_w,
|
||||
InlinedItemRef::TraitItem(def_id, trait_item));
|
||||
}
|
||||
ast::MethodTraitItem(ref sig, ref body) => {
|
||||
hir::MethodTraitItem(ref sig, ref body) => {
|
||||
// If this is a static method, we've already
|
||||
// encoded this.
|
||||
if is_nonstatic_method {
|
||||
@ -1453,13 +1453,13 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_method_argument_names(rbml_w, &sig.decl);
|
||||
}
|
||||
|
||||
ast::TypeTraitItem(..) => {}
|
||||
hir::TypeTraitItem(..) => {}
|
||||
}
|
||||
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
}
|
||||
ast::ItemExternCrate(_) | ast::ItemUse(_) => {
|
||||
hir::ItemExternCrate(_) | hir::ItemUse(_) => {
|
||||
// these are encoded separately
|
||||
}
|
||||
}
|
||||
@ -1467,7 +1467,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
|
||||
fn encode_info_for_foreign_item(ecx: &EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
nitem: &ast::ForeignItem,
|
||||
nitem: &hir::ForeignItem,
|
||||
index: &mut Vec<IndexEntry>,
|
||||
path: PathElems,
|
||||
abi: abi::Abi) {
|
||||
@ -1480,7 +1480,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
|
||||
encode_def_id(rbml_w, DefId::local(nitem.id));
|
||||
encode_visibility(rbml_w, nitem.vis);
|
||||
match nitem.node {
|
||||
ast::ForeignItemFn(ref fndecl, _) => {
|
||||
hir::ForeignItemFn(ref fndecl, _) => {
|
||||
encode_family(rbml_w, FN_FAMILY);
|
||||
encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id);
|
||||
encode_name(rbml_w, nitem.ident.name);
|
||||
@ -1493,7 +1493,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
|
||||
encode_symbol(ecx, rbml_w, nitem.id);
|
||||
encode_method_argument_names(rbml_w, &*fndecl);
|
||||
}
|
||||
ast::ForeignItemStatic(_, mutbl) => {
|
||||
hir::ForeignItemStatic(_, mutbl) => {
|
||||
if mutbl {
|
||||
encode_family(rbml_w, 'b');
|
||||
} else {
|
||||
@ -1511,9 +1511,9 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
fn my_visit_expr(_e: &ast::Expr) { }
|
||||
fn my_visit_expr(_e: &hir::Expr) { }
|
||||
|
||||
fn my_visit_item(i: &ast::Item,
|
||||
fn my_visit_item(i: &hir::Item,
|
||||
rbml_w: &mut Encoder,
|
||||
ecx: &EncodeContext,
|
||||
index: &mut Vec<IndexEntry>) {
|
||||
@ -1522,7 +1522,7 @@ fn my_visit_item(i: &ast::Item,
|
||||
});
|
||||
}
|
||||
|
||||
fn my_visit_foreign_item(ni: &ast::ForeignItem,
|
||||
fn my_visit_foreign_item(ni: &hir::ForeignItem,
|
||||
rbml_w: &mut Encoder,
|
||||
ecx: &EncodeContext,
|
||||
index: &mut Vec<IndexEntry>) {
|
||||
@ -1545,18 +1545,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: &ast::Expr) {
|
||||
fn visit_expr(&mut self, ex: &hir::Expr) {
|
||||
visit::walk_expr(self, ex);
|
||||
my_visit_expr(ex);
|
||||
}
|
||||
fn visit_item(&mut self, i: &ast::Item) {
|
||||
fn visit_item(&mut self, i: &hir::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: &ast::ForeignItem) {
|
||||
fn visit_foreign_item(&mut self, ni: &hir::ForeignItem) {
|
||||
visit::walk_foreign_item(self, ni);
|
||||
my_visit_foreign_item(ni,
|
||||
self.rbml_w_for_visit_item,
|
||||
@ -1567,7 +1567,7 @@ 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: &ast::Crate)
|
||||
krate: &hir::Crate)
|
||||
-> Vec<IndexEntry> {
|
||||
let mut index = Vec::new();
|
||||
rbml_w.start_tag(tag_items_data);
|
||||
@ -1582,7 +1582,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
|
||||
CRATE_NODE_ID,
|
||||
[].iter().cloned().chain(LinkedPath::empty()),
|
||||
syntax::parse::token::special_idents::invalid.name,
|
||||
ast::Public);
|
||||
hir::Public);
|
||||
|
||||
visit::walk_crate(&mut EncodeVisitor {
|
||||
index: &mut index,
|
||||
@ -1644,10 +1644,10 @@ fn encode_attributes(rbml_w: &mut Encoder, attrs: &[ast::Attribute]) {
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_unsafety(rbml_w: &mut Encoder, unsafety: ast::Unsafety) {
|
||||
fn encode_unsafety(rbml_w: &mut Encoder, unsafety: hir::Unsafety) {
|
||||
let byte: u8 = match unsafety {
|
||||
ast::Unsafety::Normal => 0,
|
||||
ast::Unsafety::Unsafe => 1,
|
||||
hir::Unsafety::Normal => 0,
|
||||
hir::Unsafety::Unsafe => 1,
|
||||
};
|
||||
rbml_w.wr_tagged_u8(tag_unsafety, byte);
|
||||
}
|
||||
@ -1670,10 +1670,10 @@ fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[Name]) {
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_polarity(rbml_w: &mut Encoder, polarity: ast::ImplPolarity) {
|
||||
fn encode_polarity(rbml_w: &mut Encoder, polarity: hir::ImplPolarity) {
|
||||
let byte: u8 = match polarity {
|
||||
ast::ImplPolarity::Positive => 0,
|
||||
ast::ImplPolarity::Negative => 1,
|
||||
hir::ImplPolarity::Positive => 0,
|
||||
hir::ImplPolarity::Negative => 1,
|
||||
};
|
||||
rbml_w.wr_tagged_u8(tag_polarity, byte);
|
||||
}
|
||||
@ -1782,7 +1782,7 @@ fn encode_codemap(ecx: &EncodeContext, rbml_w: &mut Encoder) {
|
||||
|
||||
/// Serialize the text of the exported macros
|
||||
fn encode_macro_defs(rbml_w: &mut Encoder,
|
||||
krate: &ast::Crate) {
|
||||
krate: &hir::Crate) {
|
||||
rbml_w.start_tag(tag_macro_defs);
|
||||
for def in &krate.exported_macros {
|
||||
rbml_w.start_tag(tag_macro_def);
|
||||
@ -1798,13 +1798,13 @@ fn encode_macro_defs(rbml_w: &mut Encoder,
|
||||
rbml_w.end_tag();
|
||||
}
|
||||
|
||||
fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &ast::Crate) {
|
||||
fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &hir::Crate) {
|
||||
struct StructFieldVisitor<'a, 'b:'a> {
|
||||
rbml_w: &'a mut Encoder<'b>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'v> Visitor<'v> for StructFieldVisitor<'a, 'b> {
|
||||
fn visit_struct_field(&mut self, field: &ast::StructField) {
|
||||
fn visit_struct_field(&mut self, field: &hir::StructField) {
|
||||
self.rbml_w.start_tag(tag_struct_field);
|
||||
self.rbml_w.wr_tagged_u32(tag_struct_field_id, field.node.id);
|
||||
encode_attributes(self.rbml_w, &field.node.attrs);
|
||||
@ -1827,8 +1827,8 @@ 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: &ast::Item) {
|
||||
if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
if let hir::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
|
||||
let def_id = self.ecx.tcx.def_map.borrow().get(&trait_ref.ref_id).unwrap().def_id();
|
||||
|
||||
// Load eagerly if this is an implementation of the Drop trait
|
||||
@ -1856,7 +1856,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: &ast::Crate,
|
||||
krate: &hir::Crate,
|
||||
rbml_w: &'a mut Encoder) {
|
||||
rbml_w.start_tag(tag_impls);
|
||||
|
||||
@ -1872,7 +1872,7 @@ fn encode_impls<'a>(ecx: &'a EncodeContext,
|
||||
}
|
||||
|
||||
fn encode_misc_info(ecx: &EncodeContext,
|
||||
krate: &ast::Crate,
|
||||
krate: &hir::Crate,
|
||||
rbml_w: &mut Encoder) {
|
||||
rbml_w.start_tag(tag_misc_info);
|
||||
rbml_w.start_tag(tag_misc_info_crate_items);
|
||||
@ -1956,7 +1956,7 @@ 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, 2 ];
|
||||
|
||||
pub fn encode_metadata(parms: EncodeParams, krate: &ast::Crate) -> Vec<u8> {
|
||||
pub fn encode_metadata(parms: EncodeParams, krate: &hir::Crate) -> Vec<u8> {
|
||||
let mut wr = Cursor::new(Vec::new());
|
||||
encode_metadata_inner(&mut wr, parms, krate);
|
||||
|
||||
@ -1995,7 +1995,7 @@ pub fn encode_metadata(parms: EncodeParams, krate: &ast::Crate) -> Vec<u8> {
|
||||
|
||||
fn encode_metadata_inner(wr: &mut Cursor<Vec<u8>>,
|
||||
parms: EncodeParams,
|
||||
krate: &ast::Crate) {
|
||||
krate: &hir::Crate) {
|
||||
struct Stats {
|
||||
attr_bytes: u64,
|
||||
dep_bytes: u64,
|
||||
|
@ -21,7 +21,6 @@ use syntax::attr;
|
||||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use rustc_front::attr::AttrMetaMethods as FrontAttrMetaMethods;
|
||||
|
||||
struct MacroLoader<'a> {
|
||||
sess: &'a Session,
|
||||
|
@ -27,6 +27,7 @@ use util::nodemap::FnvHashMap;
|
||||
use rustc_front::hir;
|
||||
|
||||
use syntax::abi::Abi;
|
||||
use syntax::ast;
|
||||
use syntax::diagnostic::SpanHandler;
|
||||
|
||||
use rbml::writer::Encoder;
|
||||
@ -65,26 +66,26 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
|
||||
ty::TyChar => mywrite!(w, "c"),
|
||||
ty::TyInt(t) => {
|
||||
match t {
|
||||
hir::TyIs => mywrite!(w, "is"),
|
||||
hir::TyI8 => mywrite!(w, "MB"),
|
||||
hir::TyI16 => mywrite!(w, "MW"),
|
||||
hir::TyI32 => mywrite!(w, "ML"),
|
||||
hir::TyI64 => mywrite!(w, "MD")
|
||||
ast::TyIs => mywrite!(w, "is"),
|
||||
ast::TyI8 => mywrite!(w, "MB"),
|
||||
ast::TyI16 => mywrite!(w, "MW"),
|
||||
ast::TyI32 => mywrite!(w, "ML"),
|
||||
ast::TyI64 => mywrite!(w, "MD")
|
||||
}
|
||||
}
|
||||
ty::TyUint(t) => {
|
||||
match t {
|
||||
hir::TyUs => mywrite!(w, "us"),
|
||||
hir::TyU8 => mywrite!(w, "Mb"),
|
||||
hir::TyU16 => mywrite!(w, "Mw"),
|
||||
hir::TyU32 => mywrite!(w, "Ml"),
|
||||
hir::TyU64 => mywrite!(w, "Md")
|
||||
ast::TyUs => mywrite!(w, "us"),
|
||||
ast::TyU8 => mywrite!(w, "Mb"),
|
||||
ast::TyU16 => mywrite!(w, "Mw"),
|
||||
ast::TyU32 => mywrite!(w, "Ml"),
|
||||
ast::TyU64 => mywrite!(w, "Md")
|
||||
}
|
||||
}
|
||||
ty::TyFloat(t) => {
|
||||
match t {
|
||||
hir::TyF32 => mywrite!(w, "Mf"),
|
||||
hir::TyF64 => mywrite!(w, "MF"),
|
||||
ast::TyF32 => mywrite!(w, "Mf"),
|
||||
ast::TyF64 => mywrite!(w, "MF"),
|
||||
}
|
||||
}
|
||||
ty::TyEnum(def, substs) => {
|
||||
|
@ -404,7 +404,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir:
|
||||
|
||||
fn const_val_to_expr(value: &ConstVal) -> P<hir::Expr> {
|
||||
let node = match value {
|
||||
&ConstVal::Bool(b) => hir::LitBool(b),
|
||||
&ConstVal::Bool(b) => ast::LitBool(b),
|
||||
_ => unreachable!()
|
||||
};
|
||||
P(hir::Expr {
|
||||
|
@ -466,35 +466,35 @@ pub enum IntTy { I8, I16, I32, I64 }
|
||||
pub enum UintTy { U8, U16, U32, U64 }
|
||||
|
||||
impl IntTy {
|
||||
pub fn from(tcx: &ty::ctxt, t: hir::IntTy) -> IntTy {
|
||||
let t = if let hir::TyIs = t {
|
||||
pub fn from(tcx: &ty::ctxt, t: ast::IntTy) -> IntTy {
|
||||
let t = if let ast::TyIs = t {
|
||||
tcx.sess.target.int_type
|
||||
} else {
|
||||
t
|
||||
};
|
||||
match t {
|
||||
hir::TyIs => unreachable!(),
|
||||
hir::TyI8 => IntTy::I8,
|
||||
hir::TyI16 => IntTy::I16,
|
||||
hir::TyI32 => IntTy::I32,
|
||||
hir::TyI64 => IntTy::I64,
|
||||
ast::TyIs => unreachable!(),
|
||||
ast::TyI8 => IntTy::I8,
|
||||
ast::TyI16 => IntTy::I16,
|
||||
ast::TyI32 => IntTy::I32,
|
||||
ast::TyI64 => IntTy::I64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UintTy {
|
||||
pub fn from(tcx: &ty::ctxt, t: hir::UintTy) -> UintTy {
|
||||
let t = if let hir::TyUs = t {
|
||||
pub fn from(tcx: &ty::ctxt, t: ast::UintTy) -> UintTy {
|
||||
let t = if let ast::TyUs = t {
|
||||
tcx.sess.target.uint_type
|
||||
} else {
|
||||
t
|
||||
};
|
||||
match t {
|
||||
hir::TyUs => unreachable!(),
|
||||
hir::TyU8 => UintTy::U8,
|
||||
hir::TyU16 => UintTy::U16,
|
||||
hir::TyU32 => UintTy::U32,
|
||||
hir::TyU64 => UintTy::U64,
|
||||
ast::TyUs => unreachable!(),
|
||||
ast::TyU8 => UintTy::U8,
|
||||
ast::TyU16 => UintTy::U16,
|
||||
ast::TyU32 => UintTy::U32,
|
||||
ast::TyU64 => UintTy::U64,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1141,60 +1141,60 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult {
|
||||
|
||||
// Issue #23890: If isize/usize, then dispatch to appropriate target representation type
|
||||
match (&ty.sty, tcx.sess.target.int_type, tcx.sess.target.uint_type) {
|
||||
(&ty::TyInt(hir::TyIs), hir::TyI32, _) => return convert_val!(i32, Int, i64),
|
||||
(&ty::TyInt(hir::TyIs), hir::TyI64, _) => return convert_val!(i64, Int, i64),
|
||||
(&ty::TyInt(hir::TyIs), _, _) => panic!("unexpected target.int_type"),
|
||||
(&ty::TyInt(ast::TyIs), ast::TyI32, _) => return convert_val!(i32, Int, i64),
|
||||
(&ty::TyInt(ast::TyIs), ast::TyI64, _) => return convert_val!(i64, Int, i64),
|
||||
(&ty::TyInt(ast::TyIs), _, _) => panic!("unexpected target.int_type"),
|
||||
|
||||
(&ty::TyUint(hir::TyUs), _, hir::TyU32) => return convert_val!(u32, Uint, u64),
|
||||
(&ty::TyUint(hir::TyUs), _, hir::TyU64) => return convert_val!(u64, Uint, u64),
|
||||
(&ty::TyUint(hir::TyUs), _, _) => panic!("unexpected target.uint_type"),
|
||||
(&ty::TyUint(ast::TyUs), _, ast::TyU32) => return convert_val!(u32, Uint, u64),
|
||||
(&ty::TyUint(ast::TyUs), _, ast::TyU64) => return convert_val!(u64, Uint, u64),
|
||||
(&ty::TyUint(ast::TyUs), _, _) => panic!("unexpected target.uint_type"),
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match ty.sty {
|
||||
ty::TyInt(hir::TyIs) => unreachable!(),
|
||||
ty::TyUint(hir::TyUs) => unreachable!(),
|
||||
ty::TyInt(ast::TyIs) => unreachable!(),
|
||||
ty::TyUint(ast::TyUs) => unreachable!(),
|
||||
|
||||
ty::TyInt(hir::TyI8) => convert_val!(i8, Int, i64),
|
||||
ty::TyInt(hir::TyI16) => convert_val!(i16, Int, i64),
|
||||
ty::TyInt(hir::TyI32) => convert_val!(i32, Int, i64),
|
||||
ty::TyInt(hir::TyI64) => convert_val!(i64, Int, i64),
|
||||
ty::TyInt(ast::TyI8) => convert_val!(i8, Int, i64),
|
||||
ty::TyInt(ast::TyI16) => convert_val!(i16, Int, i64),
|
||||
ty::TyInt(ast::TyI32) => convert_val!(i32, Int, i64),
|
||||
ty::TyInt(ast::TyI64) => convert_val!(i64, Int, i64),
|
||||
|
||||
ty::TyUint(hir::TyU8) => convert_val!(u8, Uint, u64),
|
||||
ty::TyUint(hir::TyU16) => convert_val!(u16, Uint, u64),
|
||||
ty::TyUint(hir::TyU32) => convert_val!(u32, Uint, u64),
|
||||
ty::TyUint(hir::TyU64) => convert_val!(u64, Uint, u64),
|
||||
ty::TyUint(ast::TyU8) => convert_val!(u8, Uint, u64),
|
||||
ty::TyUint(ast::TyU16) => convert_val!(u16, Uint, u64),
|
||||
ty::TyUint(ast::TyU32) => convert_val!(u32, Uint, u64),
|
||||
ty::TyUint(ast::TyU64) => convert_val!(u64, Uint, u64),
|
||||
|
||||
ty::TyFloat(hir::TyF32) => convert_val!(f32, Float, f64),
|
||||
ty::TyFloat(hir::TyF64) => convert_val!(f64, Float, f64),
|
||||
ty::TyFloat(ast::TyF32) => convert_val!(f32, Float, f64),
|
||||
ty::TyFloat(ast::TyF64) => convert_val!(f64, Float, f64),
|
||||
_ => Err(ErrKind::CannotCast),
|
||||
}
|
||||
}
|
||||
|
||||
fn lit_to_const(lit: &hir::Lit, ty_hint: Option<Ty>) -> ConstVal {
|
||||
fn lit_to_const(lit: &ast::Lit, ty_hint: Option<Ty>) -> ConstVal {
|
||||
match lit.node {
|
||||
hir::LitStr(ref s, _) => Str((*s).clone()),
|
||||
hir::LitByteStr(ref data) => {
|
||||
ast::LitStr(ref s, _) => Str((*s).clone()),
|
||||
ast::LitByteStr(ref data) => {
|
||||
ByteStr(data.clone())
|
||||
}
|
||||
hir::LitByte(n) => Uint(n as u64),
|
||||
hir::LitChar(n) => Uint(n as u64),
|
||||
hir::LitInt(n, hir::SignedIntLit(_, hir::Plus)) => Int(n as i64),
|
||||
hir::LitInt(n, hir::UnsuffixedIntLit(hir::Plus)) => {
|
||||
ast::LitByte(n) => Uint(n as u64),
|
||||
ast::LitChar(n) => Uint(n as u64),
|
||||
ast::LitInt(n, ast::SignedIntLit(_, ast::Plus)) => Int(n as i64),
|
||||
ast::LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => {
|
||||
match ty_hint.map(|ty| &ty.sty) {
|
||||
Some(&ty::TyUint(_)) => Uint(n),
|
||||
_ => Int(n as i64)
|
||||
}
|
||||
}
|
||||
hir::LitInt(n, hir::SignedIntLit(_, hir::Minus)) |
|
||||
hir::LitInt(n, hir::UnsuffixedIntLit(hir::Minus)) => Int(-(n as i64)),
|
||||
hir::LitInt(n, hir::UnsignedIntLit(_)) => Uint(n),
|
||||
hir::LitFloat(ref n, _) |
|
||||
hir::LitFloatUnsuffixed(ref n) => {
|
||||
ast::LitInt(n, ast::SignedIntLit(_, ast::Minus)) |
|
||||
ast::LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => Int(-(n as i64)),
|
||||
ast::LitInt(n, ast::UnsignedIntLit(_)) => Uint(n),
|
||||
ast::LitFloat(ref n, _) |
|
||||
ast::LitFloatUnsuffixed(ref n) => {
|
||||
Float(n.parse::<f64>().unwrap() as f64)
|
||||
}
|
||||
hir::LitBool(b) => Bool(b)
|
||||
ast::LitBool(b) => Bool(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ use std::usize;
|
||||
use syntax::ast;
|
||||
use syntax::ast_util::IdRange;
|
||||
use syntax::print::pp;
|
||||
use syntax::print::pprust::PrintState;
|
||||
use util::nodemap::NodeMap;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit;
|
||||
|
@ -15,7 +15,6 @@
|
||||
use front::map as ast_map;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
use rustc_front::attr::{self, AttrMetaMethods};
|
||||
|
||||
use middle::{def, pat_util, privacy, ty};
|
||||
use middle::def_id::{DefId};
|
||||
@ -24,6 +23,7 @@ use util::nodemap::NodeSet;
|
||||
|
||||
use std::collections::HashSet;
|
||||
use syntax::{ast, codemap};
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
|
||||
// Any local node that may call something in its body block should be
|
||||
// explored. For example, if it's a live NodeItem that is a
|
||||
@ -285,13 +285,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn has_allow_dead_code_or_lang_attr(attrs: &[hir::Attribute]) -> bool {
|
||||
fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
|
||||
if attr::contains_name(attrs, "lang") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let dead_code = lint::builtin::DEAD_CODE.name_lower();
|
||||
for attr in lint::gather_attrs_from_hir(attrs) {
|
||||
for attr in lint::gather_attrs(attrs) {
|
||||
match attr {
|
||||
Ok((ref name, lint::Allow, _))
|
||||
if &name[..] == dead_code => return true,
|
||||
|
@ -12,10 +12,10 @@
|
||||
use front::map as ast_map;
|
||||
use session::{config, Session};
|
||||
use syntax::ast::NodeId;
|
||||
use rustc_front::hir::{Item, ItemFn};
|
||||
use rustc_front::attr;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::entry::EntryPointType;
|
||||
use rustc_front::hir::{Item, ItemFn};
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
|
||||
|
@ -48,8 +48,8 @@ use middle::ty::error::TypeError;
|
||||
use middle::ty::fold::{TypeFolder, TypeFoldable};
|
||||
use middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CombineFields<'a, 'tcx: 'a> {
|
||||
@ -138,7 +138,7 @@ fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
|
||||
fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
|
||||
vid_is_expected: bool,
|
||||
vid: ty::FloatVid,
|
||||
val: hir::FloatTy)
|
||||
val: ast::FloatTy)
|
||||
-> RelateResult<'tcx, Ty<'tcx>>
|
||||
{
|
||||
try!(infcx
|
||||
@ -388,7 +388,7 @@ fn int_unification_error<'tcx>(a_is_expected: bool, v: (ty::IntVarValue, ty::Int
|
||||
}
|
||||
|
||||
fn float_unification_error<'tcx>(a_is_expected: bool,
|
||||
v: (hir::FloatTy, hir::FloatTy))
|
||||
v: (ast::FloatTy, ast::FloatTy))
|
||||
-> TypeError<'tcx>
|
||||
{
|
||||
let (a, b) = v;
|
||||
|
@ -8,9 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use syntax::ast;
|
||||
use middle::ty::{self, IntVarValue, Ty};
|
||||
use rustc_data_structures::unify::UnifyKey;
|
||||
use rustc_front::hir as ast;
|
||||
|
||||
pub trait ToType<'tcx> {
|
||||
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
|
||||
|
@ -28,7 +28,8 @@ use middle::ty;
|
||||
use middle::weak_lang_items;
|
||||
use util::nodemap::FnvHashMap;
|
||||
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use syntax::ast;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::codemap::{DUMMY_SP, Span};
|
||||
use syntax::parse::token::InternedString;
|
||||
use rustc_front::visit::Visitor;
|
||||
@ -216,7 +217,7 @@ impl<'a> LanguageItemCollector<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract(attrs: &[hir::Attribute]) -> Option<InternedString> {
|
||||
pub fn extract(attrs: &[ast::Attribute]) -> Option<InternedString> {
|
||||
for attribute in attrs {
|
||||
match attribute.value_str() {
|
||||
Some(ref value) if attribute.check_name("lang") => {
|
||||
|
@ -26,8 +26,8 @@ use util::nodemap::NodeSet;
|
||||
use std::collections::HashSet;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::visit;
|
||||
|
||||
|
@ -21,13 +21,13 @@ use metadata::csearch;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
use syntax::ast;
|
||||
use syntax::ast::NodeId;
|
||||
use syntax::ast::{NodeId, Attribute};
|
||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
||||
use syntax::attr::{self, Stability, AttrMetaMethods};
|
||||
use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{FnDecl, Attribute, Block, Crate, Item, Generics, StructField, Variant};
|
||||
use rustc_front::attr::{self, Stability, AttrMetaMethods};
|
||||
use rustc_front::hir::{FnDecl, Block, Crate, Item, Generics, StructField, Variant};
|
||||
use rustc_front::visit::{self, FnKind, Visitor};
|
||||
|
||||
use std::mem::replace;
|
||||
@ -237,7 +237,7 @@ impl<'tcx> Index<'tcx> {
|
||||
for attr in &krate.attrs {
|
||||
if &attr.name()[..] == "staged_api" {
|
||||
match attr.node.value.node {
|
||||
hir::MetaWord(_) => {
|
||||
ast::MetaWord(_) => {
|
||||
attr::mark_used(attr);
|
||||
is_staged_api = true;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ use middle::ty::fold::TypeFoldable;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::attr::{AttributeMethods, AttrMetaMethods};
|
||||
use syntax::attr::{AttributeMethods, AttrMetaMethods};
|
||||
|
||||
pub fn report_fulfillment_errors<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
||||
errors: &Vec<FulfillmentError<'tcx>>) {
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
use middle::ty::{self, Ty};
|
||||
|
||||
use rustc_front::hir as ast;
|
||||
use syntax::ast;
|
||||
|
||||
/// Types that are represented as ints.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -16,7 +16,7 @@ use util::nodemap::FnvHashMap;
|
||||
use std::fmt;
|
||||
use std::ops;
|
||||
|
||||
use rustc_front::hir;
|
||||
use syntax::ast;
|
||||
|
||||
/// Type contents is how the type checker reasons about kinds.
|
||||
/// They track what kinds of things are found within a type. You can
|
||||
@ -182,7 +182,7 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
|
||||
let result = match ty.sty {
|
||||
// usize and isize are ffi-unsafe
|
||||
ty::TyUint(hir::TyUs) | ty::TyInt(hir::TyIs) => {
|
||||
ty::TyUint(ast::TyUs) | ty::TyInt(ast::TyIs) => {
|
||||
TC::None
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,11 @@ use std::cell::{Cell, RefCell, Ref};
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::rc::Rc;
|
||||
use syntax::abi;
|
||||
use syntax::ast::{Name, NodeId};
|
||||
use syntax::ast::{self, Name, NodeId};
|
||||
use syntax::attr;
|
||||
use syntax::parse::token::special_idents;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
|
||||
/// Internal storage
|
||||
pub struct CtxtArenas<'tcx> {
|
||||
@ -146,18 +146,18 @@ impl<'tcx> CommonTypes<'tcx> {
|
||||
bool: mk(TyBool),
|
||||
char: mk(TyChar),
|
||||
err: mk(TyError),
|
||||
isize: mk(TyInt(hir::TyIs)),
|
||||
i8: mk(TyInt(hir::TyI8)),
|
||||
i16: mk(TyInt(hir::TyI16)),
|
||||
i32: mk(TyInt(hir::TyI32)),
|
||||
i64: mk(TyInt(hir::TyI64)),
|
||||
usize: mk(TyUint(hir::TyUs)),
|
||||
u8: mk(TyUint(hir::TyU8)),
|
||||
u16: mk(TyUint(hir::TyU16)),
|
||||
u32: mk(TyUint(hir::TyU32)),
|
||||
u64: mk(TyUint(hir::TyU64)),
|
||||
f32: mk(TyFloat(hir::TyF32)),
|
||||
f64: mk(TyFloat(hir::TyF64)),
|
||||
isize: mk(TyInt(ast::TyIs)),
|
||||
i8: mk(TyInt(ast::TyI8)),
|
||||
i16: mk(TyInt(ast::TyI16)),
|
||||
i32: mk(TyInt(ast::TyI32)),
|
||||
i64: mk(TyInt(ast::TyI64)),
|
||||
usize: mk(TyUint(ast::TyUs)),
|
||||
u8: mk(TyUint(ast::TyU8)),
|
||||
u16: mk(TyUint(ast::TyU16)),
|
||||
u32: mk(TyUint(ast::TyU32)),
|
||||
u64: mk(TyUint(ast::TyU64)),
|
||||
f32: mk(TyFloat(ast::TyF32)),
|
||||
f64: mk(TyFloat(ast::TyF64)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -771,30 +771,30 @@ impl<'tcx> ctxt<'tcx> {
|
||||
ctxt::intern_ty(&self.arenas.type_, &self.interner, st)
|
||||
}
|
||||
|
||||
pub fn mk_mach_int(&self, tm: hir::IntTy) -> Ty<'tcx> {
|
||||
pub fn mk_mach_int(&self, tm: ast::IntTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
hir::TyIs => self.types.isize,
|
||||
hir::TyI8 => self.types.i8,
|
||||
hir::TyI16 => self.types.i16,
|
||||
hir::TyI32 => self.types.i32,
|
||||
hir::TyI64 => self.types.i64,
|
||||
ast::TyIs => self.types.isize,
|
||||
ast::TyI8 => self.types.i8,
|
||||
ast::TyI16 => self.types.i16,
|
||||
ast::TyI32 => self.types.i32,
|
||||
ast::TyI64 => self.types.i64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_mach_uint(&self, tm: hir::UintTy) -> Ty<'tcx> {
|
||||
pub fn mk_mach_uint(&self, tm: ast::UintTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
hir::TyUs => self.types.usize,
|
||||
hir::TyU8 => self.types.u8,
|
||||
hir::TyU16 => self.types.u16,
|
||||
hir::TyU32 => self.types.u32,
|
||||
hir::TyU64 => self.types.u64,
|
||||
ast::TyUs => self.types.usize,
|
||||
ast::TyU8 => self.types.u8,
|
||||
ast::TyU16 => self.types.u16,
|
||||
ast::TyU32 => self.types.u32,
|
||||
ast::TyU64 => self.types.u64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_mach_float(&self, tm: hir::FloatTy) -> Ty<'tcx> {
|
||||
pub fn mk_mach_float(&self, tm: ast::FloatTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
hir::TyF32 => self.types.f32,
|
||||
hir::TyF64 => self.types.f64,
|
||||
ast::TyF32 => self.types.f32,
|
||||
ast::TyF64 => self.types.f64,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ use middle::ty::{self, BoundRegion, Region, Ty};
|
||||
|
||||
use std::fmt;
|
||||
use syntax::abi;
|
||||
use syntax::ast::Name;
|
||||
use syntax::ast::{self, Name};
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use rustc_front::hir;
|
||||
@ -49,7 +49,7 @@ pub enum TypeError<'tcx> {
|
||||
Sorts(ExpectedFound<Ty<'tcx>>),
|
||||
IntegerAsChar,
|
||||
IntMismatch(ExpectedFound<ty::IntVarValue>),
|
||||
FloatMismatch(ExpectedFound<hir::FloatTy>),
|
||||
FloatMismatch(ExpectedFound<ast::FloatTy>),
|
||||
Traits(ExpectedFound<DefId>),
|
||||
BuiltinBoundsMismatch(ExpectedFound<ty::BuiltinBounds>),
|
||||
VariadicMismatch(ExpectedFound<bool>),
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
use middle::def_id::DefId;
|
||||
use middle::ty::{self, Ty};
|
||||
use rustc_front::hir;
|
||||
use syntax::ast;
|
||||
|
||||
use self::SimplifiedType::*;
|
||||
|
||||
@ -19,9 +19,9 @@ use self::SimplifiedType::*;
|
||||
pub enum SimplifiedType {
|
||||
BoolSimplifiedType,
|
||||
CharSimplifiedType,
|
||||
IntSimplifiedType(hir::IntTy),
|
||||
UintSimplifiedType(hir::UintTy),
|
||||
FloatSimplifiedType(hir::FloatTy),
|
||||
IntSimplifiedType(ast::IntTy),
|
||||
UintSimplifiedType(ast::UintTy),
|
||||
FloatSimplifiedType(ast::FloatTy),
|
||||
EnumSimplifiedType(DefId),
|
||||
StrSimplifiedType,
|
||||
VecSimplifiedType,
|
||||
|
@ -44,13 +44,13 @@ use std::slice;
|
||||
use std::vec::IntoIter;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use syntax::ast::{self, CrateNum, Name, NodeId};
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::{InternedString, special_idents};
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{ItemImpl, ItemTrait};
|
||||
use rustc_front::hir::{MutImmutable, MutMutable, Visibility};
|
||||
use rustc_front::attr::{self, AttrMetaMethods};
|
||||
|
||||
pub use self::sty::{Binder, DebruijnIndex};
|
||||
pub use self::sty::{BuiltinBound, BuiltinBounds, ExistentialBounds};
|
||||
@ -563,8 +563,8 @@ pub struct ClosureUpvar<'tcx> {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum IntVarValue {
|
||||
IntType(hir::IntTy),
|
||||
UintType(hir::UintTy),
|
||||
IntType(ast::IntTy),
|
||||
UintType(ast::UintTy),
|
||||
}
|
||||
|
||||
/// Default region to use for the bound of objects that are
|
||||
@ -2337,7 +2337,7 @@ impl<'tcx> ctxt<'tcx> {
|
||||
}
|
||||
|
||||
/// Get the attributes of a definition.
|
||||
pub fn get_attrs(&self, did: DefId) -> Cow<'tcx, [hir::Attribute]> {
|
||||
pub fn get_attrs(&self, did: DefId) -> Cow<'tcx, [ast::Attribute]> {
|
||||
if did.is_local() {
|
||||
Cow::Borrowed(self.map.attrs(did.node))
|
||||
} else {
|
||||
|
@ -23,7 +23,7 @@ use std::fmt;
|
||||
use std::ops;
|
||||
use std::mem;
|
||||
use syntax::abi;
|
||||
use syntax::ast::{Name, NodeId};
|
||||
use syntax::ast::{self, Name, NodeId};
|
||||
use syntax::parse::token::special_idents;
|
||||
|
||||
use rustc_front::hir;
|
||||
@ -79,13 +79,13 @@ pub enum TypeVariants<'tcx> {
|
||||
TyChar,
|
||||
|
||||
/// A primitive signed integer type. For example, `i32`.
|
||||
TyInt(hir::IntTy),
|
||||
TyInt(ast::IntTy),
|
||||
|
||||
/// A primitive unsigned integer type. For example, `u32`.
|
||||
TyUint(hir::UintTy),
|
||||
TyUint(ast::UintTy),
|
||||
|
||||
/// A primitive floating-point type. For example, `f64`.
|
||||
TyFloat(hir::FloatTy),
|
||||
TyFloat(ast::FloatTy),
|
||||
|
||||
/// An enumerated type, defined with `enum`.
|
||||
///
|
||||
@ -93,7 +93,7 @@ pub enum TypeVariants<'tcx> {
|
||||
/// That is, even after substitution it is possible that there are type
|
||||
/// variables. This happens when the `TyEnum` corresponds to an enum
|
||||
/// definition and not a concrete use of it. To get the correct `TyEnum`
|
||||
/// from the tcx, use the `NodeId` from the `hir::Ty` and look it up in
|
||||
/// from the tcx, use the `NodeId` from the `ast::Ty` and look it up in
|
||||
/// the `ast_ty_to_ty_cache`. This is probably true for `TyStruct` as
|
||||
/// well.
|
||||
TyEnum(AdtDef<'tcx>, &'tcx Substs<'tcx>),
|
||||
@ -944,7 +944,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
pub fn sequence_element_type(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
|
||||
match self.sty {
|
||||
TyArray(ty, _) | TySlice(ty) => ty,
|
||||
TyStr => cx.mk_mach_uint(hir::TyU8),
|
||||
TyStr => cx.mk_mach_uint(ast::TyU8),
|
||||
_ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}",
|
||||
self)),
|
||||
}
|
||||
@ -1035,7 +1035,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
pub fn is_uint(&self) -> bool {
|
||||
match self.sty {
|
||||
TyInfer(IntVar(_)) | TyUint(hir::TyUs) => true,
|
||||
TyInfer(IntVar(_)) | TyUint(ast::TyUs) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
@ -1081,7 +1081,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
pub fn is_machine(&self) -> bool {
|
||||
match self.sty {
|
||||
TyInt(hir::TyIs) | TyUint(hir::TyUs) => false,
|
||||
TyInt(ast::TyIs) | TyUint(ast::TyUs) => false,
|
||||
TyInt(..) | TyUint(..) | TyFloat(..) => true,
|
||||
_ => false
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ use util::num::ToPrimitive;
|
||||
|
||||
use std::cmp;
|
||||
use std::hash::{Hash, SipHasher, Hasher};
|
||||
use syntax::ast::Name;
|
||||
use syntax::ast::{self, Name};
|
||||
use syntax::attr::{self, AttrMetaMethods, SignedInt, UnsignedInt};
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr::{self, AttrMetaMethods, SignedInt, UnsignedInt};
|
||||
|
||||
pub trait IntTypeExt {
|
||||
fn to_ty<'tcx>(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
|
||||
@ -44,48 +44,48 @@ pub trait IntTypeExt {
|
||||
impl IntTypeExt for attr::IntType {
|
||||
fn to_ty<'tcx>(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx> {
|
||||
match *self {
|
||||
SignedInt(hir::TyI8) => cx.types.i8,
|
||||
SignedInt(hir::TyI16) => cx.types.i16,
|
||||
SignedInt(hir::TyI32) => cx.types.i32,
|
||||
SignedInt(hir::TyI64) => cx.types.i64,
|
||||
SignedInt(hir::TyIs) => cx.types.isize,
|
||||
UnsignedInt(hir::TyU8) => cx.types.u8,
|
||||
UnsignedInt(hir::TyU16) => cx.types.u16,
|
||||
UnsignedInt(hir::TyU32) => cx.types.u32,
|
||||
UnsignedInt(hir::TyU64) => cx.types.u64,
|
||||
UnsignedInt(hir::TyUs) => cx.types.usize,
|
||||
SignedInt(ast::TyI8) => cx.types.i8,
|
||||
SignedInt(ast::TyI16) => cx.types.i16,
|
||||
SignedInt(ast::TyI32) => cx.types.i32,
|
||||
SignedInt(ast::TyI64) => cx.types.i64,
|
||||
SignedInt(ast::TyIs) => cx.types.isize,
|
||||
UnsignedInt(ast::TyU8) => cx.types.u8,
|
||||
UnsignedInt(ast::TyU16) => cx.types.u16,
|
||||
UnsignedInt(ast::TyU32) => cx.types.u32,
|
||||
UnsignedInt(ast::TyU64) => cx.types.u64,
|
||||
UnsignedInt(ast::TyUs) => cx.types.usize,
|
||||
}
|
||||
}
|
||||
|
||||
fn i64_to_disr(&self, val: i64) -> Option<Disr> {
|
||||
match *self {
|
||||
SignedInt(hir::TyI8) => val.to_i8() .map(|v| v as Disr),
|
||||
SignedInt(hir::TyI16) => val.to_i16() .map(|v| v as Disr),
|
||||
SignedInt(hir::TyI32) => val.to_i32() .map(|v| v as Disr),
|
||||
SignedInt(hir::TyI64) => val.to_i64() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU8) => val.to_u8() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU16) => val.to_u16() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU32) => val.to_u32() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU64) => val.to_u64() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI8) => val.to_i8() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI16) => val.to_i16() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI32) => val.to_i32() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI64) => val.to_i64() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU8) => val.to_u8() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU16) => val.to_u16() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU32) => val.to_u32() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU64) => val.to_u64() .map(|v| v as Disr),
|
||||
|
||||
UnsignedInt(hir::TyUs) |
|
||||
SignedInt(hir::TyIs) => unreachable!(),
|
||||
UnsignedInt(ast::TyUs) |
|
||||
SignedInt(ast::TyIs) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn u64_to_disr(&self, val: u64) -> Option<Disr> {
|
||||
match *self {
|
||||
SignedInt(hir::TyI8) => val.to_i8() .map(|v| v as Disr),
|
||||
SignedInt(hir::TyI16) => val.to_i16() .map(|v| v as Disr),
|
||||
SignedInt(hir::TyI32) => val.to_i32() .map(|v| v as Disr),
|
||||
SignedInt(hir::TyI64) => val.to_i64() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU8) => val.to_u8() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU16) => val.to_u16() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU32) => val.to_u32() .map(|v| v as Disr),
|
||||
UnsignedInt(hir::TyU64) => val.to_u64() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI8) => val.to_i8() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI16) => val.to_i16() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI32) => val.to_i32() .map(|v| v as Disr),
|
||||
SignedInt(ast::TyI64) => val.to_i64() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU8) => val.to_u8() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU16) => val.to_u16() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU32) => val.to_u32() .map(|v| v as Disr),
|
||||
UnsignedInt(ast::TyU64) => val.to_u64() .map(|v| v as Disr),
|
||||
|
||||
UnsignedInt(hir::TyUs) |
|
||||
SignedInt(hir::TyIs) => unreachable!(),
|
||||
UnsignedInt(ast::TyUs) |
|
||||
SignedInt(ast::TyIs) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,18 +97,18 @@ impl IntTypeExt for attr::IntType {
|
||||
// SignedInt repr means we *want* to reinterpret the bits
|
||||
// treating the highest bit of Disr as a sign-bit, so
|
||||
// cast to i64 before range-checking.
|
||||
SignedInt(hir::TyI8) => add1!((val as i64).to_i8()),
|
||||
SignedInt(hir::TyI16) => add1!((val as i64).to_i16()),
|
||||
SignedInt(hir::TyI32) => add1!((val as i64).to_i32()),
|
||||
SignedInt(hir::TyI64) => add1!(Some(val as i64)),
|
||||
SignedInt(ast::TyI8) => add1!((val as i64).to_i8()),
|
||||
SignedInt(ast::TyI16) => add1!((val as i64).to_i16()),
|
||||
SignedInt(ast::TyI32) => add1!((val as i64).to_i32()),
|
||||
SignedInt(ast::TyI64) => add1!(Some(val as i64)),
|
||||
|
||||
UnsignedInt(hir::TyU8) => add1!(val.to_u8()),
|
||||
UnsignedInt(hir::TyU16) => add1!(val.to_u16()),
|
||||
UnsignedInt(hir::TyU32) => add1!(val.to_u32()),
|
||||
UnsignedInt(hir::TyU64) => add1!(Some(val)),
|
||||
UnsignedInt(ast::TyU8) => add1!(val.to_u8()),
|
||||
UnsignedInt(ast::TyU16) => add1!(val.to_u16()),
|
||||
UnsignedInt(ast::TyU32) => add1!(val.to_u32()),
|
||||
UnsignedInt(ast::TyU64) => add1!(Some(val)),
|
||||
|
||||
UnsignedInt(hir::TyUs) |
|
||||
SignedInt(hir::TyIs) => unreachable!(),
|
||||
UnsignedInt(ast::TyUs) |
|
||||
SignedInt(ast::TyIs) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,17 +117,17 @@ impl IntTypeExt for attr::IntType {
|
||||
// full range from `i64::MIN` through `u64::MAX`.
|
||||
fn disr_string(&self, val: Disr) -> String {
|
||||
match *self {
|
||||
SignedInt(hir::TyI8) => format!("{}", val as i8 ),
|
||||
SignedInt(hir::TyI16) => format!("{}", val as i16),
|
||||
SignedInt(hir::TyI32) => format!("{}", val as i32),
|
||||
SignedInt(hir::TyI64) => format!("{}", val as i64),
|
||||
UnsignedInt(hir::TyU8) => format!("{}", val as u8 ),
|
||||
UnsignedInt(hir::TyU16) => format!("{}", val as u16),
|
||||
UnsignedInt(hir::TyU32) => format!("{}", val as u32),
|
||||
UnsignedInt(hir::TyU64) => format!("{}", val as u64),
|
||||
SignedInt(ast::TyI8) => format!("{}", val as i8 ),
|
||||
SignedInt(ast::TyI16) => format!("{}", val as i16),
|
||||
SignedInt(ast::TyI32) => format!("{}", val as i32),
|
||||
SignedInt(ast::TyI64) => format!("{}", val as i64),
|
||||
UnsignedInt(ast::TyU8) => format!("{}", val as u8 ),
|
||||
UnsignedInt(ast::TyU16) => format!("{}", val as u16),
|
||||
UnsignedInt(ast::TyU32) => format!("{}", val as u32),
|
||||
UnsignedInt(ast::TyU64) => format!("{}", val as u64),
|
||||
|
||||
UnsignedInt(hir::TyUs) |
|
||||
SignedInt(hir::TyIs) => unreachable!(),
|
||||
UnsignedInt(ast::TyUs) |
|
||||
SignedInt(ast::TyIs) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,17 +137,17 @@ impl IntTypeExt for attr::IntType {
|
||||
}
|
||||
let val = val.unwrap_or(ty::INITIAL_DISCRIMINANT_VALUE);
|
||||
match *self {
|
||||
SignedInt(hir::TyI8) => add1!(val as i8 ),
|
||||
SignedInt(hir::TyI16) => add1!(val as i16),
|
||||
SignedInt(hir::TyI32) => add1!(val as i32),
|
||||
SignedInt(hir::TyI64) => add1!(val as i64),
|
||||
UnsignedInt(hir::TyU8) => add1!(val as u8 ),
|
||||
UnsignedInt(hir::TyU16) => add1!(val as u16),
|
||||
UnsignedInt(hir::TyU32) => add1!(val as u32),
|
||||
UnsignedInt(hir::TyU64) => add1!(val as u64),
|
||||
SignedInt(ast::TyI8) => add1!(val as i8 ),
|
||||
SignedInt(ast::TyI16) => add1!(val as i16),
|
||||
SignedInt(ast::TyI32) => add1!(val as i32),
|
||||
SignedInt(ast::TyI64) => add1!(val as i64),
|
||||
UnsignedInt(ast::TyU8) => add1!(val as u8 ),
|
||||
UnsignedInt(ast::TyU16) => add1!(val as u16),
|
||||
UnsignedInt(ast::TyU32) => add1!(val as u32),
|
||||
UnsignedInt(ast::TyU64) => add1!(val as u64),
|
||||
|
||||
UnsignedInt(hir::TyUs) |
|
||||
SignedInt(hir::TyIs) => unreachable!(),
|
||||
UnsignedInt(ast::TyUs) |
|
||||
SignedInt(ast::TyIs) => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -279,14 +279,14 @@ impl<'tcx> ty::ctxt<'tcx> {
|
||||
//
|
||||
// NB. Historically `fn enum_variants` generate i64 here, while
|
||||
// rustc_typeck::check would generate isize.
|
||||
_ => SignedInt(hir::TyIs),
|
||||
_ => SignedInt(ast::TyIs),
|
||||
};
|
||||
|
||||
let repr_type_ty = repr_type.to_ty(self);
|
||||
let repr_type = match repr_type {
|
||||
SignedInt(hir::TyIs) =>
|
||||
SignedInt(ast::TyIs) =>
|
||||
SignedInt(self.sess.target.int_type),
|
||||
UnsignedInt(hir::TyUs) =>
|
||||
UnsignedInt(ast::TyUs) =>
|
||||
UnsignedInt(self.sess.target.uint_type),
|
||||
other => other
|
||||
};
|
||||
|
@ -15,6 +15,7 @@ use session::Session;
|
||||
use metadata::csearch;
|
||||
use middle::lang_items;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::InternedString;
|
||||
use rustc_front::visit::Visitor;
|
||||
@ -54,7 +55,7 @@ pub fn check_crate(krate: &hir::Crate,
|
||||
verify(sess, items);
|
||||
}
|
||||
|
||||
pub fn link_name(attrs: &[hir::Attribute]) -> Option<InternedString> {
|
||||
pub fn link_name(attrs: &[ast::Attribute]) -> Option<InternedString> {
|
||||
lang_items::extract(attrs).and_then(|name| {
|
||||
$(if &name[..] == stringify!($name) {
|
||||
Some(InternedString::new(stringify!($sym)))
|
||||
|
@ -11,12 +11,12 @@
|
||||
//! Used by `rustc` when compiling a plugin crate.
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::diagnostic;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
|
||||
struct RegistrarFinder {
|
||||
registrars: Vec<(ast::NodeId, Span)> ,
|
||||
|
@ -25,11 +25,9 @@ use rustc_back::target::Target;
|
||||
use lint;
|
||||
use metadata::cstore;
|
||||
|
||||
use syntax::ast;
|
||||
use rustc_front::hir::{IntTy, UintTy};
|
||||
use syntax::ast::{self, IntTy, UintTy};
|
||||
use syntax::attr;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use rustc_front::hir;
|
||||
use syntax::diagnostic::{ColorConfig, Auto, Always, Never, SpanHandler};
|
||||
use syntax::parse;
|
||||
use syntax::parse::token::InternedString;
|
||||
@ -669,8 +667,8 @@ pub fn build_target_config(opts: &Options, sp: &SpanHandler) -> Config {
|
||||
};
|
||||
|
||||
let (int_type, uint_type) = match &target.target_pointer_width[..] {
|
||||
"32" => (hir::TyI32, hir::TyU32),
|
||||
"64" => (hir::TyI64, hir::TyU64),
|
||||
"32" => (ast::TyI32, ast::TyU32),
|
||||
"64" => (ast::TyI64, ast::TyU64),
|
||||
w => sp.handler().fatal(&format!("target specification was invalid: unrecognized \
|
||||
target-pointer-width {}", w))
|
||||
};
|
||||
|
@ -25,9 +25,10 @@ use middle::ty::fold::TypeFoldable;
|
||||
|
||||
use std::fmt;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::parse::token;
|
||||
use syntax::ast::DUMMY_NODE_ID;
|
||||
use rustc_front::hir as ast;
|
||||
use rustc_front::hir;
|
||||
|
||||
pub fn verbose() -> bool {
|
||||
ty::tls::with(|tcx| tcx.sess.verbose())
|
||||
@ -334,7 +335,7 @@ impl<'tcx> fmt::Debug for ty::TyS<'tcx> {
|
||||
impl<'tcx> fmt::Display for ty::TypeAndMut<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}",
|
||||
if self.mutbl == ast::MutMutable { "mut " } else { "" },
|
||||
if self.mutbl == hir::MutMutable { "mut " } else { "" },
|
||||
self.ty)
|
||||
}
|
||||
}
|
||||
@ -825,8 +826,8 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
|
||||
TyBox(typ) => write!(f, "Box<{}>", typ),
|
||||
TyRawPtr(ref tm) => {
|
||||
write!(f, "*{} {}", match tm.mutbl {
|
||||
ast::MutMutable => "mut",
|
||||
ast::MutImmutable => "const",
|
||||
hir::MutMutable => "mut",
|
||||
hir::MutImmutable => "const",
|
||||
}, tm.ty)
|
||||
}
|
||||
TyRef(r, ref tm) => {
|
||||
@ -853,7 +854,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
|
||||
write!(f, ")")
|
||||
}
|
||||
TyBareFn(opt_def_id, ref bare_fn) => {
|
||||
if bare_fn.unsafety == ast::Unsafety::Unsafe {
|
||||
if bare_fn.unsafety == hir::Unsafety::Unsafe {
|
||||
try!(write!(f, "unsafe "));
|
||||
}
|
||||
|
||||
@ -966,10 +967,10 @@ impl fmt::Display for ty::ExplicitSelfCategory {
|
||||
f.write_str(match *self {
|
||||
ty::StaticExplicitSelfCategory => "static",
|
||||
ty::ByValueExplicitSelfCategory => "self",
|
||||
ty::ByReferenceExplicitSelfCategory(_, ast::MutMutable) => {
|
||||
ty::ByReferenceExplicitSelfCategory(_, hir::MutMutable) => {
|
||||
"&mut self"
|
||||
}
|
||||
ty::ByReferenceExplicitSelfCategory(_, ast::MutImmutable) => "&self",
|
||||
ty::ByReferenceExplicitSelfCategory(_, hir::MutImmutable) => "&self",
|
||||
ty::ByBoxExplicitSelfCategory => "Box<self>",
|
||||
})
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ mod svh_visitor {
|
||||
SawExprTup,
|
||||
SawExprBinary(hir::BinOp_),
|
||||
SawExprUnary(hir::UnOp),
|
||||
SawExprLit(hir::Lit_),
|
||||
SawExprLit(ast::Lit_),
|
||||
SawExprCast,
|
||||
SawExprIf,
|
||||
SawExprWhile,
|
||||
|
@ -28,7 +28,7 @@ use std::mem;
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||
enum Fragment {
|
||||
|
@ -32,6 +32,7 @@ use syntax::ast;
|
||||
use syntax::codemap;
|
||||
use syntax::fold::{self, Folder};
|
||||
use syntax::print::{pp, pprust};
|
||||
use syntax::print::pprust::PrintState;
|
||||
use syntax::ptr::P;
|
||||
use syntax::util::small_vector::SmallVector;
|
||||
|
||||
|
@ -15,8 +15,6 @@ pub use self::ReprAttr::*;
|
||||
pub use self::IntType::*;
|
||||
|
||||
use hir;
|
||||
use hir::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
|
||||
use lowering::{lower_attr_style, unlower_attribute};
|
||||
use syntax::codemap::{Span, Spanned, spanned, dummy_spanned};
|
||||
use syntax::codemap::BytePos;
|
||||
use syntax::diagnostic::SpanHandler;
|
||||
|
@ -12,7 +12,8 @@
|
||||
//! and returns a piece of the same type.
|
||||
|
||||
use hir::*;
|
||||
use syntax::ast::{Ident, NodeId, DUMMY_NODE_ID};
|
||||
use syntax::ast::{Ident, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
|
||||
use syntax::ast::{MetaWord, MetaList, MetaNameValue};
|
||||
use hir;
|
||||
use syntax::codemap::{respan, Span, Spanned};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
|
@ -11,7 +11,6 @@
|
||||
// The Rust HIR.
|
||||
|
||||
pub use self::AsmDialect::*;
|
||||
pub use self::AttrStyle::*;
|
||||
pub use self::BindingMode::*;
|
||||
pub use self::BinOp_::*;
|
||||
pub use self::BlockCheckMode::*;
|
||||
@ -19,28 +18,20 @@ pub use self::CaptureClause::*;
|
||||
pub use self::Decl_::*;
|
||||
pub use self::ExplicitSelf_::*;
|
||||
pub use self::Expr_::*;
|
||||
pub use self::FloatTy::*;
|
||||
pub use self::FunctionRetTy::*;
|
||||
pub use self::ForeignItem_::*;
|
||||
pub use self::ImplItem_::*;
|
||||
pub use self::IntTy::*;
|
||||
pub use self::Item_::*;
|
||||
pub use self::Lit_::*;
|
||||
pub use self::LitIntType::*;
|
||||
pub use self::MetaItem_::*;
|
||||
pub use self::Mutability::*;
|
||||
pub use self::Pat_::*;
|
||||
pub use self::PathListItem_::*;
|
||||
pub use self::PatWildKind::*;
|
||||
pub use self::PrimTy::*;
|
||||
pub use self::Sign::*;
|
||||
pub use self::Stmt_::*;
|
||||
pub use self::StrStyle::*;
|
||||
pub use self::StructFieldKind::*;
|
||||
pub use self::TraitItem_::*;
|
||||
pub use self::Ty_::*;
|
||||
pub use self::TyParamBound::*;
|
||||
pub use self::UintTy::*;
|
||||
pub use self::UnOp::*;
|
||||
pub use self::UnsafeSource::*;
|
||||
pub use self::VariantKind::*;
|
||||
@ -51,6 +42,7 @@ pub use self::PathParameters::*;
|
||||
use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
|
||||
use syntax::abi::Abi;
|
||||
use syntax::ast::{Name, Ident, NodeId, DUMMY_NODE_ID, TokenTree};
|
||||
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, CrateConfig};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::ptr::P;
|
||||
@ -59,7 +51,6 @@ use print::pprust;
|
||||
use util;
|
||||
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
use serialize::{Encodable, Encoder, Decoder};
|
||||
|
||||
|
||||
@ -333,10 +324,6 @@ pub struct WhereEqPredicate {
|
||||
pub ty: P<Ty>,
|
||||
}
|
||||
|
||||
/// The set of MetaItems that define the compilation environment of the crate,
|
||||
/// used to drive conditional compilation
|
||||
pub type CrateConfig = Vec<P<MetaItem>> ;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct Crate {
|
||||
pub module: Mod,
|
||||
@ -362,40 +349,6 @@ pub struct MacroDef {
|
||||
pub body: Vec<TokenTree>,
|
||||
}
|
||||
|
||||
pub type MetaItem = Spanned<MetaItem_>;
|
||||
|
||||
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum MetaItem_ {
|
||||
MetaWord(InternedString),
|
||||
MetaList(InternedString, Vec<P<MetaItem>>),
|
||||
MetaNameValue(InternedString, Lit),
|
||||
}
|
||||
|
||||
// can't be derived because the MetaList requires an unordered comparison
|
||||
impl PartialEq for MetaItem_ {
|
||||
fn eq(&self, other: &MetaItem_) -> bool {
|
||||
match *self {
|
||||
MetaWord(ref ns) => match *other {
|
||||
MetaWord(ref no) => (*ns) == (*no),
|
||||
_ => false
|
||||
},
|
||||
MetaNameValue(ref ns, ref vs) => match *other {
|
||||
MetaNameValue(ref no, ref vo) => {
|
||||
(*ns) == (*no) && vs.node == vo.node
|
||||
}
|
||||
_ => false
|
||||
},
|
||||
MetaList(ref ns, ref miss) => match *other {
|
||||
MetaList(ref no, ref miso) => {
|
||||
ns == no &&
|
||||
miss.iter().all(|mi| miso.iter().any(|x| x.node == mi.node))
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct Block {
|
||||
/// Statements in a block
|
||||
@ -787,72 +740,6 @@ pub enum CaptureClause {
|
||||
CaptureByRef,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum StrStyle {
|
||||
/// A regular string, like `"foo"`
|
||||
CookedStr,
|
||||
/// A raw string, like `r##"foo"##`
|
||||
///
|
||||
/// The uint is the number of `#` symbols used
|
||||
RawStr(usize)
|
||||
}
|
||||
|
||||
/// A literal
|
||||
pub type Lit = Spanned<Lit_>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum Sign {
|
||||
Minus,
|
||||
Plus
|
||||
}
|
||||
|
||||
impl Sign {
|
||||
pub fn new<T: IntSign>(n: T) -> Sign {
|
||||
n.sign()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IntSign {
|
||||
fn sign(&self) -> Sign;
|
||||
}
|
||||
macro_rules! doit {
|
||||
($($t:ident)*) => ($(impl IntSign for $t {
|
||||
#[allow(unused_comparisons)]
|
||||
fn sign(&self) -> Sign {
|
||||
if *self < 0 {Minus} else {Plus}
|
||||
}
|
||||
})*)
|
||||
}
|
||||
doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize }
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum LitIntType {
|
||||
SignedIntLit(IntTy, Sign),
|
||||
UnsignedIntLit(UintTy),
|
||||
UnsuffixedIntLit(Sign)
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum Lit_ {
|
||||
/// A string literal (`"foo"`)
|
||||
LitStr(InternedString, StrStyle),
|
||||
/// A byte string (`b"foo"`)
|
||||
LitByteStr(Rc<Vec<u8>>),
|
||||
/// A byte char (`b'f'`)
|
||||
LitByte(u8),
|
||||
/// A character literal (`'a'`)
|
||||
LitChar(char),
|
||||
/// An integer literal (`1u8`)
|
||||
LitInt(u64, LitIntType),
|
||||
/// A float literal (`1f64` or `1E10f64`)
|
||||
LitFloat(InternedString, FloatTy),
|
||||
/// A float literal without a suffix (`1.0 or 1.0E10`)
|
||||
LitFloatUnsuffixed(InternedString),
|
||||
/// A boolean literal
|
||||
LitBool(bool),
|
||||
}
|
||||
|
||||
// NB: If you change this, you'll probably want to change the corresponding
|
||||
// type structure in middle/ty.rs as well.
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
@ -917,99 +804,6 @@ pub enum ImplItem_ {
|
||||
TypeImplItem(P<Ty>),
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub enum IntTy {
|
||||
TyIs,
|
||||
TyI8,
|
||||
TyI16,
|
||||
TyI32,
|
||||
TyI64,
|
||||
}
|
||||
|
||||
impl fmt::Debug for IntTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for IntTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", util::int_ty_to_string(*self, None))
|
||||
}
|
||||
}
|
||||
|
||||
impl IntTy {
|
||||
pub fn bit_width(&self) -> Option<usize> {
|
||||
Some(match *self {
|
||||
TyIs => return None,
|
||||
TyI8 => 8,
|
||||
TyI16 => 16,
|
||||
TyI32 => 32,
|
||||
TyI64 => 64,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub enum UintTy {
|
||||
TyUs,
|
||||
TyU8,
|
||||
TyU16,
|
||||
TyU32,
|
||||
TyU64,
|
||||
}
|
||||
|
||||
impl UintTy {
|
||||
pub fn bit_width(&self) -> Option<usize> {
|
||||
Some(match *self {
|
||||
TyUs => return None,
|
||||
TyU8 => 8,
|
||||
TyU16 => 16,
|
||||
TyU32 => 32,
|
||||
TyU64 => 64,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for UintTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for UintTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", util::uint_ty_to_string(*self, None))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
|
||||
pub enum FloatTy {
|
||||
TyF32,
|
||||
TyF64,
|
||||
}
|
||||
|
||||
impl fmt::Debug for FloatTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for FloatTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", util::float_ty_to_string(*self))
|
||||
}
|
||||
}
|
||||
|
||||
impl FloatTy {
|
||||
pub fn bit_width(&self) -> usize {
|
||||
match *self {
|
||||
TyF32 => 32,
|
||||
TyF64 => 64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bind a type to an associated type: `A=Foo`.
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct TypeBinding {
|
||||
@ -1316,30 +1110,6 @@ pub enum ViewPath_ {
|
||||
ViewPathList(Path, Vec<PathListItem>)
|
||||
}
|
||||
|
||||
/// Meta-data associated with an item
|
||||
pub type Attribute = Spanned<Attribute_>;
|
||||
|
||||
/// Distinguishes between Attributes that decorate items and Attributes that
|
||||
/// are contained as statements within items. These two cases need to be
|
||||
/// distinguished for pretty-printing.
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum AttrStyle {
|
||||
AttrOuter,
|
||||
AttrInner,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub struct AttrId(pub usize);
|
||||
|
||||
/// Doc-comments are promoted to attributes that have is_sugared_doc = true
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct Attribute_ {
|
||||
pub id: AttrId,
|
||||
pub style: AttrStyle,
|
||||
pub value: P<MetaItem>,
|
||||
pub is_sugared_doc: bool,
|
||||
}
|
||||
|
||||
/// TraitRef's appear in impls.
|
||||
///
|
||||
/// resolve maps each TraitRef's ref_id to its defining trait; that's all
|
||||
|
@ -36,7 +36,6 @@
|
||||
#![feature(staged_api)]
|
||||
#![feature(str_char)]
|
||||
#![feature(filling_drop)]
|
||||
#![feature(str_escape)]
|
||||
#![cfg_attr(test, feature(test))]
|
||||
|
||||
extern crate serialize;
|
||||
@ -50,7 +49,6 @@ pub mod hir;
|
||||
pub mod lowering;
|
||||
pub mod fold;
|
||||
pub mod visit;
|
||||
pub mod attr;
|
||||
pub mod util;
|
||||
|
||||
pub mod print {
|
||||
|
@ -18,10 +18,6 @@ use syntax::codemap::Spanned;
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
|
||||
|
||||
pub fn lower_meta_items(meta_items: &Vec<P<MetaItem>>) -> Vec<P<hir::MetaItem>> {
|
||||
meta_items.iter().map(|x| lower_meta_item(x)).collect()
|
||||
}
|
||||
|
||||
pub fn lower_view_path(view_path: &ViewPath) -> P<hir::ViewPath> {
|
||||
P(Spanned {
|
||||
node: match view_path.node {
|
||||
@ -54,13 +50,9 @@ pub fn lower_view_path(view_path: &ViewPath) -> P<hir::ViewPath> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn lower_attrs(attrs: &Vec<Attribute>) -> Vec<hir::Attribute> {
|
||||
attrs.iter().map(|x| lower_attribute(x)).collect()
|
||||
}
|
||||
|
||||
pub fn lower_arm(arm: &Arm) -> hir::Arm {
|
||||
hir::Arm {
|
||||
attrs: lower_attrs(&arm.attrs),
|
||||
attrs: arm.attrs.clone(),
|
||||
pats: arm.pats.iter().map(|x| lower_pat(x)).collect(),
|
||||
guard: arm.guard.as_ref().map(|ref x| lower_expr(x)),
|
||||
body: lower_expr(&arm.body),
|
||||
@ -144,7 +136,7 @@ pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
|
||||
node: hir::Variant_ {
|
||||
id: v.node.id,
|
||||
name: v.node.name,
|
||||
attrs: lower_attrs(&v.node.attrs),
|
||||
attrs: v.node.attrs.clone(),
|
||||
kind: match v.node.kind {
|
||||
TupleVariantKind(ref variant_args) => {
|
||||
hir::TupleVariantKind(variant_args.iter().map(|ref x|
|
||||
@ -212,31 +204,6 @@ pub fn lower_local(l: &Local) -> P<hir::Local> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn lower_attribute(at: &Attribute) -> hir::Attribute {
|
||||
Spanned {
|
||||
node: hir::Attribute_ {
|
||||
id: hir::AttrId(at.node.id.0),
|
||||
style: lower_attr_style(at.node.style),
|
||||
value: lower_meta_item(&at.node.value),
|
||||
is_sugared_doc: at.node.is_sugared_doc,
|
||||
},
|
||||
span: at.span,
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME we should probably just unify hir and ast Attributes.
|
||||
pub fn unlower_attribute(at: &hir::Attribute) -> Attribute {
|
||||
Spanned {
|
||||
node: Attribute_ {
|
||||
id: AttrId(at.node.id.0),
|
||||
style: unlower_attr_style(at.node.style),
|
||||
value: unlower_meta_item(&at.node.value),
|
||||
is_sugared_doc: at.node.is_sugared_doc,
|
||||
},
|
||||
span: at.span,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_explicit_self_underscore(es: &ExplicitSelf_) -> hir::ExplicitSelf_ {
|
||||
match *es {
|
||||
SelfStatic => hir::SelfStatic,
|
||||
@ -261,33 +228,6 @@ pub fn lower_explicit_self(s: &ExplicitSelf) -> hir::ExplicitSelf {
|
||||
Spanned { node: lower_explicit_self_underscore(&s.node), span: s.span }
|
||||
}
|
||||
|
||||
|
||||
pub fn lower_meta_item(mi: &MetaItem) -> P<hir::MetaItem> {
|
||||
P(Spanned {
|
||||
node: match mi.node {
|
||||
MetaWord(ref id) => hir::MetaWord(id.clone()),
|
||||
MetaList(ref id, ref mis) => {
|
||||
hir::MetaList(id.clone(), mis.iter().map(|mi| lower_meta_item(mi)).collect())
|
||||
}
|
||||
MetaNameValue(ref id, ref s) => hir::MetaNameValue(id.clone(), lower_lit(s))
|
||||
},
|
||||
span: mi.span,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn unlower_meta_item(mi: &hir::MetaItem) -> P<MetaItem> {
|
||||
P(Spanned {
|
||||
node: match mi.node {
|
||||
hir::MetaWord(ref id) => MetaWord(id.clone()),
|
||||
hir::MetaList(ref id, ref mis) => {
|
||||
MetaList(id.clone(), mis.iter().map(|mi| unlower_meta_item(mi)).collect())
|
||||
}
|
||||
hir::MetaNameValue(ref id, ref s) => MetaNameValue(id.clone(), unlower_lit(s))
|
||||
},
|
||||
span: mi.span,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn lower_arg(arg: &Arg) -> hir::Arg {
|
||||
hir::Arg { id: arg.id, pat: lower_pat(&arg.pat), ty: lower_ty(&arg.ty) }
|
||||
}
|
||||
@ -424,7 +364,7 @@ pub fn lower_struct_field(f: &StructField) -> hir::StructField {
|
||||
id: f.node.id,
|
||||
kind: lower_struct_field_kind(&f.node.kind),
|
||||
ty: lower_ty(&f.node.ty),
|
||||
attrs: lower_attrs(&f.node.attrs),
|
||||
attrs: f.node.attrs.clone(),
|
||||
},
|
||||
span: f.span,
|
||||
}
|
||||
@ -528,7 +468,7 @@ pub fn lower_trait_item(i: &TraitItem) -> P<hir::TraitItem> {
|
||||
P(hir::TraitItem {
|
||||
id: i.id,
|
||||
ident: i.ident,
|
||||
attrs: lower_attrs(&i.attrs),
|
||||
attrs: i.attrs.clone(),
|
||||
node: match i.node {
|
||||
ConstTraitItem(ref ty, ref default) => {
|
||||
hir::ConstTraitItem(lower_ty(ty),
|
||||
@ -551,7 +491,7 @@ pub fn lower_impl_item(i: &ImplItem) -> P<hir::ImplItem> {
|
||||
P(hir::ImplItem {
|
||||
id: i.id,
|
||||
ident: i.ident,
|
||||
attrs: lower_attrs(&i.attrs),
|
||||
attrs: i.attrs.clone(),
|
||||
vis: lower_visibility(i.vis),
|
||||
node: match i.node {
|
||||
ConstImplItem(ref ty, ref expr) => {
|
||||
@ -573,12 +513,10 @@ pub fn lower_mod(m: &Mod) -> hir::Mod {
|
||||
}
|
||||
|
||||
pub fn lower_crate(c: &Crate) -> hir::Crate {
|
||||
let config = lower_meta_items(&c.config);
|
||||
|
||||
hir::Crate {
|
||||
module: lower_mod(&c.module),
|
||||
attrs: lower_attrs(&c.attrs),
|
||||
config: config,
|
||||
attrs: c.attrs.clone(),
|
||||
config: c.config.clone(),
|
||||
span: c.span,
|
||||
exported_macros: c.exported_macros.iter().map(|m| lower_macro_def(m)).collect(),
|
||||
}
|
||||
@ -587,7 +525,7 @@ pub fn lower_crate(c: &Crate) -> hir::Crate {
|
||||
pub fn lower_macro_def(m: &MacroDef) -> hir::MacroDef {
|
||||
hir::MacroDef {
|
||||
ident: m.ident,
|
||||
attrs: m.attrs.iter().map(|a| lower_attribute(a)).collect(),
|
||||
attrs: m.attrs.clone(),
|
||||
id: m.id,
|
||||
span: m.span,
|
||||
imported_from: m.imported_from,
|
||||
@ -610,7 +548,7 @@ pub fn lower_item_simple(i: &Item) -> hir::Item {
|
||||
hir::Item {
|
||||
id: i.id,
|
||||
ident: i.ident,
|
||||
attrs: lower_attrs(&i.attrs),
|
||||
attrs: i.attrs.clone(),
|
||||
node: node,
|
||||
vis: lower_visibility(i.vis),
|
||||
span: i.span,
|
||||
@ -621,7 +559,7 @@ pub fn lower_foreign_item(i: &ForeignItem) -> P<hir::ForeignItem> {
|
||||
P(hir::ForeignItem {
|
||||
id: i.id,
|
||||
ident: i.ident,
|
||||
attrs: lower_attrs(&i.attrs),
|
||||
attrs: i.attrs.clone(),
|
||||
node: match i.node {
|
||||
ForeignItemFn(ref fdec, ref generics) => {
|
||||
hir::ForeignItemFn(lower_fn_decl(fdec), lower_generics(generics))
|
||||
@ -660,37 +598,6 @@ pub fn lower_constness(c: Constness) -> hir::Constness {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_lit(l: &Lit) -> hir::Lit {
|
||||
Spanned {
|
||||
node: match l.node {
|
||||
LitStr(ref i, s) => hir::LitStr(i.clone(), lower_string_style(s)),
|
||||
LitByteStr(ref b) => hir::LitByteStr(b.clone()),
|
||||
LitByte(u) => hir::LitByte(u),
|
||||
LitChar(c) => hir::LitChar(c),
|
||||
LitInt(u, ref t) => hir::LitInt(u, lower_lit_int_type(t)),
|
||||
LitFloat(ref i, t) => hir::LitFloat(i.clone(), lower_float_ty(t)),
|
||||
LitFloatUnsuffixed(ref i) => hir::LitFloatUnsuffixed(i.clone()),
|
||||
LitBool(b) => hir::LitBool(b),
|
||||
},
|
||||
span: l.span,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_lit(l: &hir::Lit) -> Lit {
|
||||
Spanned {
|
||||
node: match l.node {
|
||||
hir::LitStr(ref i, s) => LitStr(i.clone(), unlower_string_style(s)),
|
||||
hir::LitByteStr(ref b) => LitByteStr(b.clone()),
|
||||
hir::LitByte(u) => LitByte(u),
|
||||
hir::LitChar(c) => LitChar(c),
|
||||
hir::LitInt(u, ref t) => LitInt(u, unlower_lit_int_type(t)),
|
||||
hir::LitFloat(ref i, t) => LitFloat(i.clone(), unlower_float_ty(t)),
|
||||
hir::LitFloatUnsuffixed(ref i) => LitFloatUnsuffixed(i.clone()),
|
||||
hir::LitBool(b) => LitBool(b),
|
||||
},
|
||||
span: l.span,
|
||||
}
|
||||
}
|
||||
pub fn lower_unop(u: UnOp) -> hir::UnOp {
|
||||
match u {
|
||||
UnUniq => hir::UnUniq,
|
||||
@ -810,7 +717,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
||||
ExprUnary(op, ref ohs) => {
|
||||
hir::ExprUnary(lower_unop(op), lower_expr(ohs))
|
||||
}
|
||||
ExprLit(ref l) => hir::ExprLit(P(lower_lit(l))),
|
||||
ExprLit(ref l) => hir::ExprLit(P((**l).clone())),
|
||||
ExprCast(ref expr, ref ty) => {
|
||||
hir::ExprCast(lower_expr(expr), lower_ty(ty))
|
||||
}
|
||||
@ -891,7 +798,7 @@ pub fn lower_expr(e: &Expr) -> P<hir::Expr> {
|
||||
(c.clone(), lower_expr(out), *is_rw)
|
||||
}).collect(),
|
||||
asm: asm.clone(),
|
||||
asm_str_style: lower_string_style(asm_str_style),
|
||||
asm_str_style: asm_str_style,
|
||||
clobbers: clobbers.clone(),
|
||||
volatile: volatile,
|
||||
alignstack: alignstack,
|
||||
@ -937,20 +844,6 @@ pub fn lower_stmt(s: &Stmt) -> P<hir::Stmt> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_string_style(s: StrStyle) -> hir::StrStyle {
|
||||
match s {
|
||||
CookedStr => hir::CookedStr,
|
||||
RawStr(u) => hir::RawStr(u),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_string_style(s: hir::StrStyle) -> StrStyle {
|
||||
match s {
|
||||
hir::CookedStr => CookedStr,
|
||||
hir::RawStr(u) => RawStr(u),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_match_source(m: &MatchSource) -> hir::MatchSource {
|
||||
match *m {
|
||||
MatchSource::Normal => hir::MatchSource::Normal,
|
||||
@ -1027,107 +920,9 @@ pub fn lower_impl_polarity(i: ImplPolarity) -> hir::ImplPolarity {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_float_ty(f: FloatTy) -> hir::FloatTy {
|
||||
match f {
|
||||
TyF32 => hir::TyF32,
|
||||
TyF64 => hir::TyF64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_float_ty(f: hir::FloatTy) -> FloatTy {
|
||||
match f {
|
||||
hir::TyF32 => TyF32,
|
||||
hir::TyF64 => TyF64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_lit_int_type(i: &LitIntType) -> hir::LitIntType {
|
||||
match *i {
|
||||
SignedIntLit(i, s) => hir::SignedIntLit(lower_int_ty(i), lower_sign(s)),
|
||||
UnsignedIntLit(u) => hir::UnsignedIntLit(lower_uint_ty(u)),
|
||||
UnsuffixedIntLit(s) => hir::UnsuffixedIntLit(lower_sign(s)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_lit_int_type(i: &hir::LitIntType) -> LitIntType {
|
||||
match *i {
|
||||
hir::SignedIntLit(i, s) => SignedIntLit(unlower_int_ty(i), unlower_sign(s)),
|
||||
hir::UnsignedIntLit(u) => UnsignedIntLit(unlower_uint_ty(u)),
|
||||
hir::UnsuffixedIntLit(s) => UnsuffixedIntLit(unlower_sign(s)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_int_ty(i: IntTy) -> hir::IntTy {
|
||||
match i {
|
||||
TyIs => hir::TyIs,
|
||||
TyI8 => hir::TyI8,
|
||||
TyI16 => hir::TyI16,
|
||||
TyI32 => hir::TyI32,
|
||||
TyI64 => hir::TyI64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_int_ty(i: hir::IntTy) -> IntTy {
|
||||
match i {
|
||||
hir::TyIs => TyIs,
|
||||
hir::TyI8 => TyI8,
|
||||
hir::TyI16 => TyI16,
|
||||
hir::TyI32 => TyI32,
|
||||
hir::TyI64 => TyI64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_uint_ty(u: UintTy) -> hir::UintTy {
|
||||
match u {
|
||||
TyUs => hir::TyUs,
|
||||
TyU8 => hir::TyU8,
|
||||
TyU16 => hir::TyU16,
|
||||
TyU32 => hir::TyU32,
|
||||
TyU64 => hir::TyU64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_uint_ty(u: hir::UintTy) -> UintTy {
|
||||
match u {
|
||||
hir::TyUs => TyUs,
|
||||
hir::TyU8 => TyU8,
|
||||
hir::TyU16 => TyU16,
|
||||
hir::TyU32 => TyU32,
|
||||
hir::TyU64 => TyU64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_sign(f: Sign) -> hir::Sign {
|
||||
match f {
|
||||
Minus => hir::Minus,
|
||||
Plus => hir::Plus,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_sign(f: hir::Sign) -> Sign {
|
||||
match f {
|
||||
hir::Minus => Minus,
|
||||
hir::Plus => Plus,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_trait_bound_modifier(f: TraitBoundModifier) -> hir::TraitBoundModifier {
|
||||
match f {
|
||||
TraitBoundModifier::None => hir::TraitBoundModifier::None,
|
||||
TraitBoundModifier::Maybe => hir::TraitBoundModifier::Maybe,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_attr_style(f: AttrStyle) -> hir::AttrStyle {
|
||||
match f {
|
||||
AttrOuter => hir::AttrOuter,
|
||||
AttrInner => hir::AttrInner,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unlower_attr_style(f: hir::AttrStyle) -> AttrStyle {
|
||||
match f {
|
||||
hir::AttrOuter => AttrOuter,
|
||||
hir::AttrInner => AttrInner,
|
||||
}
|
||||
}
|
||||
|
@ -1,686 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
//! This pretty-printer is a direct reimplementation of Philip Karlton's
|
||||
//! Mesa pretty-printer, as described in appendix A of
|
||||
//!
|
||||
//! STAN-CS-79-770: "Pretty Printing", by Derek C. Oppen.
|
||||
//! Stanford Department of Computer Science, 1979.
|
||||
//!
|
||||
//! The algorithm's aim is to break a stream into as few lines as possible
|
||||
//! while respecting the indentation-consistency requirements of the enclosing
|
||||
//! block, and avoiding breaking at silly places on block boundaries, for
|
||||
//! example, between "x" and ")" in "x)".
|
||||
//!
|
||||
//! I am implementing this algorithm because it comes with 20 pages of
|
||||
//! documentation explaining its theory, and because it addresses the set of
|
||||
//! concerns I've seen other pretty-printers fall down on. Weirdly. Even though
|
||||
//! it's 32 years old. What can I say?
|
||||
//!
|
||||
//! Despite some redundancies and quirks in the way it's implemented in that
|
||||
//! paper, I've opted to keep the implementation here as similar as I can,
|
||||
//! changing only what was blatantly wrong, a typo, or sufficiently
|
||||
//! non-idiomatic rust that it really stuck out.
|
||||
//!
|
||||
//! In particular you'll see a certain amount of churn related to INTEGER vs.
|
||||
//! CARDINAL in the Mesa implementation. Mesa apparently interconverts the two
|
||||
//! somewhat readily? In any case, I've used usize for indices-in-buffers and
|
||||
//! ints for character-sizes-and-indentation-offsets. This respects the need
|
||||
//! for ints to "go negative" while carrying a pending-calculation balance, and
|
||||
//! helps differentiate all the numbers flying around internally (slightly).
|
||||
//!
|
||||
//! I also inverted the indentation arithmetic used in the print stack, since
|
||||
//! the Mesa implementation (somewhat randomly) stores the offset on the print
|
||||
//! stack in terms of margin-col rather than col itself. I store col.
|
||||
//!
|
||||
//! I also implemented a small change in the String token, in that I store an
|
||||
//! explicit length for the string. For most tokens this is just the length of
|
||||
//! the accompanying string. But it's necessary to permit it to differ, for
|
||||
//! encoding things that are supposed to "go on their own line" -- certain
|
||||
//! classes of comment and blank-line -- where relying on adjacent
|
||||
//! hardbreak-like Break tokens with long blankness indication doesn't actually
|
||||
//! work. To see why, consider when there is a "thing that should be on its own
|
||||
//! line" between two long blocks, say functions. If you put a hardbreak after
|
||||
//! each function (or before each) and the breaking algorithm decides to break
|
||||
//! there anyways (because the functions themselves are long) you wind up with
|
||||
//! extra blank lines. If you don't put hardbreaks you can wind up with the
|
||||
//! "thing which should be on its own line" not getting its own line in the
|
||||
//! rare case of "really small functions" or such. This re-occurs with comments
|
||||
//! and explicit blank lines. So in those cases we use a string with a payload
|
||||
//! we want isolated to a line and an explicit length that's huge, surrounded
|
||||
//! by two zero-length breaks. The algorithm will try its best to fit it on a
|
||||
//! line (which it can't) and so naturally place the content on its own line to
|
||||
//! avoid combining it with other lines and making matters even worse.
|
||||
|
||||
use std::io;
|
||||
use std::string;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum Breaks {
|
||||
Consistent,
|
||||
Inconsistent,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct BreakToken {
|
||||
offset: isize,
|
||||
blank_space: isize
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct BeginToken {
|
||||
offset: isize,
|
||||
breaks: Breaks
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Token {
|
||||
String(String, isize),
|
||||
Break(BreakToken),
|
||||
Begin(BeginToken),
|
||||
End,
|
||||
Eof,
|
||||
}
|
||||
|
||||
impl Token {
|
||||
pub fn is_eof(&self) -> bool {
|
||||
match *self {
|
||||
Token::Eof => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_hardbreak_tok(&self) -> bool {
|
||||
match *self {
|
||||
Token::Break(BreakToken {
|
||||
offset: 0,
|
||||
blank_space: bs
|
||||
}) if bs == SIZE_INFINITY =>
|
||||
true,
|
||||
_ =>
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tok_str(token: &Token) -> String {
|
||||
match *token {
|
||||
Token::String(ref s, len) => format!("STR({},{})", s, len),
|
||||
Token::Break(_) => "BREAK".to_string(),
|
||||
Token::Begin(_) => "BEGIN".to_string(),
|
||||
Token::End => "END".to_string(),
|
||||
Token::Eof => "EOF".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn buf_str(toks: &[Token],
|
||||
szs: &[isize],
|
||||
left: usize,
|
||||
right: usize,
|
||||
lim: usize)
|
||||
-> String {
|
||||
let n = toks.len();
|
||||
assert_eq!(n, szs.len());
|
||||
let mut i = left;
|
||||
let mut l = lim;
|
||||
let mut s = string::String::from("[");
|
||||
while i != right && l != 0 {
|
||||
l -= 1;
|
||||
if i != left {
|
||||
s.push_str(", ");
|
||||
}
|
||||
s.push_str(&format!("{}={}",
|
||||
szs[i],
|
||||
tok_str(&toks[i])));
|
||||
i += 1;
|
||||
i %= n;
|
||||
}
|
||||
s.push(']');
|
||||
s
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum PrintStackBreak {
|
||||
Fits,
|
||||
Broken(Breaks),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PrintStackElem {
|
||||
offset: isize,
|
||||
pbreak: PrintStackBreak
|
||||
}
|
||||
|
||||
const SIZE_INFINITY: isize = 0xffff;
|
||||
|
||||
pub fn mk_printer<'a>(out: Box<io::Write+'a>, linewidth: usize) -> Printer<'a> {
|
||||
// Yes 3, it makes the ring buffers big enough to never
|
||||
// fall behind.
|
||||
let n: usize = 3 * linewidth;
|
||||
debug!("mk_printer {}", linewidth);
|
||||
let token = vec![Token::Eof; n];
|
||||
let size = vec![0_isize; n];
|
||||
let scan_stack = vec![0_usize; n];
|
||||
Printer {
|
||||
out: out,
|
||||
buf_len: n,
|
||||
margin: linewidth as isize,
|
||||
space: linewidth as isize,
|
||||
left: 0,
|
||||
right: 0,
|
||||
token: token,
|
||||
size: size,
|
||||
left_total: 0,
|
||||
right_total: 0,
|
||||
scan_stack: scan_stack,
|
||||
scan_stack_empty: true,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
print_stack: Vec::new(),
|
||||
pending_indentation: 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// In case you do not have the paper, here is an explanation of what's going
|
||||
/// on.
|
||||
///
|
||||
/// There is a stream of input tokens flowing through this printer.
|
||||
///
|
||||
/// The printer buffers up to 3N tokens inside itself, where N is linewidth.
|
||||
/// Yes, linewidth is chars and tokens are multi-char, but in the worst
|
||||
/// case every token worth buffering is 1 char long, so it's ok.
|
||||
///
|
||||
/// Tokens are String, Break, and Begin/End to delimit blocks.
|
||||
///
|
||||
/// Begin tokens can carry an offset, saying "how far to indent when you break
|
||||
/// inside here", as well as a flag indicating "consistent" or "inconsistent"
|
||||
/// breaking. Consistent breaking means that after the first break, no attempt
|
||||
/// will be made to flow subsequent breaks together onto lines. Inconsistent
|
||||
/// is the opposite. Inconsistent breaking example would be, say:
|
||||
///
|
||||
/// foo(hello, there, good, friends)
|
||||
///
|
||||
/// breaking inconsistently to become
|
||||
///
|
||||
/// foo(hello, there
|
||||
/// good, friends);
|
||||
///
|
||||
/// whereas a consistent breaking would yield:
|
||||
///
|
||||
/// foo(hello,
|
||||
/// there
|
||||
/// good,
|
||||
/// friends);
|
||||
///
|
||||
/// That is, in the consistent-break blocks we value vertical alignment
|
||||
/// more than the ability to cram stuff onto a line. But in all cases if it
|
||||
/// can make a block a one-liner, it'll do so.
|
||||
///
|
||||
/// Carrying on with high-level logic:
|
||||
///
|
||||
/// The buffered tokens go through a ring-buffer, 'tokens'. The 'left' and
|
||||
/// 'right' indices denote the active portion of the ring buffer as well as
|
||||
/// describing hypothetical points-in-the-infinite-stream at most 3N tokens
|
||||
/// apart (i.e. "not wrapped to ring-buffer boundaries"). The paper will switch
|
||||
/// between using 'left' and 'right' terms to denote the wrapped-to-ring-buffer
|
||||
/// and point-in-infinite-stream senses freely.
|
||||
///
|
||||
/// There is a parallel ring buffer, 'size', that holds the calculated size of
|
||||
/// each token. Why calculated? Because for Begin/End pairs, the "size"
|
||||
/// includes everything between the pair. That is, the "size" of Begin is
|
||||
/// actually the sum of the sizes of everything between Begin and the paired
|
||||
/// End that follows. Since that is arbitrarily far in the future, 'size' is
|
||||
/// being rewritten regularly while the printer runs; in fact most of the
|
||||
/// machinery is here to work out 'size' entries on the fly (and give up when
|
||||
/// they're so obviously over-long that "infinity" is a good enough
|
||||
/// approximation for purposes of line breaking).
|
||||
///
|
||||
/// The "input side" of the printer is managed as an abstract process called
|
||||
/// SCAN, which uses 'scan_stack', 'scan_stack_empty', 'top' and 'bottom', to
|
||||
/// manage calculating 'size'. SCAN is, in other words, the process of
|
||||
/// calculating 'size' entries.
|
||||
///
|
||||
/// The "output side" of the printer is managed by an abstract process called
|
||||
/// PRINT, which uses 'print_stack', 'margin' and 'space' to figure out what to
|
||||
/// do with each token/size pair it consumes as it goes. It's trying to consume
|
||||
/// the entire buffered window, but can't output anything until the size is >=
|
||||
/// 0 (sizes are set to negative while they're pending calculation).
|
||||
///
|
||||
/// So SCAN takes input and buffers tokens and pending calculations, while
|
||||
/// PRINT gobbles up completed calculations and tokens from the buffer. The
|
||||
/// theory is that the two can never get more than 3N tokens apart, because
|
||||
/// once there's "obviously" too much data to fit on a line, in a size
|
||||
/// calculation, SCAN will write "infinity" to the size and let PRINT consume
|
||||
/// it.
|
||||
///
|
||||
/// In this implementation (following the paper, again) the SCAN process is
|
||||
/// the method called 'pretty_print', and the 'PRINT' process is the method
|
||||
/// called 'print'.
|
||||
pub struct Printer<'a> {
|
||||
pub out: Box<io::Write+'a>,
|
||||
buf_len: usize,
|
||||
/// Width of lines we're constrained to
|
||||
margin: isize,
|
||||
/// Number of spaces left on line
|
||||
space: isize,
|
||||
/// Index of left side of input stream
|
||||
left: usize,
|
||||
/// Index of right side of input stream
|
||||
right: usize,
|
||||
/// Ring-buffer stream goes through
|
||||
token: Vec<Token> ,
|
||||
/// Ring-buffer of calculated sizes
|
||||
size: Vec<isize> ,
|
||||
/// Running size of stream "...left"
|
||||
left_total: isize,
|
||||
/// Running size of stream "...right"
|
||||
right_total: isize,
|
||||
/// Pseudo-stack, really a ring too. Holds the
|
||||
/// primary-ring-buffers index of the Begin that started the
|
||||
/// current block, possibly with the most recent Break after that
|
||||
/// Begin (if there is any) on top of it. Stuff is flushed off the
|
||||
/// bottom as it becomes irrelevant due to the primary ring-buffer
|
||||
/// advancing.
|
||||
scan_stack: Vec<usize> ,
|
||||
/// Top==bottom disambiguator
|
||||
scan_stack_empty: bool,
|
||||
/// Index of top of scan_stack
|
||||
top: usize,
|
||||
/// Index of bottom of scan_stack
|
||||
bottom: usize,
|
||||
/// Stack of blocks-in-progress being flushed by print
|
||||
print_stack: Vec<PrintStackElem> ,
|
||||
/// Buffered indentation to avoid writing trailing whitespace
|
||||
pending_indentation: isize,
|
||||
}
|
||||
|
||||
impl<'a> Printer<'a> {
|
||||
pub fn last_token(&mut self) -> Token {
|
||||
self.token[self.right].clone()
|
||||
}
|
||||
// be very careful with this!
|
||||
pub fn replace_last_token(&mut self, t: Token) {
|
||||
self.token[self.right] = t;
|
||||
}
|
||||
pub fn pretty_print(&mut self, token: Token) -> io::Result<()> {
|
||||
debug!("pp Vec<{},{}>", self.left, self.right);
|
||||
match token {
|
||||
Token::Eof => {
|
||||
if !self.scan_stack_empty {
|
||||
self.check_stack(0);
|
||||
try!(self.advance_left());
|
||||
}
|
||||
self.indent(0);
|
||||
Ok(())
|
||||
}
|
||||
Token::Begin(b) => {
|
||||
if self.scan_stack_empty {
|
||||
self.left_total = 1;
|
||||
self.right_total = 1;
|
||||
self.left = 0;
|
||||
self.right = 0;
|
||||
} else { self.advance_right(); }
|
||||
debug!("pp Begin({})/buffer Vec<{},{}>",
|
||||
b.offset, self.left, self.right);
|
||||
self.token[self.right] = token;
|
||||
self.size[self.right] = -self.right_total;
|
||||
let right = self.right;
|
||||
self.scan_push(right);
|
||||
Ok(())
|
||||
}
|
||||
Token::End => {
|
||||
if self.scan_stack_empty {
|
||||
debug!("pp End/print Vec<{},{}>", self.left, self.right);
|
||||
self.print(token, 0)
|
||||
} else {
|
||||
debug!("pp End/buffer Vec<{},{}>", self.left, self.right);
|
||||
self.advance_right();
|
||||
self.token[self.right] = token;
|
||||
self.size[self.right] = -1;
|
||||
let right = self.right;
|
||||
self.scan_push(right);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Token::Break(b) => {
|
||||
if self.scan_stack_empty {
|
||||
self.left_total = 1;
|
||||
self.right_total = 1;
|
||||
self.left = 0;
|
||||
self.right = 0;
|
||||
} else { self.advance_right(); }
|
||||
debug!("pp Break({})/buffer Vec<{},{}>",
|
||||
b.offset, self.left, self.right);
|
||||
self.check_stack(0);
|
||||
let right = self.right;
|
||||
self.scan_push(right);
|
||||
self.token[self.right] = token;
|
||||
self.size[self.right] = -self.right_total;
|
||||
self.right_total += b.blank_space;
|
||||
Ok(())
|
||||
}
|
||||
Token::String(s, len) => {
|
||||
if self.scan_stack_empty {
|
||||
debug!("pp String('{}')/print Vec<{},{}>",
|
||||
s, self.left, self.right);
|
||||
self.print(Token::String(s, len), len)
|
||||
} else {
|
||||
debug!("pp String('{}')/buffer Vec<{},{}>",
|
||||
s, self.left, self.right);
|
||||
self.advance_right();
|
||||
self.token[self.right] = Token::String(s, len);
|
||||
self.size[self.right] = len;
|
||||
self.right_total += len;
|
||||
self.check_stream()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn check_stream(&mut self) -> io::Result<()> {
|
||||
debug!("check_stream Vec<{}, {}> with left_total={}, right_total={}",
|
||||
self.left, self.right, self.left_total, self.right_total);
|
||||
if self.right_total - self.left_total > self.space {
|
||||
debug!("scan window is {}, longer than space on line ({})",
|
||||
self.right_total - self.left_total, self.space);
|
||||
if !self.scan_stack_empty {
|
||||
if self.left == self.scan_stack[self.bottom] {
|
||||
debug!("setting {} to infinity and popping", self.left);
|
||||
let scanned = self.scan_pop_bottom();
|
||||
self.size[scanned] = SIZE_INFINITY;
|
||||
}
|
||||
}
|
||||
try!(self.advance_left());
|
||||
if self.left != self.right {
|
||||
try!(self.check_stream());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn scan_push(&mut self, x: usize) {
|
||||
debug!("scan_push {}", x);
|
||||
if self.scan_stack_empty {
|
||||
self.scan_stack_empty = false;
|
||||
} else {
|
||||
self.top += 1;
|
||||
self.top %= self.buf_len;
|
||||
assert!((self.top != self.bottom));
|
||||
}
|
||||
self.scan_stack[self.top] = x;
|
||||
}
|
||||
pub fn scan_pop(&mut self) -> usize {
|
||||
assert!((!self.scan_stack_empty));
|
||||
let x = self.scan_stack[self.top];
|
||||
if self.top == self.bottom {
|
||||
self.scan_stack_empty = true;
|
||||
} else {
|
||||
self.top += self.buf_len - 1; self.top %= self.buf_len;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
pub fn scan_top(&mut self) -> usize {
|
||||
assert!((!self.scan_stack_empty));
|
||||
return self.scan_stack[self.top];
|
||||
}
|
||||
pub fn scan_pop_bottom(&mut self) -> usize {
|
||||
assert!((!self.scan_stack_empty));
|
||||
let x = self.scan_stack[self.bottom];
|
||||
if self.top == self.bottom {
|
||||
self.scan_stack_empty = true;
|
||||
} else {
|
||||
self.bottom += 1; self.bottom %= self.buf_len;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
pub fn advance_right(&mut self) {
|
||||
self.right += 1;
|
||||
self.right %= self.buf_len;
|
||||
assert!((self.right != self.left));
|
||||
}
|
||||
pub fn advance_left(&mut self) -> io::Result<()> {
|
||||
debug!("advance_left Vec<{},{}>, sizeof({})={}", self.left, self.right,
|
||||
self.left, self.size[self.left]);
|
||||
|
||||
let mut left_size = self.size[self.left];
|
||||
|
||||
while left_size >= 0 {
|
||||
let left = self.token[self.left].clone();
|
||||
|
||||
let len = match left {
|
||||
Token::Break(b) => b.blank_space,
|
||||
Token::String(_, len) => {
|
||||
assert_eq!(len, left_size);
|
||||
len
|
||||
}
|
||||
_ => 0
|
||||
};
|
||||
|
||||
try!(self.print(left, left_size));
|
||||
|
||||
self.left_total += len;
|
||||
|
||||
if self.left == self.right {
|
||||
break;
|
||||
}
|
||||
|
||||
self.left += 1;
|
||||
self.left %= self.buf_len;
|
||||
|
||||
left_size = self.size[self.left];
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub fn check_stack(&mut self, k: isize) {
|
||||
if !self.scan_stack_empty {
|
||||
let x = self.scan_top();
|
||||
match self.token[x] {
|
||||
Token::Begin(_) => {
|
||||
if k > 0 {
|
||||
let popped = self.scan_pop();
|
||||
self.size[popped] = self.size[x] + self.right_total;
|
||||
self.check_stack(k - 1);
|
||||
}
|
||||
}
|
||||
Token::End => {
|
||||
// paper says + not =, but that makes no sense.
|
||||
let popped = self.scan_pop();
|
||||
self.size[popped] = 1;
|
||||
self.check_stack(k + 1);
|
||||
}
|
||||
_ => {
|
||||
let popped = self.scan_pop();
|
||||
self.size[popped] = self.size[x] + self.right_total;
|
||||
if k > 0 {
|
||||
self.check_stack(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn print_newline(&mut self, amount: isize) -> io::Result<()> {
|
||||
debug!("NEWLINE {}", amount);
|
||||
let ret = write!(self.out, "\n");
|
||||
self.pending_indentation = 0;
|
||||
self.indent(amount);
|
||||
return ret;
|
||||
}
|
||||
pub fn indent(&mut self, amount: isize) {
|
||||
debug!("INDENT {}", amount);
|
||||
self.pending_indentation += amount;
|
||||
}
|
||||
pub fn get_top(&mut self) -> PrintStackElem {
|
||||
let print_stack = &mut self.print_stack;
|
||||
let n = print_stack.len();
|
||||
if n != 0 {
|
||||
(*print_stack)[n - 1]
|
||||
} else {
|
||||
PrintStackElem {
|
||||
offset: 0,
|
||||
pbreak: PrintStackBreak::Broken(Breaks::Inconsistent)
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn print_str(&mut self, s: &str) -> io::Result<()> {
|
||||
while self.pending_indentation > 0 {
|
||||
try!(write!(self.out, " "));
|
||||
self.pending_indentation -= 1;
|
||||
}
|
||||
write!(self.out, "{}", s)
|
||||
}
|
||||
pub fn print(&mut self, token: Token, l: isize) -> io::Result<()> {
|
||||
debug!("print {} {} (remaining line space={})", tok_str(&token), l,
|
||||
self.space);
|
||||
debug!("{}", buf_str(&self.token,
|
||||
&self.size,
|
||||
self.left,
|
||||
self.right,
|
||||
6));
|
||||
match token {
|
||||
Token::Begin(b) => {
|
||||
if l > self.space {
|
||||
let col = self.margin - self.space + b.offset;
|
||||
debug!("print Begin -> push broken block at col {}", col);
|
||||
self.print_stack.push(PrintStackElem {
|
||||
offset: col,
|
||||
pbreak: PrintStackBreak::Broken(b.breaks)
|
||||
});
|
||||
} else {
|
||||
debug!("print Begin -> push fitting block");
|
||||
self.print_stack.push(PrintStackElem {
|
||||
offset: 0,
|
||||
pbreak: PrintStackBreak::Fits
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Token::End => {
|
||||
debug!("print End -> pop End");
|
||||
let print_stack = &mut self.print_stack;
|
||||
assert!((!print_stack.is_empty()));
|
||||
print_stack.pop().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
Token::Break(b) => {
|
||||
let top = self.get_top();
|
||||
match top.pbreak {
|
||||
PrintStackBreak::Fits => {
|
||||
debug!("print Break({}) in fitting block", b.blank_space);
|
||||
self.space -= b.blank_space;
|
||||
self.indent(b.blank_space);
|
||||
Ok(())
|
||||
}
|
||||
PrintStackBreak::Broken(Breaks::Consistent) => {
|
||||
debug!("print Break({}+{}) in consistent block",
|
||||
top.offset, b.offset);
|
||||
let ret = self.print_newline(top.offset + b.offset);
|
||||
self.space = self.margin - (top.offset + b.offset);
|
||||
ret
|
||||
}
|
||||
PrintStackBreak::Broken(Breaks::Inconsistent) => {
|
||||
if l > self.space {
|
||||
debug!("print Break({}+{}) w/ newline in inconsistent",
|
||||
top.offset, b.offset);
|
||||
let ret = self.print_newline(top.offset + b.offset);
|
||||
self.space = self.margin - (top.offset + b.offset);
|
||||
ret
|
||||
} else {
|
||||
debug!("print Break({}) w/o newline in inconsistent",
|
||||
b.blank_space);
|
||||
self.indent(b.blank_space);
|
||||
self.space -= b.blank_space;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Token::String(s, len) => {
|
||||
debug!("print String({})", s);
|
||||
assert_eq!(l, len);
|
||||
// assert!(l <= space);
|
||||
self.space -= len;
|
||||
self.print_str(&s[..])
|
||||
}
|
||||
Token::Eof => {
|
||||
// Eof should never get here.
|
||||
panic!();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convenience functions to talk to the printer.
|
||||
//
|
||||
// "raw box"
|
||||
pub fn rbox(p: &mut Printer, indent: usize, b: Breaks) -> io::Result<()> {
|
||||
p.pretty_print(Token::Begin(BeginToken {
|
||||
offset: indent as isize,
|
||||
breaks: b
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn ibox(p: &mut Printer, indent: usize) -> io::Result<()> {
|
||||
rbox(p, indent, Breaks::Inconsistent)
|
||||
}
|
||||
|
||||
pub fn cbox(p: &mut Printer, indent: usize) -> io::Result<()> {
|
||||
rbox(p, indent, Breaks::Consistent)
|
||||
}
|
||||
|
||||
pub fn break_offset(p: &mut Printer, n: usize, off: isize) -> io::Result<()> {
|
||||
p.pretty_print(Token::Break(BreakToken {
|
||||
offset: off,
|
||||
blank_space: n as isize
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn end(p: &mut Printer) -> io::Result<()> {
|
||||
p.pretty_print(Token::End)
|
||||
}
|
||||
|
||||
pub fn eof(p: &mut Printer) -> io::Result<()> {
|
||||
p.pretty_print(Token::Eof)
|
||||
}
|
||||
|
||||
pub fn word(p: &mut Printer, wrd: &str) -> io::Result<()> {
|
||||
p.pretty_print(Token::String(/* bad */ wrd.to_string(), wrd.len() as isize))
|
||||
}
|
||||
|
||||
pub fn huge_word(p: &mut Printer, wrd: &str) -> io::Result<()> {
|
||||
p.pretty_print(Token::String(/* bad */ wrd.to_string(), SIZE_INFINITY))
|
||||
}
|
||||
|
||||
pub fn zero_word(p: &mut Printer, wrd: &str) -> io::Result<()> {
|
||||
p.pretty_print(Token::String(/* bad */ wrd.to_string(), 0))
|
||||
}
|
||||
|
||||
pub fn spaces(p: &mut Printer, n: usize) -> io::Result<()> {
|
||||
break_offset(p, n, 0)
|
||||
}
|
||||
|
||||
pub fn zerobreak(p: &mut Printer) -> io::Result<()> {
|
||||
spaces(p, 0)
|
||||
}
|
||||
|
||||
pub fn space(p: &mut Printer) -> io::Result<()> {
|
||||
spaces(p, 1)
|
||||
}
|
||||
|
||||
pub fn hardbreak(p: &mut Printer) -> io::Result<()> {
|
||||
spaces(p, SIZE_INFINITY as usize)
|
||||
}
|
||||
|
||||
pub fn hardbreak_tok_offset(off: isize) -> Token {
|
||||
Token::Break(BreakToken {offset: off, blank_space: SIZE_INFINITY})
|
||||
}
|
||||
|
||||
pub fn hardbreak_tok() -> Token {
|
||||
hardbreak_tok_offset(0)
|
||||
}
|
@ -18,18 +18,16 @@ use syntax::diagnostic;
|
||||
use syntax::parse::token::{self, BinOpToken};
|
||||
use syntax::parse::lexer::comments;
|
||||
use syntax::parse;
|
||||
use syntax::print::pp::{self, break_offset, word, space, zerobreak, hardbreak};
|
||||
use syntax::print::pp::{self, break_offset, word, space, hardbreak};
|
||||
use syntax::print::pp::{Breaks, eof};
|
||||
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
|
||||
use syntax::print::pprust::{self as ast_pp, PrintState};
|
||||
use syntax::ptr::P;
|
||||
|
||||
use hir;
|
||||
use hir::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
|
||||
use attr::{AttrMetaMethods, AttributeMethods};
|
||||
|
||||
use std::ascii;
|
||||
use std::io::{self, Write, Read};
|
||||
use std::iter;
|
||||
|
||||
pub enum AnnNode<'a> {
|
||||
NodeIdent(&'a ast::Ident),
|
||||
@ -51,22 +49,39 @@ pub struct NoAnn;
|
||||
|
||||
impl PpAnn for NoAnn {}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct CurrentCommentAndLiteral {
|
||||
cur_cmnt: usize,
|
||||
cur_lit: usize,
|
||||
}
|
||||
|
||||
pub struct State<'a> {
|
||||
pub s: pp::Printer<'a>,
|
||||
cm: Option<&'a CodeMap>,
|
||||
comments: Option<Vec<comments::Comment> >,
|
||||
literals: Option<Vec<comments::Literal> >,
|
||||
cur_cmnt_and_lit: CurrentCommentAndLiteral,
|
||||
comments: Option<Vec<comments::Comment>>,
|
||||
literals: Option<Vec<comments::Literal>>,
|
||||
cur_cmnt_and_lit: ast_pp::CurrentCommentAndLiteral,
|
||||
boxes: Vec<pp::Breaks>,
|
||||
ann: &'a (PpAnn+'a),
|
||||
}
|
||||
|
||||
impl<'a> PrintState<'a> for State<'a> {
|
||||
fn writer(&mut self) -> &mut pp::Printer<'a> {
|
||||
&mut self.s
|
||||
}
|
||||
|
||||
fn boxes(&mut self) -> &mut Vec<pp::Breaks> {
|
||||
&mut self.boxes
|
||||
}
|
||||
|
||||
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
|
||||
&mut self.comments
|
||||
}
|
||||
|
||||
fn cur_cmnt_and_lit(&mut self) -> &mut ast_pp::CurrentCommentAndLiteral {
|
||||
&mut self.cur_cmnt_and_lit
|
||||
}
|
||||
|
||||
fn literals(&self) -> &Option<Vec<comments::Literal>> {
|
||||
&self.literals
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rust_printer<'a>(writer: Box<Write+'a>) -> State<'a> {
|
||||
static NO_ANN: NoAnn = NoAnn;
|
||||
rust_printer_annotated(writer, &NO_ANN)
|
||||
@ -79,7 +94,7 @@ pub fn rust_printer_annotated<'a>(writer: Box<Write+'a>,
|
||||
cm: None,
|
||||
comments: None,
|
||||
literals: None,
|
||||
cur_cmnt_and_lit: CurrentCommentAndLiteral {
|
||||
cur_cmnt_and_lit: ast_pp::CurrentCommentAndLiteral {
|
||||
cur_cmnt: 0,
|
||||
cur_lit: 0
|
||||
},
|
||||
@ -154,9 +169,9 @@ impl<'a> State<'a> {
|
||||
State {
|
||||
s: pp::mk_printer(out, default_columns),
|
||||
cm: Some(cm),
|
||||
comments: comments,
|
||||
literals: literals,
|
||||
cur_cmnt_and_lit: CurrentCommentAndLiteral {
|
||||
comments: comments.clone(),
|
||||
literals: literals.clone(),
|
||||
cur_cmnt_and_lit: ast_pp::CurrentCommentAndLiteral {
|
||||
cur_cmnt: 0,
|
||||
cur_lit: 0
|
||||
},
|
||||
@ -221,10 +236,6 @@ pub fn stmt_to_string(stmt: &hir::Stmt) -> String {
|
||||
to_string(|s| s.print_stmt(stmt))
|
||||
}
|
||||
|
||||
pub fn attr_to_string(attr: &hir::Attribute) -> String {
|
||||
to_string(|s| s.print_attribute(attr))
|
||||
}
|
||||
|
||||
pub fn item_to_string(i: &hir::Item) -> String {
|
||||
to_string(|s| s.print_item(i))
|
||||
}
|
||||
@ -283,18 +294,6 @@ pub fn block_to_string(blk: &hir::Block) -> String {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn meta_item_to_string(mi: &hir::MetaItem) -> String {
|
||||
to_string(|s| s.print_meta_item(mi))
|
||||
}
|
||||
|
||||
pub fn attribute_to_string(attr: &hir::Attribute) -> String {
|
||||
to_string(|s| s.print_attribute(attr))
|
||||
}
|
||||
|
||||
pub fn lit_to_string(l: &hir::Lit) -> String {
|
||||
to_string(|s| s.print_literal(l))
|
||||
}
|
||||
|
||||
pub fn explicit_self_to_string(explicit_self: &hir::ExplicitSelf_) -> String {
|
||||
to_string(|s| s.print_explicit_self(explicit_self, hir::MutImmutable).map(|_| {}))
|
||||
}
|
||||
@ -324,27 +323,11 @@ fn needs_parentheses(expr: &hir::Expr) -> bool {
|
||||
}
|
||||
|
||||
impl<'a> State<'a> {
|
||||
pub fn ibox(&mut self, u: usize) -> io::Result<()> {
|
||||
self.boxes.push(pp::Breaks::Inconsistent);
|
||||
pp::ibox(&mut self.s, u)
|
||||
}
|
||||
|
||||
pub fn end(&mut self) -> io::Result<()> {
|
||||
self.boxes.pop().unwrap();
|
||||
pp::end(&mut self.s)
|
||||
}
|
||||
|
||||
pub fn cbox(&mut self, u: usize) -> io::Result<()> {
|
||||
self.boxes.push(pp::Breaks::Consistent);
|
||||
pp::cbox(&mut self.s, u)
|
||||
}
|
||||
|
||||
// "raw box"
|
||||
pub fn rbox(&mut self, u: usize, b: pp::Breaks) -> io::Result<()> {
|
||||
self.boxes.push(b);
|
||||
pp::rbox(&mut self.s, u, b)
|
||||
}
|
||||
|
||||
pub fn nbsp(&mut self) -> io::Result<()> { word(&mut self.s, " ") }
|
||||
|
||||
pub fn word_nbsp(&mut self, w: &str) -> io::Result<()> {
|
||||
@ -352,15 +335,6 @@ impl<'a> State<'a> {
|
||||
self.nbsp()
|
||||
}
|
||||
|
||||
pub fn word_space(&mut self, w: &str) -> io::Result<()> {
|
||||
try!(word(&mut self.s, w));
|
||||
space(&mut self.s)
|
||||
}
|
||||
|
||||
pub fn popen(&mut self) -> io::Result<()> { word(&mut self.s, "(") }
|
||||
|
||||
pub fn pclose(&mut self) -> io::Result<()> { word(&mut self.s, ")") }
|
||||
|
||||
pub fn head(&mut self, w: &str) -> io::Result<()> {
|
||||
// outer-box is consistent
|
||||
try!(self.cbox(indent_unit));
|
||||
@ -396,38 +370,12 @@ impl<'a> State<'a> {
|
||||
self.bclose_(span, indent_unit)
|
||||
}
|
||||
|
||||
pub fn is_begin(&mut self) -> bool {
|
||||
match self.s.last_token() {
|
||||
pp::Token::Begin(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_end(&mut self) -> bool {
|
||||
match self.s.last_token() {
|
||||
pp::Token::End => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// is this the beginning of a line?
|
||||
pub fn is_bol(&mut self) -> bool {
|
||||
self.s.last_token().is_eof() || self.s.last_token().is_hardbreak_tok()
|
||||
}
|
||||
|
||||
pub fn in_cbox(&self) -> bool {
|
||||
match self.boxes.last() {
|
||||
Some(&last_box) => last_box == pp::Breaks::Consistent,
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hardbreak_if_not_bol(&mut self) -> io::Result<()> {
|
||||
if !self.is_bol() {
|
||||
try!(hardbreak(&mut self.s))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn space_if_not_bol(&mut self) -> io::Result<()> {
|
||||
if !self.is_bol() { try!(space(&mut self.s)); }
|
||||
Ok(())
|
||||
@ -457,18 +405,6 @@ impl<'a> State<'a> {
|
||||
word(&mut self.s, "*/")
|
||||
}
|
||||
|
||||
pub fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> io::Result<()> where
|
||||
F: FnMut(&mut State, &T) -> io::Result<()>,
|
||||
{
|
||||
try!(self.rbox(0, b));
|
||||
let mut first = true;
|
||||
for elt in elts {
|
||||
if first { first = false; } else { try!(self.word_space(",")); }
|
||||
try!(op(self, elt));
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
|
||||
|
||||
pub fn commasep_cmnt<T, F, G>(&mut self,
|
||||
b: Breaks,
|
||||
@ -501,7 +437,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
pub fn print_mod(&mut self, _mod: &hir::Mod,
|
||||
attrs: &[hir::Attribute]) -> io::Result<()> {
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
try!(self.print_inner_attributes(attrs));
|
||||
for item in &_mod.items {
|
||||
try!(self.print_item(&**item));
|
||||
@ -510,7 +446,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
pub fn print_foreign_mod(&mut self, nmod: &hir::ForeignMod,
|
||||
attrs: &[hir::Attribute]) -> io::Result<()> {
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
try!(self.print_inner_attributes(attrs));
|
||||
for item in &nmod.items {
|
||||
try!(self.print_foreign_item(&**item));
|
||||
@ -694,7 +630,7 @@ impl<'a> State<'a> {
|
||||
if let Some(p) = *optional_path {
|
||||
let val = p.as_str();
|
||||
if val.contains("-") {
|
||||
try!(self.print_string(&val, hir::CookedStr));
|
||||
try!(self.print_string(&val, ast::CookedStr));
|
||||
} else {
|
||||
try!(self.print_name(p));
|
||||
}
|
||||
@ -1105,58 +1041,6 @@ impl<'a> State<'a> {
|
||||
self.ann.post(self, NodeSubItem(ii.id))
|
||||
}
|
||||
|
||||
pub fn print_outer_attributes(&mut self,
|
||||
attrs: &[hir::Attribute]) -> io::Result<()> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
hir::AttrOuter => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
_ => {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_inner_attributes(&mut self,
|
||||
attrs: &[hir::Attribute]) -> io::Result<()> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
hir::AttrInner => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
_ => {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_attribute(&mut self, attr: &hir::Attribute) -> io::Result<()> {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(attr.span.lo));
|
||||
if attr.node.is_sugared_doc {
|
||||
word(&mut self.s, &attr.value_str().unwrap())
|
||||
} else {
|
||||
match attr.node.style {
|
||||
hir::AttrInner => try!(word(&mut self.s, "#![")),
|
||||
hir::AttrOuter => try!(word(&mut self.s, "#[")),
|
||||
}
|
||||
try!(self.print_meta_item(&*attr.meta()));
|
||||
word(&mut self.s, "]")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn print_stmt(&mut self, st: &hir::Stmt) -> io::Result<()> {
|
||||
try!(self.maybe_print_comment(st.span.lo));
|
||||
match st.node {
|
||||
@ -1194,14 +1078,14 @@ impl<'a> State<'a> {
|
||||
|
||||
pub fn print_block_with_attrs(&mut self,
|
||||
blk: &hir::Block,
|
||||
attrs: &[hir::Attribute]) -> io::Result<()> {
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
self.print_block_maybe_unclosed(blk, indent_unit, attrs, true)
|
||||
}
|
||||
|
||||
pub fn print_block_maybe_unclosed(&mut self,
|
||||
blk: &hir::Block,
|
||||
indented: usize,
|
||||
attrs: &[hir::Attribute],
|
||||
attrs: &[ast::Attribute],
|
||||
close_box: bool) -> io::Result<()> {
|
||||
match blk.rules {
|
||||
hir::UnsafeBlock(..) | hir::PushUnsafeBlock(..) => try!(self.word_space("unsafe")),
|
||||
@ -1620,9 +1504,9 @@ impl<'a> State<'a> {
|
||||
match co.slice_shift_char() {
|
||||
Some(('=', operand)) if is_rw => {
|
||||
try!(s.print_string(&format!("+{}", operand),
|
||||
hir::CookedStr))
|
||||
ast::CookedStr))
|
||||
}
|
||||
_ => try!(s.print_string(&co, hir::CookedStr))
|
||||
_ => try!(s.print_string(&co, ast::CookedStr))
|
||||
}
|
||||
try!(s.popen());
|
||||
try!(s.print_expr(&**o));
|
||||
@ -1634,7 +1518,7 @@ impl<'a> State<'a> {
|
||||
|
||||
try!(self.commasep(Inconsistent, &a.inputs,
|
||||
|s, &(ref co, ref o)| {
|
||||
try!(s.print_string(&co, hir::CookedStr));
|
||||
try!(s.print_string(&co, ast::CookedStr));
|
||||
try!(s.popen());
|
||||
try!(s.print_expr(&**o));
|
||||
try!(s.pclose());
|
||||
@ -1645,7 +1529,7 @@ impl<'a> State<'a> {
|
||||
|
||||
try!(self.commasep(Inconsistent, &a.clobbers,
|
||||
|s, co| {
|
||||
try!(s.print_string(&co, hir::CookedStr));
|
||||
try!(s.print_string(&co, ast::CookedStr));
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
@ -1665,7 +1549,7 @@ impl<'a> State<'a> {
|
||||
try!(self.word_space(":"));
|
||||
try!(self.commasep(Inconsistent, &*options,
|
||||
|s, &co| {
|
||||
try!(s.print_string(co, hir::CookedStr));
|
||||
try!(s.print_string(co, ast::CookedStr));
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
@ -2294,29 +2178,6 @@ impl<'a> State<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_meta_item(&mut self, item: &hir::MetaItem) -> io::Result<()> {
|
||||
try!(self.ibox(indent_unit));
|
||||
match item.node {
|
||||
hir::MetaWord(ref name) => {
|
||||
try!(word(&mut self.s, &name));
|
||||
}
|
||||
hir::MetaNameValue(ref name, ref value) => {
|
||||
try!(self.word_space(&name[..]));
|
||||
try!(self.word_space("="));
|
||||
try!(self.print_literal(value));
|
||||
}
|
||||
hir::MetaList(ref name, ref items) => {
|
||||
try!(word(&mut self.s, &name));
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Consistent,
|
||||
&items[..],
|
||||
|s, i| s.print_meta_item(&**i)));
|
||||
try!(self.pclose());
|
||||
}
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
|
||||
pub fn print_view_path(&mut self, vp: &hir::ViewPath) -> io::Result<()> {
|
||||
match vp.node {
|
||||
hir::ViewPathSimple(ident, ref path) => {
|
||||
@ -2494,181 +2355,6 @@ impl<'a> State<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_literal(&mut self, lit: &hir::Lit) -> io::Result<()> {
|
||||
try!(self.maybe_print_comment(lit.span.lo));
|
||||
match self.next_lit(lit.span.lo) {
|
||||
Some(ref ltrl) => {
|
||||
return word(&mut self.s, &(*ltrl).lit);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
match lit.node {
|
||||
hir::LitStr(ref st, style) => self.print_string(&st, style),
|
||||
hir::LitByte(byte) => {
|
||||
let mut res = String::from("b'");
|
||||
res.extend(ascii::escape_default(byte).map(|c| c as char));
|
||||
res.push('\'');
|
||||
word(&mut self.s, &res[..])
|
||||
}
|
||||
hir::LitChar(ch) => {
|
||||
let mut res = String::from("'");
|
||||
res.extend(ch.escape_default());
|
||||
res.push('\'');
|
||||
word(&mut self.s, &res[..])
|
||||
}
|
||||
hir::LitInt(i, t) => {
|
||||
match t {
|
||||
hir::SignedIntLit(st, hir::Plus) => {
|
||||
word(&mut self.s,
|
||||
&::util::int_ty_to_string(st, Some(i as i64)))
|
||||
}
|
||||
hir::SignedIntLit(st, hir::Minus) => {
|
||||
let istr = ::util::int_ty_to_string(st, Some(-(i as i64)));
|
||||
word(&mut self.s,
|
||||
&format!("-{}", istr))
|
||||
}
|
||||
hir::UnsignedIntLit(ut) => {
|
||||
word(&mut self.s, &::util::uint_ty_to_string(ut, Some(i)))
|
||||
}
|
||||
hir::UnsuffixedIntLit(hir::Plus) => {
|
||||
word(&mut self.s, &format!("{}", i))
|
||||
}
|
||||
hir::UnsuffixedIntLit(hir::Minus) => {
|
||||
word(&mut self.s, &format!("-{}", i))
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::LitFloat(ref f, t) => {
|
||||
word(&mut self.s,
|
||||
&format!(
|
||||
"{}{}",
|
||||
&f,
|
||||
&::util::float_ty_to_string(t)))
|
||||
}
|
||||
hir::LitFloatUnsuffixed(ref f) => word(&mut self.s, &f[..]),
|
||||
hir::LitBool(val) => {
|
||||
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
|
||||
}
|
||||
hir::LitByteStr(ref v) => {
|
||||
let mut escaped: String = String::new();
|
||||
for &ch in v.iter() {
|
||||
escaped.extend(ascii::escape_default(ch)
|
||||
.map(|c| c as char));
|
||||
}
|
||||
word(&mut self.s, &format!("b\"{}\"", escaped))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_lit(&mut self, pos: BytePos) -> Option<comments::Literal> {
|
||||
match self.literals {
|
||||
Some(ref lits) => {
|
||||
while self.cur_cmnt_and_lit.cur_lit < lits.len() {
|
||||
let ltrl = (*lits)[self.cur_cmnt_and_lit.cur_lit].clone();
|
||||
if ltrl.pos > pos { return None; }
|
||||
self.cur_cmnt_and_lit.cur_lit += 1;
|
||||
if ltrl.pos == pos { return Some(ltrl); }
|
||||
}
|
||||
None
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_print_comment(&mut self, pos: BytePos) -> io::Result<()> {
|
||||
loop {
|
||||
match self.next_comment() {
|
||||
Some(ref cmnt) => {
|
||||
if (*cmnt).pos < pos {
|
||||
try!(self.print_comment(cmnt));
|
||||
self.cur_cmnt_and_lit.cur_cmnt += 1;
|
||||
} else { break; }
|
||||
}
|
||||
_ => break
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_comment(&mut self,
|
||||
cmnt: &comments::Comment) -> io::Result<()> {
|
||||
match cmnt.style {
|
||||
comments::Mixed => {
|
||||
assert_eq!(cmnt.lines.len(), 1);
|
||||
try!(zerobreak(&mut self.s));
|
||||
try!(word(&mut self.s, &cmnt.lines[0]));
|
||||
zerobreak(&mut self.s)
|
||||
}
|
||||
comments::Isolated => {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
for line in &cmnt.lines {
|
||||
// Don't print empty lines because they will end up as trailing
|
||||
// whitespace
|
||||
if !line.is_empty() {
|
||||
try!(word(&mut self.s, &line[..]));
|
||||
}
|
||||
try!(hardbreak(&mut self.s));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
comments::Trailing => {
|
||||
try!(word(&mut self.s, " "));
|
||||
if cmnt.lines.len() == 1 {
|
||||
try!(word(&mut self.s, &cmnt.lines[0]));
|
||||
hardbreak(&mut self.s)
|
||||
} else {
|
||||
try!(self.ibox(0));
|
||||
for line in &cmnt.lines {
|
||||
if !line.is_empty() {
|
||||
try!(word(&mut self.s, &line[..]));
|
||||
}
|
||||
try!(hardbreak(&mut self.s));
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
}
|
||||
comments::BlankLine => {
|
||||
// We need to do at least one, possibly two hardbreaks.
|
||||
let is_semi = match self.s.last_token() {
|
||||
pp::Token::String(s, _) => ";" == s,
|
||||
_ => false
|
||||
};
|
||||
if is_semi || self.is_begin() || self.is_end() {
|
||||
try!(hardbreak(&mut self.s));
|
||||
}
|
||||
hardbreak(&mut self.s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_string(&mut self, st: &str,
|
||||
style: hir::StrStyle) -> io::Result<()> {
|
||||
let st = match style {
|
||||
hir::CookedStr => {
|
||||
(format!("\"{}\"", st.escape_default()))
|
||||
}
|
||||
hir::RawStr(n) => {
|
||||
(format!("r{delim}\"{string}\"{delim}",
|
||||
delim=repeat("#", n),
|
||||
string=st))
|
||||
}
|
||||
};
|
||||
word(&mut self.s, &st[..])
|
||||
}
|
||||
|
||||
pub fn next_comment(&mut self) -> Option<comments::Comment> {
|
||||
match self.comments {
|
||||
Some(ref cmnts) => {
|
||||
if self.cur_cmnt_and_lit.cur_cmnt < cmnts.len() {
|
||||
Some(cmnts[self.cur_cmnt_and_lit.cur_cmnt].clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_opt_abi_and_extern_if_nondefault(&mut self,
|
||||
opt_abi: Option<abi::Abi>)
|
||||
-> io::Result<()> {
|
||||
@ -2722,8 +2408,6 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn repeat(s: &str, n: usize) -> String { iter::repeat(s).take(n).collect() }
|
||||
|
||||
// Dup'ed from parse::classify, but adapted for the HIR.
|
||||
/// Does this expression require a semicolon to be treated
|
||||
/// as a statement? The negation of this: 'can this expression
|
||||
|
@ -338,64 +338,10 @@ pub fn compute_id_range_for_fn_body(fk: FnKind,
|
||||
id_visitor.operation.result
|
||||
}
|
||||
|
||||
/// Returns true if this literal is a string and false otherwise.
|
||||
pub fn lit_is_str(lit: &Lit) -> bool {
|
||||
match lit.node {
|
||||
LitStr(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_path(e: P<Expr>) -> bool {
|
||||
match e.node { ExprPath(..) => true, _ => false }
|
||||
}
|
||||
|
||||
/// Get a string representation of a signed int type, with its value.
|
||||
/// We want to avoid "45int" and "-3int" in favor of "45" and "-3"
|
||||
pub fn int_ty_to_string(t: IntTy, val: Option<i64>) -> String {
|
||||
let s = match t {
|
||||
TyIs => "isize",
|
||||
TyI8 => "i8",
|
||||
TyI16 => "i16",
|
||||
TyI32 => "i32",
|
||||
TyI64 => "i64"
|
||||
};
|
||||
|
||||
match val {
|
||||
// cast to a u64 so we can correctly print INT64_MIN. All integral types
|
||||
// are parsed as u64, so we wouldn't want to print an extra negative
|
||||
// sign.
|
||||
Some(n) => format!("{}{}", n as u64, s),
|
||||
None => s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Get a string representation of an unsigned int type, with its value.
|
||||
/// We want to avoid "42u" in favor of "42us". "42uint" is right out.
|
||||
pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String {
|
||||
let s = match t {
|
||||
TyUs => "usize",
|
||||
TyU8 => "u8",
|
||||
TyU16 => "u16",
|
||||
TyU32 => "u32",
|
||||
TyU64 => "u64"
|
||||
};
|
||||
|
||||
match val {
|
||||
Some(n) => format!("{}{}", n, s),
|
||||
None => s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn float_ty_to_string(t: FloatTy) -> String {
|
||||
match t {
|
||||
TyF32 => "f32".to_string(),
|
||||
TyF64 => "f64".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn empty_generics() -> Generics {
|
||||
Generics {
|
||||
lifetimes: Vec::new(),
|
||||
|
@ -24,7 +24,7 @@
|
||||
//! those that are created by the expansion of a macro.
|
||||
|
||||
use syntax::abi::Abi;
|
||||
use syntax::ast::{Ident, NodeId, CRATE_NODE_ID, Name};
|
||||
use syntax::ast::{Ident, NodeId, CRATE_NODE_ID, Name, Attribute};
|
||||
use hir::*;
|
||||
use hir;
|
||||
use syntax::codemap::Span;
|
||||
|
@ -46,18 +46,14 @@ use std::{cmp, slice};
|
||||
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
|
||||
|
||||
use syntax::{abi, ast};
|
||||
use syntax::attr as syntax_attr;
|
||||
use syntax::attr::{self, AttrMetaMethods};
|
||||
use syntax::codemap::{self, Span};
|
||||
use syntax::feature_gate::{KNOWN_ATTRIBUTES, AttributeType};
|
||||
use rustc_front::hir::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
|
||||
use syntax::ast::{TyIs, TyUs, TyI8, TyU8, TyI16, TyU16, TyI32, TyU32, TyI64, TyU64};
|
||||
use syntax::ptr::P;
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
use rustc_front::attr::{self, AttrMetaMethods};
|
||||
use rustc_front::visit::{self, FnKind, Visitor};
|
||||
use rustc_front::lowering::unlower_attribute;
|
||||
|
||||
use rustc_front::util::is_shift_binop;
|
||||
|
||||
// hardwired lints from librustc
|
||||
@ -80,7 +76,7 @@ impl LintPass for WhileTrue {
|
||||
fn check_expr(&mut self, cx: &Context, e: &hir::Expr) {
|
||||
if let hir::ExprWhile(ref cond, _, _) = e.node {
|
||||
if let hir::ExprLit(ref lit) = cond.node {
|
||||
if let hir::LitBool(true) = lit.node {
|
||||
if let ast::LitBool(true) = lit.node {
|
||||
cx.span_lint(WHILE_TRUE, e.span,
|
||||
"denote infinite loops with loop { ... }");
|
||||
}
|
||||
@ -132,10 +128,10 @@ impl LintPass for TypeLimits {
|
||||
match expr.node {
|
||||
hir::ExprLit(ref lit) => {
|
||||
match lit.node {
|
||||
hir::LitInt(_, hir::UnsignedIntLit(_)) => {
|
||||
ast::LitInt(_, ast::UnsignedIntLit(_)) => {
|
||||
check_unsigned_negation_feature(cx, e.span);
|
||||
},
|
||||
hir::LitInt(_, hir::UnsuffixedIntLit(_)) => {
|
||||
ast::LitInt(_, ast::UnsuffixedIntLit(_)) => {
|
||||
if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty {
|
||||
check_unsigned_negation_feature(cx, e.span);
|
||||
}
|
||||
@ -176,7 +172,7 @@ impl LintPass for TypeLimits {
|
||||
|
||||
if let Some(bits) = opt_ty_bits {
|
||||
let exceeding = if let hir::ExprLit(ref lit) = r.node {
|
||||
if let hir::LitInt(shift, _) = lit.node { shift >= bits }
|
||||
if let ast::LitInt(shift, _) = lit.node { shift >= bits }
|
||||
else { false }
|
||||
} else {
|
||||
match eval_const_expr_partial(cx.tcx, &r, ExprTypeChecked) {
|
||||
@ -196,9 +192,9 @@ impl LintPass for TypeLimits {
|
||||
match cx.tcx.node_id_to_type(e.id).sty {
|
||||
ty::TyInt(t) => {
|
||||
match lit.node {
|
||||
hir::LitInt(v, hir::SignedIntLit(_, hir::Plus)) |
|
||||
hir::LitInt(v, hir::UnsuffixedIntLit(hir::Plus)) => {
|
||||
let int_type = if let hir::TyIs = t {
|
||||
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
|
||||
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => {
|
||||
let int_type = if let ast::TyIs = t {
|
||||
cx.sess().target.int_type
|
||||
} else {
|
||||
t
|
||||
@ -219,15 +215,15 @@ impl LintPass for TypeLimits {
|
||||
};
|
||||
},
|
||||
ty::TyUint(t) => {
|
||||
let uint_type = if let hir::TyUs = t {
|
||||
let uint_type = if let ast::TyUs = t {
|
||||
cx.sess().target.uint_type
|
||||
} else {
|
||||
t
|
||||
};
|
||||
let (min, max) = uint_ty_range(uint_type);
|
||||
let lit_val: u64 = match lit.node {
|
||||
hir::LitByte(_v) => return, // _v is u8, within range by definition
|
||||
hir::LitInt(v, _) => v,
|
||||
ast::LitByte(_v) => return, // _v is u8, within range by definition
|
||||
ast::LitInt(v, _) => v,
|
||||
_ => panic!()
|
||||
};
|
||||
if lit_val < min || lit_val > max {
|
||||
@ -238,8 +234,8 @@ impl LintPass for TypeLimits {
|
||||
ty::TyFloat(t) => {
|
||||
let (min, max) = float_ty_range(t);
|
||||
let lit_val: f64 = match lit.node {
|
||||
hir::LitFloat(ref v, _) |
|
||||
hir::LitFloatUnsuffixed(ref v) => {
|
||||
ast::LitFloat(ref v, _) |
|
||||
ast::LitFloatUnsuffixed(ref v) => {
|
||||
match v.parse() {
|
||||
Ok(f) => f,
|
||||
Err(_) => return
|
||||
@ -282,50 +278,50 @@ impl LintPass for TypeLimits {
|
||||
|
||||
// for isize & usize, be conservative with the warnings, so that the
|
||||
// warnings are consistent between 32- and 64-bit platforms
|
||||
fn int_ty_range(int_ty: hir::IntTy) -> (i64, i64) {
|
||||
fn int_ty_range(int_ty: ast::IntTy) -> (i64, i64) {
|
||||
match int_ty {
|
||||
hir::TyIs => (i64::MIN, i64::MAX),
|
||||
hir::TyI8 => (i8::MIN as i64, i8::MAX as i64),
|
||||
hir::TyI16 => (i16::MIN as i64, i16::MAX as i64),
|
||||
hir::TyI32 => (i32::MIN as i64, i32::MAX as i64),
|
||||
hir::TyI64 => (i64::MIN, i64::MAX)
|
||||
ast::TyIs => (i64::MIN, i64::MAX),
|
||||
ast::TyI8 => (i8::MIN as i64, i8::MAX as i64),
|
||||
ast::TyI16 => (i16::MIN as i64, i16::MAX as i64),
|
||||
ast::TyI32 => (i32::MIN as i64, i32::MAX as i64),
|
||||
ast::TyI64 => (i64::MIN, i64::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
fn uint_ty_range(uint_ty: hir::UintTy) -> (u64, u64) {
|
||||
fn uint_ty_range(uint_ty: ast::UintTy) -> (u64, u64) {
|
||||
match uint_ty {
|
||||
hir::TyUs => (u64::MIN, u64::MAX),
|
||||
hir::TyU8 => (u8::MIN as u64, u8::MAX as u64),
|
||||
hir::TyU16 => (u16::MIN as u64, u16::MAX as u64),
|
||||
hir::TyU32 => (u32::MIN as u64, u32::MAX as u64),
|
||||
hir::TyU64 => (u64::MIN, u64::MAX)
|
||||
ast::TyUs => (u64::MIN, u64::MAX),
|
||||
ast::TyU8 => (u8::MIN as u64, u8::MAX as u64),
|
||||
ast::TyU16 => (u16::MIN as u64, u16::MAX as u64),
|
||||
ast::TyU32 => (u32::MIN as u64, u32::MAX as u64),
|
||||
ast::TyU64 => (u64::MIN, u64::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
fn float_ty_range(float_ty: hir::FloatTy) -> (f64, f64) {
|
||||
fn float_ty_range(float_ty: ast::FloatTy) -> (f64, f64) {
|
||||
match float_ty {
|
||||
hir::TyF32 => (f32::MIN as f64, f32::MAX as f64),
|
||||
hir::TyF64 => (f64::MIN, f64::MAX)
|
||||
ast::TyF32 => (f32::MIN as f64, f32::MAX as f64),
|
||||
ast::TyF64 => (f64::MIN, f64::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
fn int_ty_bits(int_ty: hir::IntTy, target_int_ty: hir::IntTy) -> u64 {
|
||||
fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
|
||||
match int_ty {
|
||||
hir::TyIs => int_ty_bits(target_int_ty, target_int_ty),
|
||||
hir::TyI8 => i8::BITS as u64,
|
||||
hir::TyI16 => i16::BITS as u64,
|
||||
hir::TyI32 => i32::BITS as u64,
|
||||
hir::TyI64 => i64::BITS as u64
|
||||
ast::TyIs => int_ty_bits(target_int_ty, target_int_ty),
|
||||
ast::TyI8 => i8::BITS as u64,
|
||||
ast::TyI16 => i16::BITS as u64,
|
||||
ast::TyI32 => i32::BITS as u64,
|
||||
ast::TyI64 => i64::BITS as u64
|
||||
}
|
||||
}
|
||||
|
||||
fn uint_ty_bits(uint_ty: hir::UintTy, target_uint_ty: hir::UintTy) -> u64 {
|
||||
fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
|
||||
match uint_ty {
|
||||
hir::TyUs => uint_ty_bits(target_uint_ty, target_uint_ty),
|
||||
hir::TyU8 => u8::BITS as u64,
|
||||
hir::TyU16 => u16::BITS as u64,
|
||||
hir::TyU32 => u32::BITS as u64,
|
||||
hir::TyU64 => u64::BITS as u64
|
||||
ast::TyUs => uint_ty_bits(target_uint_ty, target_uint_ty),
|
||||
ast::TyU8 => u8::BITS as u64,
|
||||
ast::TyU16 => u16::BITS as u64,
|
||||
ast::TyU32 => u32::BITS as u64,
|
||||
ast::TyU64 => u64::BITS as u64
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,10 +344,10 @@ impl LintPass for TypeLimits {
|
||||
let (min, max) = int_ty_range(int_ty);
|
||||
let lit_val: i64 = match lit.node {
|
||||
hir::ExprLit(ref li) => match li.node {
|
||||
hir::LitInt(v, hir::SignedIntLit(_, hir::Plus)) |
|
||||
hir::LitInt(v, hir::UnsuffixedIntLit(hir::Plus)) => v as i64,
|
||||
hir::LitInt(v, hir::SignedIntLit(_, hir::Minus)) |
|
||||
hir::LitInt(v, hir::UnsuffixedIntLit(hir::Minus)) => -(v as i64),
|
||||
ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) |
|
||||
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => v as i64,
|
||||
ast::LitInt(v, ast::SignedIntLit(_, ast::Minus)) |
|
||||
ast::LitInt(v, ast::UnsuffixedIntLit(ast::Minus)) => -(v as i64),
|
||||
_ => return true
|
||||
},
|
||||
_ => panic!()
|
||||
@ -362,7 +358,7 @@ impl LintPass for TypeLimits {
|
||||
let (min, max): (u64, u64) = uint_ty_range(uint_ty);
|
||||
let lit_val: u64 = match lit.node {
|
||||
hir::ExprLit(ref li) => match li.node {
|
||||
hir::LitInt(v, _) => v,
|
||||
ast::LitInt(v, _) => v,
|
||||
_ => return true
|
||||
},
|
||||
_ => panic!()
|
||||
@ -557,11 +553,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
FfiSafe
|
||||
}
|
||||
|
||||
ty::TyInt(hir::TyIs) => {
|
||||
ty::TyInt(ast::TyIs) => {
|
||||
FfiUnsafe("found Rust type `isize` in foreign module, while \
|
||||
`libc::c_int` or `libc::c_long` should be used")
|
||||
}
|
||||
ty::TyUint(hir::TyUs) => {
|
||||
ty::TyUint(ast::TyUs) => {
|
||||
FfiUnsafe("found Rust type `usize` in foreign module, while \
|
||||
`libc::c_uint` or `libc::c_ulong` should be used")
|
||||
}
|
||||
@ -892,7 +888,7 @@ impl LintPass for UnusedAttributes {
|
||||
lint_array!(UNUSED_ATTRIBUTES)
|
||||
}
|
||||
|
||||
fn check_attribute(&mut self, cx: &Context, attr: &hir::Attribute) {
|
||||
fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) {
|
||||
// Note that check_name() marks the attribute as used if it matches.
|
||||
for &(ref name, ty, _) in KNOWN_ATTRIBUTES {
|
||||
match ty {
|
||||
@ -910,7 +906,7 @@ impl LintPass for UnusedAttributes {
|
||||
}
|
||||
}
|
||||
|
||||
if !syntax_attr::is_used(&unlower_attribute(attr)) {
|
||||
if !attr::is_used(attr) {
|
||||
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
|
||||
// Is it a builtin attribute that must be used at the crate level?
|
||||
let known_crate = KNOWN_ATTRIBUTES.iter().find(|&&(name, ty, _)| {
|
||||
@ -927,9 +923,9 @@ impl LintPass for UnusedAttributes {
|
||||
}).is_some();
|
||||
if known_crate || plugin_crate {
|
||||
let msg = match attr.node.style {
|
||||
hir::AttrOuter => "crate-level attribute should be an inner \
|
||||
ast::AttrOuter => "crate-level attribute should be an inner \
|
||||
attribute: add an exclamation mark: #![foo]",
|
||||
hir::AttrInner => "crate-level attribute should be in the \
|
||||
ast::AttrInner => "crate-level attribute should be in the \
|
||||
root module",
|
||||
};
|
||||
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, msg);
|
||||
@ -1019,7 +1015,7 @@ impl LintPass for UnusedResults {
|
||||
cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
|
||||
}
|
||||
|
||||
fn check_must_use(cx: &Context, attrs: &[hir::Attribute], sp: Span) -> bool {
|
||||
fn check_must_use(cx: &Context, attrs: &[ast::Attribute], sp: Span) -> bool {
|
||||
for attr in attrs {
|
||||
if attr.check_name("must_use") {
|
||||
let mut msg = "unused result which must be used".to_string();
|
||||
@ -1780,7 +1776,7 @@ impl MissingDoc {
|
||||
fn check_missing_docs_attrs(&self,
|
||||
cx: &Context,
|
||||
id: Option<ast::NodeId>,
|
||||
attrs: &[hir::Attribute],
|
||||
attrs: &[ast::Attribute],
|
||||
sp: Span,
|
||||
desc: &'static str) {
|
||||
// If we're building a test harness, then warning about
|
||||
@ -1805,7 +1801,7 @@ impl MissingDoc {
|
||||
|
||||
let has_doc = attrs.iter().any(|a| {
|
||||
match a.node.value.node {
|
||||
hir::MetaNameValue(ref name, _) if *name == "doc" => true,
|
||||
ast::MetaNameValue(ref name, _) if *name == "doc" => true,
|
||||
_ => false
|
||||
}
|
||||
});
|
||||
@ -1821,7 +1817,7 @@ impl LintPass for MissingDoc {
|
||||
lint_array!(MISSING_DOCS)
|
||||
}
|
||||
|
||||
fn enter_lint_attrs(&mut self, _: &Context, attrs: &[hir::Attribute]) {
|
||||
fn enter_lint_attrs(&mut self, _: &Context, attrs: &[ast::Attribute]) {
|
||||
let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| {
|
||||
attr.check_name("doc") && match attr.meta_item_list() {
|
||||
None => false,
|
||||
@ -1831,7 +1827,7 @@ impl LintPass for MissingDoc {
|
||||
self.doc_hidden_stack.push(doc_hidden);
|
||||
}
|
||||
|
||||
fn exit_lint_attrs(&mut self, _: &Context, _: &[hir::Attribute]) {
|
||||
fn exit_lint_attrs(&mut self, _: &Context, _: &[ast::Attribute]) {
|
||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
@ -2573,7 +2569,7 @@ impl LintPass for UnstableFeatures {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(UNSTABLE_FEATURES)
|
||||
}
|
||||
fn check_attribute(&mut self, ctx: &Context, attr: &hir::Attribute) {
|
||||
fn check_attribute(&mut self, ctx: &Context, attr: &ast::Attribute) {
|
||||
if attr::contains_name(&[attr.node.value.clone()], "feature") {
|
||||
if let Some(items) = attr.node.value.meta_item_list() {
|
||||
for item in items {
|
||||
|
@ -32,9 +32,9 @@ use self::rustc::middle::region::CodeExtentData;
|
||||
use self::rustc::middle::ty::{self, Ty};
|
||||
use self::rustc::util::common::ErrorReported;
|
||||
use self::rustc_front::hir;
|
||||
use self::rustc_front::attr::{AttrMetaMethods};
|
||||
use self::rustc_front::visit;
|
||||
use self::syntax::ast;
|
||||
use self::syntax::attr::AttrMetaMethods;
|
||||
use self::syntax::codemap::Span;
|
||||
|
||||
pub fn dump_crate(tcx: &ty::ctxt) {
|
||||
@ -50,7 +50,7 @@ struct OuterDump<'a,'tcx:'a> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> OuterDump<'a, 'tcx> {
|
||||
fn visit_mir<OP>(&self, attributes: &'tcx [hir::Attribute], mut walk_op: OP)
|
||||
fn visit_mir<OP>(&self, attributes: &'tcx [ast::Attribute], mut walk_op: OP)
|
||||
where OP: FnMut(&mut InnerDump<'a,'tcx>)
|
||||
{
|
||||
let mut built_mir = false;
|
||||
@ -94,7 +94,7 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for OuterDump<'a, 'tcx> {
|
||||
|
||||
struct InnerDump<'a,'tcx:'a> {
|
||||
tcx: &'a ty::ctxt<'tcx>,
|
||||
attr: Option<&'a hir::Attribute>,
|
||||
attr: Option<&'a ast::Attribute>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> visit::Visitor<'tcx> for InnerDump<'a,'tcx> {
|
||||
|
@ -23,6 +23,7 @@ use tcx::rustc::middle::pat_util;
|
||||
use tcx::rustc::middle::ty::{self, Ty};
|
||||
use tcx::rustc_front::hir;
|
||||
use tcx::rustc_front::util as hir_util;
|
||||
use tcx::syntax::ast;
|
||||
use tcx::syntax::codemap::Span;
|
||||
use tcx::syntax::parse::token;
|
||||
use tcx::syntax::ptr::P;
|
||||
@ -462,56 +463,56 @@ fn to_borrow_kind(m: hir::Mutability) -> BorrowKind {
|
||||
fn convert_literal<'a,'tcx:'a>(cx: &mut Cx<'a,'tcx>,
|
||||
expr_span: Span,
|
||||
expr_ty: Ty<'tcx>,
|
||||
literal: &hir::Lit)
|
||||
literal: &ast::Lit)
|
||||
-> Literal<Cx<'a,'tcx>>
|
||||
{
|
||||
use repr::IntegralBits::*;
|
||||
match (&literal.node, &expr_ty.sty) {
|
||||
(&hir::LitStr(ref text, _), _) =>
|
||||
(&ast::LitStr(ref text, _), _) =>
|
||||
Literal::String { value: text.clone() },
|
||||
(&hir::LitByteStr(ref bytes), _) =>
|
||||
(&ast::LitByteStr(ref bytes), _) =>
|
||||
Literal::Bytes { value: bytes.clone() },
|
||||
(&hir::LitByte(c), _) =>
|
||||
(&ast::LitByte(c), _) =>
|
||||
Literal::Uint { bits: B8, value: c as u64 },
|
||||
(&hir::LitChar(c), _) =>
|
||||
(&ast::LitChar(c), _) =>
|
||||
Literal::Char { c: c },
|
||||
(&hir::LitInt(v, _), &ty::TyUint(hir::TyU8)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyUint(ast::TyU8)) =>
|
||||
Literal::Uint { bits: B8, value: v },
|
||||
(&hir::LitInt(v, _), &ty::TyUint(hir::TyU16)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyUint(ast::TyU16)) =>
|
||||
Literal::Uint { bits: B16, value: v },
|
||||
(&hir::LitInt(v, _), &ty::TyUint(hir::TyU32)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyUint(ast::TyU32)) =>
|
||||
Literal::Uint { bits: B32, value: v },
|
||||
(&hir::LitInt(v, _), &ty::TyUint(hir::TyU64)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyUint(ast::TyU64)) =>
|
||||
Literal::Uint { bits: B64, value: v },
|
||||
(&hir::LitInt(v, _), &ty::TyUint(hir::TyUs)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyUint(ast::TyUs)) =>
|
||||
Literal::Uint { bits: BSize, value: v },
|
||||
(&hir::LitInt(v, hir::SignedIntLit(_, hir::Sign::Minus)), &ty::TyInt(hir::TyI8)) =>
|
||||
(&ast::LitInt(v, ast::SignedIntLit(_, ast::Sign::Minus)), &ty::TyInt(ast::TyI8)) =>
|
||||
Literal::Int { bits: B8, value: -(v as i64) },
|
||||
(&hir::LitInt(v, hir::SignedIntLit(_, hir::Sign::Minus)), &ty::TyInt(hir::TyI16)) =>
|
||||
(&ast::LitInt(v, ast::SignedIntLit(_, ast::Sign::Minus)), &ty::TyInt(ast::TyI16)) =>
|
||||
Literal::Int { bits: B16, value: -(v as i64) },
|
||||
(&hir::LitInt(v, hir::SignedIntLit(_, hir::Sign::Minus)), &ty::TyInt(hir::TyI32)) =>
|
||||
(&ast::LitInt(v, ast::SignedIntLit(_, ast::Sign::Minus)), &ty::TyInt(ast::TyI32)) =>
|
||||
Literal::Int { bits: B32, value: -(v as i64) },
|
||||
(&hir::LitInt(v, hir::SignedIntLit(_, hir::Sign::Minus)), &ty::TyInt(hir::TyI64)) =>
|
||||
(&ast::LitInt(v, ast::SignedIntLit(_, ast::Sign::Minus)), &ty::TyInt(ast::TyI64)) =>
|
||||
Literal::Int { bits: B64, value: -(v as i64) },
|
||||
(&hir::LitInt(v, hir::SignedIntLit(_, hir::Sign::Minus)), &ty::TyInt(hir::TyIs)) =>
|
||||
(&ast::LitInt(v, ast::SignedIntLit(_, ast::Sign::Minus)), &ty::TyInt(ast::TyIs)) =>
|
||||
Literal::Int { bits: BSize, value: -(v as i64) },
|
||||
(&hir::LitInt(v, _), &ty::TyInt(hir::TyI8)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyInt(ast::TyI8)) =>
|
||||
Literal::Int { bits: B8, value: v as i64 },
|
||||
(&hir::LitInt(v, _), &ty::TyInt(hir::TyI16)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyInt(ast::TyI16)) =>
|
||||
Literal::Int { bits: B16, value: v as i64 },
|
||||
(&hir::LitInt(v, _), &ty::TyInt(hir::TyI32)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyInt(ast::TyI32)) =>
|
||||
Literal::Int { bits: B32, value: v as i64 },
|
||||
(&hir::LitInt(v, _), &ty::TyInt(hir::TyI64)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyInt(ast::TyI64)) =>
|
||||
Literal::Int { bits: B64, value: v as i64 },
|
||||
(&hir::LitInt(v, _), &ty::TyInt(hir::TyIs)) =>
|
||||
(&ast::LitInt(v, _), &ty::TyInt(ast::TyIs)) =>
|
||||
Literal::Int { bits: BSize, value: v as i64 },
|
||||
(&hir::LitFloat(ref v, _), &ty::TyFloat(hir::TyF32)) |
|
||||
(&hir::LitFloatUnsuffixed(ref v), &ty::TyFloat(hir::TyF32)) =>
|
||||
(&ast::LitFloat(ref v, _), &ty::TyFloat(ast::TyF32)) |
|
||||
(&ast::LitFloatUnsuffixed(ref v), &ty::TyFloat(ast::TyF32)) =>
|
||||
Literal::Float { bits: FloatBits::F32, value: v.parse::<f64>().unwrap() },
|
||||
(&hir::LitFloat(ref v, _), &ty::TyFloat(hir::TyF64)) |
|
||||
(&hir::LitFloatUnsuffixed(ref v), &ty::TyFloat(hir::TyF64)) =>
|
||||
(&ast::LitFloat(ref v, _), &ty::TyFloat(ast::TyF64)) |
|
||||
(&ast::LitFloatUnsuffixed(ref v), &ty::TyFloat(ast::TyF64)) =>
|
||||
Literal::Float { bits: FloatBits::F64, value: v.parse::<f64>().unwrap() },
|
||||
(&hir::LitBool(v), _) =>
|
||||
(&ast::LitBool(v), _) =>
|
||||
Literal::Bool { value: v },
|
||||
(ref l, ref t) =>
|
||||
cx.tcx.sess.span_bug(
|
||||
|
@ -37,6 +37,7 @@ use rustc::middle::def::*;
|
||||
use rustc::middle::def_id::DefId;
|
||||
|
||||
use syntax::ast::{Name, NodeId};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::parse::token::special_idents;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
|
||||
@ -53,7 +54,6 @@ use rustc_front::hir::TupleVariantKind;
|
||||
use rustc_front::hir::UnnamedField;
|
||||
use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use rustc_front::hir::Visibility;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
|
||||
use std::mem::replace;
|
||||
|
@ -65,7 +65,8 @@ use rustc::util::nodemap::{NodeMap, DefIdSet, FnvHashMap};
|
||||
use rustc::util::lev_distance::lev_distance;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Ident, Name, NodeId, CrateNum};
|
||||
use syntax::ast::{Ident, Name, NodeId, CrateNum, TyIs, TyI8, TyI16, TyI32, TyI64};
|
||||
use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::ext::mtwt;
|
||||
use syntax::parse::token::{self, special_names, special_idents};
|
||||
@ -86,10 +87,8 @@ use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse};
|
||||
use rustc_front::hir::{Local, MethodImplItem};
|
||||
use rustc_front::hir::{Pat, PatEnum, PatIdent, PatLit, PatQPath};
|
||||
use rustc_front::hir::{PatRange, PatStruct, Path, PrimTy};
|
||||
use rustc_front::hir::{TraitRef, Ty, TyBool, TyChar, TyF32};
|
||||
use rustc_front::hir::{TyF64, TyFloat, TyIs, TyI8, TyI16, TyI32, TyI64, TyInt};
|
||||
use rustc_front::hir::{TyPath, TyPtr};
|
||||
use rustc_front::hir::{TyRptr, TyStr, TyUs, TyU8, TyU16, TyU32, TyU64, TyUint};
|
||||
use rustc_front::hir::{TraitRef, Ty, TyBool, TyChar, TyFloat, TyInt};
|
||||
use rustc_front::hir::{TyRptr, TyStr, TyUint, TyPath, TyPtr};
|
||||
use rustc_front::hir::TypeImplItem;
|
||||
use rustc_front::util::walk_pat;
|
||||
|
||||
|
@ -46,7 +46,6 @@ use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use rustc_front::attr::AttrMetaMethods as FrontAttrMetaMethods;
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
|
@ -905,7 +905,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
compare_str(cx, lhs_data, lhs_len, rhs_data, rhs_len, rhs_t, debug_loc)
|
||||
}
|
||||
ty::TyArray(ty, _) | ty::TySlice(ty) => match ty.sty {
|
||||
ty::TyUint(hir::TyU8) => {
|
||||
ty::TyUint(ast::TyU8) => {
|
||||
// NOTE: cast &[u8] and &[u8; N] to &str and abuse the str_eq lang item,
|
||||
// which calls memcmp().
|
||||
let pat_len = val_ty(rhs).element_type().array_length();
|
||||
|
@ -51,9 +51,8 @@ use middle::subst;
|
||||
use middle::ty::{self, Ty};
|
||||
use middle::ty::Disr;
|
||||
use syntax::ast;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::attr::IntType;
|
||||
use rustc_front::hir;
|
||||
use syntax::attr;
|
||||
use syntax::attr::IntType;
|
||||
use trans::_match;
|
||||
use trans::build::*;
|
||||
use trans::cleanup;
|
||||
@ -387,11 +386,11 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
let ity = if use_align {
|
||||
// Use the overall alignment
|
||||
match align {
|
||||
1 => attr::UnsignedInt(hir::TyU8),
|
||||
2 => attr::UnsignedInt(hir::TyU16),
|
||||
4 => attr::UnsignedInt(hir::TyU32),
|
||||
1 => attr::UnsignedInt(ast::TyU8),
|
||||
2 => attr::UnsignedInt(ast::TyU16),
|
||||
4 => attr::UnsignedInt(ast::TyU32),
|
||||
8 if machine::llalign_of_min(cx, Type::i64(cx)) == 8 =>
|
||||
attr::UnsignedInt(hir::TyU64),
|
||||
attr::UnsignedInt(ast::TyU64),
|
||||
_ => min_ity // use min_ity as a fallback
|
||||
}
|
||||
} else {
|
||||
@ -583,12 +582,12 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
|
||||
// Lists of sizes to try. u64 is always allowed as a fallback.
|
||||
#[allow(non_upper_case_globals)]
|
||||
const choose_shortest: &'static [IntType] = &[
|
||||
attr::UnsignedInt(hir::TyU8), attr::SignedInt(hir::TyI8),
|
||||
attr::UnsignedInt(hir::TyU16), attr::SignedInt(hir::TyI16),
|
||||
attr::UnsignedInt(hir::TyU32), attr::SignedInt(hir::TyI32)];
|
||||
attr::UnsignedInt(ast::TyU8), attr::SignedInt(ast::TyI8),
|
||||
attr::UnsignedInt(ast::TyU16), attr::SignedInt(ast::TyI16),
|
||||
attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)];
|
||||
#[allow(non_upper_case_globals)]
|
||||
const at_least_32: &'static [IntType] = &[
|
||||
attr::UnsignedInt(hir::TyU32), attr::SignedInt(hir::TyI32)];
|
||||
attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)];
|
||||
|
||||
let attempts;
|
||||
match hint {
|
||||
@ -622,7 +621,7 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
|
||||
return ity;
|
||||
}
|
||||
}
|
||||
return attr::UnsignedInt(hir::TyU64);
|
||||
return attr::UnsignedInt(ast::TyU64);
|
||||
}
|
||||
|
||||
pub fn ll_inttype(cx: &CrateContext, ity: IntType) -> Type {
|
||||
|
@ -15,8 +15,9 @@ use middle::ty;
|
||||
use middle::infer;
|
||||
use session::config::NoDebugInfo;
|
||||
use syntax::abi;
|
||||
pub use syntax::attr::InlineAttr;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
pub use rustc_front::attr::InlineAttr;
|
||||
use trans::base;
|
||||
use trans::common;
|
||||
use trans::context::CrateContext;
|
||||
@ -90,8 +91,8 @@ pub fn set_optimize_for_size(val: ValueRef, optimize: bool) {
|
||||
|
||||
/// Composite function which sets LLVM attributes for function depending on its AST (#[attribute])
|
||||
/// attributes.
|
||||
pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[hir::Attribute], llfn: ValueRef) {
|
||||
use rustc_front::attr::*;
|
||||
pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[ast::Attribute], llfn: ValueRef) {
|
||||
use syntax::attr::*;
|
||||
inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), attrs));
|
||||
|
||||
// FIXME: #11906: Omitting frame pointers breaks retrieving the value of a
|
||||
|
@ -95,9 +95,9 @@ use std::{i8, i16, i32, i64};
|
||||
use syntax::abi::{Rust, RustCall, RustIntrinsic, PlatformIntrinsic, Abi};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::attr;
|
||||
use rustc_front;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::visit::Visitor;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir;
|
||||
@ -581,12 +581,12 @@ pub fn llty_and_min_for_signed_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
ty::TyInt(t) => {
|
||||
let llty = Type::int_from_ty(cx.ccx(), t);
|
||||
let min = match t {
|
||||
hir::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
|
||||
hir::TyIs => i64::MIN as u64,
|
||||
hir::TyI8 => i8::MIN as u64,
|
||||
hir::TyI16 => i16::MIN as u64,
|
||||
hir::TyI32 => i32::MIN as u64,
|
||||
hir::TyI64 => i64::MIN as u64,
|
||||
ast::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64,
|
||||
ast::TyIs => i64::MIN as u64,
|
||||
ast::TyI8 => i8::MIN as u64,
|
||||
ast::TyI16 => i16::MIN as u64,
|
||||
ast::TyI32 => i32::MIN as u64,
|
||||
ast::TyI64 => i64::MIN as u64,
|
||||
};
|
||||
(llty, min)
|
||||
}
|
||||
@ -1563,7 +1563,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
llfndecl: ValueRef,
|
||||
param_substs: &'tcx Substs<'tcx>,
|
||||
fn_ast_id: ast::NodeId,
|
||||
_attributes: &[hir::Attribute],
|
||||
_attributes: &[ast::Attribute],
|
||||
output_type: ty::FnOutput<'tcx>,
|
||||
abi: Abi,
|
||||
closure_env: closure::ClosureEnv<'b>) {
|
||||
@ -1682,7 +1682,7 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
llfndecl: ValueRef,
|
||||
param_substs: &'tcx Substs<'tcx>,
|
||||
id: ast::NodeId,
|
||||
attrs: &[hir::Attribute]) {
|
||||
attrs: &[ast::Attribute]) {
|
||||
let _s = StatRecorder::new(ccx, ccx.tcx().map.path_to_string(id).to_string());
|
||||
debug!("trans_fn(param_substs={:?})", param_substs);
|
||||
let _icx = push_ctxt("trans_fn");
|
||||
@ -2294,7 +2294,7 @@ pub fn create_entry_wrapper(ccx: &CrateContext,
|
||||
}
|
||||
|
||||
fn exported_name<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, id: ast::NodeId,
|
||||
ty: Ty<'tcx>, attrs: &[hir::Attribute]) -> String {
|
||||
ty: Ty<'tcx>, attrs: &[ast::Attribute]) -> String {
|
||||
match ccx.external_srcs().borrow().get(&id) {
|
||||
Some(&did) => {
|
||||
let sym = csearch::get_symbol(&ccx.sess().cstore, did);
|
||||
@ -2492,7 +2492,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
|
||||
}
|
||||
|
||||
fn register_method(ccx: &CrateContext, id: ast::NodeId,
|
||||
attrs: &[hir::Attribute], span: Span) -> ValueRef {
|
||||
attrs: &[ast::Attribute], span: Span) -> ValueRef {
|
||||
let mty = ccx.tcx().node_id_to_type(id);
|
||||
|
||||
let sym = exported_name(ccx, id, mty, &attrs);
|
||||
|
@ -41,30 +41,30 @@ use middle::ty::cast::{CastTy,IntTy};
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use libc::c_uint;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::parse::token;
|
||||
use syntax::ptr::P;
|
||||
|
||||
pub type FnArgMap<'a> = Option<&'a NodeMap<ValueRef>>;
|
||||
|
||||
pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit)
|
||||
pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit)
|
||||
-> ValueRef {
|
||||
let _icx = push_ctxt("trans_lit");
|
||||
debug!("const_lit: {:?}", lit);
|
||||
match lit.node {
|
||||
hir::LitByte(b) => C_integral(Type::uint_from_ty(cx, hir::TyU8), b as u64, false),
|
||||
hir::LitChar(i) => C_integral(Type::char(cx), i as u64, false),
|
||||
hir::LitInt(i, hir::SignedIntLit(t, _)) => {
|
||||
ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::TyU8), b as u64, false),
|
||||
ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false),
|
||||
ast::LitInt(i, ast::SignedIntLit(t, _)) => {
|
||||
C_integral(Type::int_from_ty(cx, t), i, true)
|
||||
}
|
||||
hir::LitInt(u, hir::UnsignedIntLit(t)) => {
|
||||
ast::LitInt(u, ast::UnsignedIntLit(t)) => {
|
||||
C_integral(Type::uint_from_ty(cx, t), u, false)
|
||||
}
|
||||
hir::LitInt(i, hir::UnsuffixedIntLit(_)) => {
|
||||
ast::LitInt(i, ast::UnsuffixedIntLit(_)) => {
|
||||
let lit_int_ty = cx.tcx().node_id_to_type(e.id);
|
||||
match lit_int_ty.sty {
|
||||
ty::TyInt(t) => {
|
||||
@ -79,10 +79,10 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit)
|
||||
lit_int_ty))
|
||||
}
|
||||
}
|
||||
hir::LitFloat(ref fs, t) => {
|
||||
ast::LitFloat(ref fs, t) => {
|
||||
C_floating(&fs, Type::float_from_ty(cx, t))
|
||||
}
|
||||
hir::LitFloatUnsuffixed(ref fs) => {
|
||||
ast::LitFloatUnsuffixed(ref fs) => {
|
||||
let lit_float_ty = cx.tcx().node_id_to_type(e.id);
|
||||
match lit_float_ty.sty {
|
||||
ty::TyFloat(t) => {
|
||||
@ -94,9 +94,9 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &hir::Lit)
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::LitBool(b) => C_bool(cx, b),
|
||||
hir::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
|
||||
hir::LitByteStr(ref data) => {
|
||||
ast::LitBool(b) => C_bool(cx, b),
|
||||
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
|
||||
ast::LitByteStr(ref data) => {
|
||||
addr_of(cx, C_bytes(cx, &data[..]), "byte_str")
|
||||
}
|
||||
}
|
||||
@ -898,7 +898,7 @@ pub fn trans_static(ccx: &CrateContext,
|
||||
m: hir::Mutability,
|
||||
expr: &hir::Expr,
|
||||
id: ast::NodeId,
|
||||
attrs: &Vec<hir::Attribute>)
|
||||
attrs: &Vec<ast::Attribute>)
|
||||
-> ValueRef {
|
||||
unsafe {
|
||||
let _icx = push_ctxt("trans_static");
|
||||
|
@ -20,7 +20,7 @@ use session::config::NoDebugInfo;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
use rustc_front::attr;
|
||||
use syntax::attr;
|
||||
|
||||
|
||||
/// Inserts a side-effect free instruction sequence that makes sure that the
|
||||
|
@ -27,7 +27,6 @@ use middle::def_id::DefId;
|
||||
use middle::pat_util;
|
||||
use middle::subst::{self, Substs};
|
||||
use rustc::front::map as hir_map;
|
||||
use rustc_front;
|
||||
use rustc_front::hir;
|
||||
use trans::{type_of, adt, machine, monomorphize};
|
||||
use trans::common::{self, CrateContext, FunctionContext, Block};
|
||||
@ -43,6 +42,7 @@ use std::ffi::CString;
|
||||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use syntax;
|
||||
use syntax::util::interner::Interner;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::{ast, codemap};
|
||||
@ -934,22 +934,22 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
ty::TyBool => ("bool".to_string(), DW_ATE_boolean),
|
||||
ty::TyChar => ("char".to_string(), DW_ATE_unsigned_char),
|
||||
ty::TyInt(int_ty) => match int_ty {
|
||||
hir::TyIs => ("isize".to_string(), DW_ATE_signed),
|
||||
hir::TyI8 => ("i8".to_string(), DW_ATE_signed),
|
||||
hir::TyI16 => ("i16".to_string(), DW_ATE_signed),
|
||||
hir::TyI32 => ("i32".to_string(), DW_ATE_signed),
|
||||
hir::TyI64 => ("i64".to_string(), DW_ATE_signed)
|
||||
ast::TyIs => ("isize".to_string(), DW_ATE_signed),
|
||||
ast::TyI8 => ("i8".to_string(), DW_ATE_signed),
|
||||
ast::TyI16 => ("i16".to_string(), DW_ATE_signed),
|
||||
ast::TyI32 => ("i32".to_string(), DW_ATE_signed),
|
||||
ast::TyI64 => ("i64".to_string(), DW_ATE_signed)
|
||||
},
|
||||
ty::TyUint(uint_ty) => match uint_ty {
|
||||
hir::TyUs => ("usize".to_string(), DW_ATE_unsigned),
|
||||
hir::TyU8 => ("u8".to_string(), DW_ATE_unsigned),
|
||||
hir::TyU16 => ("u16".to_string(), DW_ATE_unsigned),
|
||||
hir::TyU32 => ("u32".to_string(), DW_ATE_unsigned),
|
||||
hir::TyU64 => ("u64".to_string(), DW_ATE_unsigned)
|
||||
ast::TyUs => ("usize".to_string(), DW_ATE_unsigned),
|
||||
ast::TyU8 => ("u8".to_string(), DW_ATE_unsigned),
|
||||
ast::TyU16 => ("u16".to_string(), DW_ATE_unsigned),
|
||||
ast::TyU32 => ("u32".to_string(), DW_ATE_unsigned),
|
||||
ast::TyU64 => ("u64".to_string(), DW_ATE_unsigned)
|
||||
},
|
||||
ty::TyFloat(float_ty) => match float_ty {
|
||||
hir::TyF32 => ("f32".to_string(), DW_ATE_float),
|
||||
hir::TyF64 => ("f64".to_string(), DW_ATE_float),
|
||||
ast::TyF32 => ("f32".to_string(), DW_ATE_float),
|
||||
ast::TyF64 => ("f64".to_string(), DW_ATE_float),
|
||||
},
|
||||
_ => cx.sess().bug("debuginfo::basic_type_metadata - t is invalid type")
|
||||
};
|
||||
@ -1608,7 +1608,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let discriminant_type_metadata = |inttype: rustc_front::attr::IntType| {
|
||||
let discriminant_type_metadata = |inttype: syntax::attr::IntType| {
|
||||
let disr_type_key = (enum_def_id, inttype);
|
||||
let cached_discriminant_type_metadata = debug_context(cx).created_enum_disr_types
|
||||
.borrow()
|
||||
|
@ -31,7 +31,6 @@ use middle::infer::normalize_associated_type;
|
||||
use middle::subst::{self, Substs};
|
||||
use rustc_front;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr::IntType;
|
||||
|
||||
use trans::common::{NodeIdAndSpan, CrateContext, FunctionContext, Block};
|
||||
use trans;
|
||||
@ -49,6 +48,7 @@ use std::rc::Rc;
|
||||
|
||||
use syntax::codemap::{Span, Pos};
|
||||
use syntax::{abi, ast, codemap};
|
||||
use syntax::attr::IntType;
|
||||
use syntax::parse::token::{self, special_idents};
|
||||
|
||||
pub mod gdb;
|
||||
|
@ -18,7 +18,7 @@ use middle::subst::{self, Substs};
|
||||
use middle::ty::{self, Ty};
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
use syntax::ast;
|
||||
|
||||
// Compute the name of the type as it should be stored in debuginfo. Does not do
|
||||
// any caching, i.e. calling the function twice with the same type will also do
|
||||
@ -43,18 +43,18 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
ty::TyBool => output.push_str("bool"),
|
||||
ty::TyChar => output.push_str("char"),
|
||||
ty::TyStr => output.push_str("str"),
|
||||
ty::TyInt(hir::TyIs) => output.push_str("isize"),
|
||||
ty::TyInt(hir::TyI8) => output.push_str("i8"),
|
||||
ty::TyInt(hir::TyI16) => output.push_str("i16"),
|
||||
ty::TyInt(hir::TyI32) => output.push_str("i32"),
|
||||
ty::TyInt(hir::TyI64) => output.push_str("i64"),
|
||||
ty::TyUint(hir::TyUs) => output.push_str("usize"),
|
||||
ty::TyUint(hir::TyU8) => output.push_str("u8"),
|
||||
ty::TyUint(hir::TyU16) => output.push_str("u16"),
|
||||
ty::TyUint(hir::TyU32) => output.push_str("u32"),
|
||||
ty::TyUint(hir::TyU64) => output.push_str("u64"),
|
||||
ty::TyFloat(hir::TyF32) => output.push_str("f32"),
|
||||
ty::TyFloat(hir::TyF64) => output.push_str("f64"),
|
||||
ty::TyInt(ast::TyIs) => output.push_str("isize"),
|
||||
ty::TyInt(ast::TyI8) => output.push_str("i8"),
|
||||
ty::TyInt(ast::TyI16) => output.push_str("i16"),
|
||||
ty::TyInt(ast::TyI32) => output.push_str("i32"),
|
||||
ty::TyInt(ast::TyI64) => output.push_str("i64"),
|
||||
ty::TyUint(ast::TyUs) => output.push_str("usize"),
|
||||
ty::TyUint(ast::TyU8) => output.push_str("u8"),
|
||||
ty::TyUint(ast::TyU16) => output.push_str("u16"),
|
||||
ty::TyUint(ast::TyU32) => output.push_str("u32"),
|
||||
ty::TyUint(ast::TyU64) => output.push_str("u64"),
|
||||
ty::TyFloat(ast::TyF32) => output.push_str("f32"),
|
||||
ty::TyFloat(ast::TyF64) => output.push_str("f64"),
|
||||
ty::TyStruct(def, substs) |
|
||||
ty::TyEnum(def, substs) => {
|
||||
push_item_name(cx, def.did, qualified, output);
|
||||
|
@ -21,8 +21,6 @@ use trans::machine;
|
||||
use trans::common::{CrateContext, FunctionContext};
|
||||
use trans::type_::Type;
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
use syntax::codemap::Span;
|
||||
use syntax::{ast, codemap};
|
||||
|
||||
@ -46,11 +44,11 @@ pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn contains_nodebug_attribute(attributes: &[hir::Attribute]) -> bool {
|
||||
pub fn contains_nodebug_attribute(attributes: &[ast::Attribute]) -> bool {
|
||||
attributes.iter().any(|attr| {
|
||||
let meta_item: &hir::MetaItem = &*attr.node.value;
|
||||
let meta_item: &ast::MetaItem = &*attr.node.value;
|
||||
match meta_item.node {
|
||||
hir::MetaWord(ref value) => &value[..] == "no_debug",
|
||||
ast::MetaWord(ref value) => &value[..] == "no_debug",
|
||||
_ => false
|
||||
}
|
||||
})
|
||||
|
@ -83,7 +83,7 @@ use trans::type_::Type;
|
||||
use rustc_front;
|
||||
use rustc_front::hir;
|
||||
|
||||
use syntax::{ast, codemap};
|
||||
use syntax::{ast, ast_util, codemap};
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::ptr::P;
|
||||
use syntax::parse::token;
|
||||
@ -1140,7 +1140,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
}
|
||||
hir::ExprLit(ref lit) => {
|
||||
match lit.node {
|
||||
hir::LitStr(ref s, _) => {
|
||||
ast::LitStr(ref s, _) => {
|
||||
tvec::trans_lit_str(bcx, expr, (*s).clone(), dest)
|
||||
}
|
||||
_ => {
|
||||
@ -1549,7 +1549,7 @@ pub fn trans_adt<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
|
||||
|
||||
fn trans_immediate_lit<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
expr: &hir::Expr,
|
||||
lit: &hir::Lit)
|
||||
lit: &ast::Lit)
|
||||
-> DatumBlock<'blk, 'tcx, Expr> {
|
||||
// must not be a string constant, that is a RvalueDpsExpr
|
||||
let _icx = push_ctxt("trans_immediate_lit");
|
||||
@ -2381,8 +2381,8 @@ impl OverflowOpViaIntrinsic {
|
||||
bcx.ccx().get_intrinsic(&name)
|
||||
}
|
||||
fn to_intrinsic_name(&self, tcx: &ty::ctxt, ty: Ty) -> &'static str {
|
||||
use rustc_front::hir::IntTy::*;
|
||||
use rustc_front::hir::UintTy::*;
|
||||
use syntax::ast::IntTy::*;
|
||||
use syntax::ast::UintTy::*;
|
||||
use middle::ty::{TyInt, TyUint};
|
||||
|
||||
let new_sty = match ty.sty {
|
||||
@ -2714,7 +2714,7 @@ fn expr_kind(tcx: &ty::ctxt, expr: &hir::Expr) -> ExprKind {
|
||||
ExprKind::RvalueDps
|
||||
}
|
||||
|
||||
hir::ExprLit(ref lit) if rustc_front::util::lit_is_str(&**lit) => {
|
||||
hir::ExprLit(ref lit) if ast_util::lit_is_str(&**lit) => {
|
||||
ExprKind::RvalueDps
|
||||
}
|
||||
|
||||
|
@ -35,12 +35,12 @@ use std::cmp;
|
||||
use libc::c_uint;
|
||||
use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi};
|
||||
use syntax::abi::{PlatformIntrinsic, RustIntrinsic, Rust, RustCall, Stdcall, Fastcall, System};
|
||||
use syntax::attr;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::{InternedString, special_idents};
|
||||
use syntax::ast;
|
||||
|
||||
use rustc_front::print::pprust;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::hir;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -188,7 +188,7 @@ pub fn get_extern_fn(ccx: &CrateContext,
|
||||
pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
abi: Abi, fty: Ty<'tcx>,
|
||||
name: &str,
|
||||
attrs: &[hir::Attribute])-> ValueRef {
|
||||
attrs: &[ast::Attribute])-> ValueRef {
|
||||
debug!("register_foreign_item_fn(abi={:?}, \
|
||||
ty={:?}, \
|
||||
name={})",
|
||||
@ -577,7 +577,7 @@ pub fn register_rust_fn_with_foreign_abi(ccx: &CrateContext,
|
||||
pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
decl: &hir::FnDecl,
|
||||
body: &hir::Block,
|
||||
attrs: &[hir::Attribute],
|
||||
attrs: &[ast::Attribute],
|
||||
llwrapfn: ValueRef,
|
||||
param_substs: &'tcx Substs<'tcx>,
|
||||
id: ast::NodeId,
|
||||
@ -600,7 +600,7 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
decl: &hir::FnDecl,
|
||||
body: &hir::Block,
|
||||
param_substs: &'tcx Substs<'tcx>,
|
||||
attrs: &[hir::Attribute],
|
||||
attrs: &[ast::Attribute],
|
||||
id: ast::NodeId,
|
||||
hash: Option<&str>)
|
||||
-> ValueRef
|
||||
|
@ -38,10 +38,10 @@ use middle::ty::{self, Ty, HasTypeFlags};
|
||||
use middle::ty::MethodCall;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::DUMMY_SP;
|
||||
use syntax::ptr::P;
|
||||
|
||||
use rustc_front::attr;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir;
|
||||
|
||||
@ -773,7 +773,7 @@ fn emit_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
fn opaque_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>, method_ty: &ty::BareFnTy<'tcx>)
|
||||
-> &'tcx ty::BareFnTy<'tcx> {
|
||||
let mut inputs = method_ty.sig.0.inputs.clone();
|
||||
inputs[0] = tcx.mk_mut_ptr(tcx.mk_mach_int(hir::TyI8));
|
||||
inputs[0] = tcx.mk_mut_ptr(tcx.mk_mach_int(ast::TyI8));
|
||||
|
||||
tcx.mk_bare_fn(ty::BareFnTy {
|
||||
unsafety: method_ty.unsafety,
|
||||
|
@ -28,10 +28,10 @@ use middle::ty::{self, HasTypeFlags, Ty};
|
||||
use rustc::front::map as hir_map;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use std::hash::{Hasher, Hash, SipHasher};
|
||||
|
||||
pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
@ -146,7 +146,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
ccx.monomorphized().borrow_mut().insert(hash_id.take().unwrap(), lldecl);
|
||||
lldecl
|
||||
};
|
||||
let setup_lldecl = |lldecl, attrs: &[hir::Attribute]| {
|
||||
let setup_lldecl = |lldecl, attrs: &[ast::Attribute]| {
|
||||
base::update_linkage(ccx, lldecl, None, base::OriginalTranslation);
|
||||
attributes::from_fn_attrs(ccx, attrs, lldecl);
|
||||
|
||||
|
@ -30,6 +30,7 @@ use middle::ty::{self, Ty};
|
||||
|
||||
use rustc_front::hir;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::parse::token::InternedString;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
@ -91,7 +92,7 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
|
||||
// Handle the "..." case (returns a slice since strings are always unsized):
|
||||
if let hir::ExprLit(ref lit) = content_expr.node {
|
||||
if let hir::LitStr(ref s, _) = lit.node {
|
||||
if let ast::LitStr(ref s, _) = lit.node {
|
||||
let scratch = rvalue_scratch_datum(bcx, vec_ty, "");
|
||||
bcx = trans_lit_str(bcx,
|
||||
content_expr,
|
||||
@ -172,7 +173,7 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
match content_expr.node {
|
||||
hir::ExprLit(ref lit) => {
|
||||
match lit.node {
|
||||
hir::LitStr(ref s, _) => {
|
||||
ast::LitStr(ref s, _) => {
|
||||
match dest {
|
||||
Ignore => return bcx,
|
||||
SaveIn(lldest) => {
|
||||
@ -268,7 +269,7 @@ fn elements_required(bcx: Block, content_expr: &hir::Expr) -> usize {
|
||||
match content_expr.node {
|
||||
hir::ExprLit(ref lit) => {
|
||||
match lit.node {
|
||||
hir::LitStr(ref s, _) => s.len(),
|
||||
ast::LitStr(ref s, _) => s.len(),
|
||||
_ => {
|
||||
bcx.tcx().sess.span_bug(content_expr.span,
|
||||
"unexpected evec content")
|
||||
|
@ -17,7 +17,7 @@ use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128};
|
||||
use trans::context::CrateContext;
|
||||
use util::nodemap::FnvHashMap;
|
||||
|
||||
use rustc_front::hir;
|
||||
use syntax::ast;
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::mem;
|
||||
@ -125,30 +125,30 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn int_from_ty(ccx: &CrateContext, t: hir::IntTy) -> Type {
|
||||
pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
|
||||
match t {
|
||||
hir::TyIs => ccx.int_type(),
|
||||
hir::TyI8 => Type::i8(ccx),
|
||||
hir::TyI16 => Type::i16(ccx),
|
||||
hir::TyI32 => Type::i32(ccx),
|
||||
hir::TyI64 => Type::i64(ccx)
|
||||
ast::TyIs => ccx.int_type(),
|
||||
ast::TyI8 => Type::i8(ccx),
|
||||
ast::TyI16 => Type::i16(ccx),
|
||||
ast::TyI32 => Type::i32(ccx),
|
||||
ast::TyI64 => Type::i64(ccx)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uint_from_ty(ccx: &CrateContext, t: hir::UintTy) -> Type {
|
||||
pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
|
||||
match t {
|
||||
hir::TyUs => ccx.int_type(),
|
||||
hir::TyU8 => Type::i8(ccx),
|
||||
hir::TyU16 => Type::i16(ccx),
|
||||
hir::TyU32 => Type::i32(ccx),
|
||||
hir::TyU64 => Type::i64(ccx)
|
||||
ast::TyUs => ccx.int_type(),
|
||||
ast::TyU8 => Type::i8(ccx),
|
||||
ast::TyU16 => Type::i16(ccx),
|
||||
ast::TyU32 => Type::i32(ccx),
|
||||
ast::TyU64 => Type::i64(ccx)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn float_from_ty(ccx: &CrateContext, t: hir::FloatTy) -> Type {
|
||||
pub fn float_from_ty(ccx: &CrateContext, t: ast::FloatTy) -> Type {
|
||||
match t {
|
||||
hir::TyF32 => Type::f32(ccx),
|
||||
hir::TyF64 => Type::f64(ccx),
|
||||
ast::TyF32 => Type::f32(ccx),
|
||||
ast::TyF64 => Type::f64(ccx),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ use middle::ty::{self, RegionEscape, Ty};
|
||||
use trans::type_::Type;
|
||||
|
||||
use syntax::abi;
|
||||
use rustc_front::hir;
|
||||
use syntax::ast;
|
||||
|
||||
// LLVM doesn't like objects that are too big. Issue #17913
|
||||
fn ensure_array_fits_in_address_space<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
@ -379,7 +379,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
|
||||
let unsized_part = cx.tcx().struct_tail(ty);
|
||||
let info_ty = match unsized_part.sty {
|
||||
ty::TyStr | ty::TyArray(..) | ty::TySlice(_) => {
|
||||
Type::uint_from_ty(cx, hir::TyUs)
|
||||
Type::uint_from_ty(cx, ast::TyUs)
|
||||
}
|
||||
ty::TyTrait(_) => Type::vtable_ptr(cx),
|
||||
_ => panic!("Unexpected type returned from \
|
||||
|
@ -56,7 +56,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
||||
// They can denote both statically and dynamically sized byte arrays
|
||||
let mut pat_ty = expr_ty;
|
||||
if let hir::ExprLit(ref lt) = lt.node {
|
||||
if let hir::LitByteStr(_) = lt.node {
|
||||
if let ast::LitByteStr(_) = lt.node {
|
||||
let expected_ty = structurally_resolved_type(fcx, pat.span, expected);
|
||||
if let ty::TyRef(_, mt) = expected_ty.sty {
|
||||
if let ty::TySlice(_) = mt.ty.sty {
|
||||
|
@ -49,7 +49,8 @@ use middle::ty::{self, Ty, HasTypeFlags};
|
||||
use middle::ty::cast::{CastKind, CastTy};
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::UintTy::TyU8;
|
||||
use syntax::ast;
|
||||
use syntax::ast::UintTy::TyU8;
|
||||
|
||||
|
||||
/// Reifies a cast check to be checked once we have full type information for
|
||||
@ -245,7 +246,7 @@ impl<'tcx> CastCheck<'tcx> {
|
||||
(_, Int(Bool)) => Err(CastError::CastToBool),
|
||||
|
||||
// * -> Char
|
||||
(Int(U(hir::TyU8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
|
||||
(Int(U(ast::TyU8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
|
||||
(_, Int(Char)) => Err(CastError::CastToChar),
|
||||
|
||||
// prim -> float,ptr
|
||||
|
@ -22,6 +22,7 @@ use {CrateCtxt, require_same_types};
|
||||
|
||||
use std::collections::{HashMap};
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
@ -470,22 +471,22 @@ fn match_intrinsic_type_to_type<'tcx, 'a>(
|
||||
},
|
||||
// (The width we pass to LLVM doesn't concern the type checker.)
|
||||
Integer(signed, bits, _llvm_width) => match (signed, bits, &t.sty) {
|
||||
(true, 8, &ty::TyInt(hir::IntTy::TyI8)) |
|
||||
(false, 8, &ty::TyUint(hir::UintTy::TyU8)) |
|
||||
(true, 16, &ty::TyInt(hir::IntTy::TyI16)) |
|
||||
(false, 16, &ty::TyUint(hir::UintTy::TyU16)) |
|
||||
(true, 32, &ty::TyInt(hir::IntTy::TyI32)) |
|
||||
(false, 32, &ty::TyUint(hir::UintTy::TyU32)) |
|
||||
(true, 64, &ty::TyInt(hir::IntTy::TyI64)) |
|
||||
(false, 64, &ty::TyUint(hir::UintTy::TyU64)) => {},
|
||||
(true, 8, &ty::TyInt(ast::IntTy::TyI8)) |
|
||||
(false, 8, &ty::TyUint(ast::UintTy::TyU8)) |
|
||||
(true, 16, &ty::TyInt(ast::IntTy::TyI16)) |
|
||||
(false, 16, &ty::TyUint(ast::UintTy::TyU16)) |
|
||||
(true, 32, &ty::TyInt(ast::IntTy::TyI32)) |
|
||||
(false, 32, &ty::TyUint(ast::UintTy::TyU32)) |
|
||||
(true, 64, &ty::TyInt(ast::IntTy::TyI64)) |
|
||||
(false, 64, &ty::TyUint(ast::UintTy::TyU64)) => {},
|
||||
_ => simple_error(&format!("`{}`", t),
|
||||
&format!("`{}{n}`",
|
||||
if signed {"i"} else {"u"},
|
||||
n = bits)),
|
||||
},
|
||||
Float(bits) => match (bits, &t.sty) {
|
||||
(32, &ty::TyFloat(hir::FloatTy::TyF32)) |
|
||||
(64, &ty::TyFloat(hir::FloatTy::TyF64)) => {},
|
||||
(32, &ty::TyFloat(ast::FloatTy::TyF32)) |
|
||||
(64, &ty::TyFloat(ast::FloatTy::TyF64)) => {},
|
||||
_ => simple_error(&format!("`{}`", t),
|
||||
&format!("`f{n}`", n = bits)),
|
||||
},
|
||||
|
@ -319,51 +319,51 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
|
||||
let lang_def_id = self.tcx().lang_items.mut_ptr_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(hir::TyI8) => {
|
||||
ty::TyInt(ast::TyI8) => {
|
||||
let lang_def_id = self.tcx().lang_items.i8_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(hir::TyI16) => {
|
||||
ty::TyInt(ast::TyI16) => {
|
||||
let lang_def_id = self.tcx().lang_items.i16_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(hir::TyI32) => {
|
||||
ty::TyInt(ast::TyI32) => {
|
||||
let lang_def_id = self.tcx().lang_items.i32_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(hir::TyI64) => {
|
||||
ty::TyInt(ast::TyI64) => {
|
||||
let lang_def_id = self.tcx().lang_items.i64_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyInt(hir::TyIs) => {
|
||||
ty::TyInt(ast::TyIs) => {
|
||||
let lang_def_id = self.tcx().lang_items.isize_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(hir::TyU8) => {
|
||||
ty::TyUint(ast::TyU8) => {
|
||||
let lang_def_id = self.tcx().lang_items.u8_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(hir::TyU16) => {
|
||||
ty::TyUint(ast::TyU16) => {
|
||||
let lang_def_id = self.tcx().lang_items.u16_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(hir::TyU32) => {
|
||||
ty::TyUint(ast::TyU32) => {
|
||||
let lang_def_id = self.tcx().lang_items.u32_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(hir::TyU64) => {
|
||||
ty::TyUint(ast::TyU64) => {
|
||||
let lang_def_id = self.tcx().lang_items.u64_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyUint(hir::TyUs) => {
|
||||
ty::TyUint(ast::TyUs) => {
|
||||
let lang_def_id = self.tcx().lang_items.usize_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyFloat(hir::TyF32) => {
|
||||
ty::TyFloat(ast::TyF32) => {
|
||||
let lang_def_id = self.tcx().lang_items.f32_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::TyFloat(hir::TyF64) => {
|
||||
ty::TyFloat(ast::TyF64) => {
|
||||
let lang_def_id = self.tcx().lang_items.f64_impl();
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
|
@ -117,6 +117,8 @@ use std::mem::replace;
|
||||
use std::slice;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::codemap::{self, Span};
|
||||
use syntax::owned_slice::OwnedSlice;
|
||||
use syntax::parse::token::{self, InternedString};
|
||||
@ -125,8 +127,6 @@ use syntax::ptr::P;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::Visibility;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use rustc_front::hir::{Item, ItemImpl};
|
||||
use rustc_front::print::pprust;
|
||||
|
||||
@ -2309,7 +2309,7 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
|
||||
// First, try built-in indexing.
|
||||
match (adjusted_ty.builtin_index(), &index_ty.sty) {
|
||||
(Some(ty), &ty::TyUint(hir::TyUs)) | (Some(ty), &ty::TyInfer(ty::IntVar(_))) => {
|
||||
(Some(ty), &ty::TyUint(ast::TyUs)) | (Some(ty), &ty::TyInfer(ty::IntVar(_))) => {
|
||||
debug!("try_index_step: success, using built-in indexing");
|
||||
// If we had `[T; N]`, we should've caught it before unsizing to `[T]`.
|
||||
assert!(!unsize);
|
||||
@ -2573,21 +2573,21 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
let arg_ty = structurally_resolved_type(fcx, arg.span,
|
||||
fcx.expr_ty(&**arg));
|
||||
match arg_ty.sty {
|
||||
ty::TyFloat(hir::TyF32) => {
|
||||
ty::TyFloat(ast::TyF32) => {
|
||||
fcx.type_error_message(arg.span,
|
||||
|t| {
|
||||
format!("can't pass an {} to variadic \
|
||||
function, cast to c_double", t)
|
||||
}, arg_ty, None);
|
||||
}
|
||||
ty::TyInt(hir::TyI8) | ty::TyInt(hir::TyI16) | ty::TyBool => {
|
||||
ty::TyInt(ast::TyI8) | ty::TyInt(ast::TyI16) | ty::TyBool => {
|
||||
fcx.type_error_message(arg.span, |t| {
|
||||
format!("can't pass {} to variadic \
|
||||
function, cast to c_int",
|
||||
t)
|
||||
}, arg_ty, None);
|
||||
}
|
||||
ty::TyUint(hir::TyU8) | ty::TyUint(hir::TyU16) => {
|
||||
ty::TyUint(ast::TyU8) | ty::TyUint(ast::TyU16) => {
|
||||
fcx.type_error_message(arg.span, |t| {
|
||||
format!("can't pass {} to variadic \
|
||||
function, cast to c_uint",
|
||||
@ -2616,23 +2616,23 @@ fn write_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
|
||||
// AST fragment checking
|
||||
fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
lit: &hir::Lit,
|
||||
lit: &ast::Lit,
|
||||
expected: Expectation<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let tcx = fcx.ccx.tcx;
|
||||
|
||||
match lit.node {
|
||||
hir::LitStr(..) => tcx.mk_static_str(),
|
||||
hir::LitByteStr(ref v) => {
|
||||
ast::LitStr(..) => tcx.mk_static_str(),
|
||||
ast::LitByteStr(ref v) => {
|
||||
tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic),
|
||||
tcx.mk_array(tcx.types.u8, v.len()))
|
||||
}
|
||||
hir::LitByte(_) => tcx.types.u8,
|
||||
hir::LitChar(_) => tcx.types.char,
|
||||
hir::LitInt(_, hir::SignedIntLit(t, _)) => tcx.mk_mach_int(t),
|
||||
hir::LitInt(_, hir::UnsignedIntLit(t)) => tcx.mk_mach_uint(t),
|
||||
hir::LitInt(_, hir::UnsuffixedIntLit(_)) => {
|
||||
ast::LitByte(_) => tcx.types.u8,
|
||||
ast::LitChar(_) => tcx.types.char,
|
||||
ast::LitInt(_, ast::SignedIntLit(t, _)) => tcx.mk_mach_int(t),
|
||||
ast::LitInt(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t),
|
||||
ast::LitInt(_, ast::UnsuffixedIntLit(_)) => {
|
||||
let opt_ty = expected.to_option(fcx).and_then(|ty| {
|
||||
match ty.sty {
|
||||
ty::TyInt(_) | ty::TyUint(_) => Some(ty),
|
||||
@ -2645,8 +2645,8 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
opt_ty.unwrap_or_else(
|
||||
|| tcx.mk_int_var(fcx.infcx().next_int_var_id()))
|
||||
}
|
||||
hir::LitFloat(_, t) => tcx.mk_mach_float(t),
|
||||
hir::LitFloatUnsuffixed(_) => {
|
||||
ast::LitFloat(_, t) => tcx.mk_mach_float(t),
|
||||
ast::LitFloatUnsuffixed(_) => {
|
||||
let opt_ty = expected.to_option(fcx).and_then(|ty| {
|
||||
match ty.sty {
|
||||
ty::TyFloat(_) => Some(ty),
|
||||
@ -2656,7 +2656,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
opt_ty.unwrap_or_else(
|
||||
|| tcx.mk_float_var(fcx.infcx().next_float_var_id()))
|
||||
}
|
||||
hir::LitBool(_) => tcx.types.bool
|
||||
ast::LitBool(_) => tcx.types.bool
|
||||
}
|
||||
}
|
||||
|
||||
@ -4219,22 +4219,22 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
|
||||
fn disr_in_range(ccx: &CrateCtxt,
|
||||
ty: attr::IntType,
|
||||
disr: ty::Disr) -> bool {
|
||||
fn uint_in_range(ccx: &CrateCtxt, ty: hir::UintTy, disr: ty::Disr) -> bool {
|
||||
fn uint_in_range(ccx: &CrateCtxt, ty: ast::UintTy, disr: ty::Disr) -> bool {
|
||||
match ty {
|
||||
hir::TyU8 => disr as u8 as Disr == disr,
|
||||
hir::TyU16 => disr as u16 as Disr == disr,
|
||||
hir::TyU32 => disr as u32 as Disr == disr,
|
||||
hir::TyU64 => disr as u64 as Disr == disr,
|
||||
hir::TyUs => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr)
|
||||
ast::TyU8 => disr as u8 as Disr == disr,
|
||||
ast::TyU16 => disr as u16 as Disr == disr,
|
||||
ast::TyU32 => disr as u32 as Disr == disr,
|
||||
ast::TyU64 => disr as u64 as Disr == disr,
|
||||
ast::TyUs => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr)
|
||||
}
|
||||
}
|
||||
fn int_in_range(ccx: &CrateCtxt, ty: hir::IntTy, disr: ty::Disr) -> bool {
|
||||
fn int_in_range(ccx: &CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool {
|
||||
match ty {
|
||||
hir::TyI8 => disr as i8 as Disr == disr,
|
||||
hir::TyI16 => disr as i16 as Disr == disr,
|
||||
hir::TyI32 => disr as i32 as Disr == disr,
|
||||
hir::TyI64 => disr as i64 as Disr == disr,
|
||||
hir::TyIs => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr)
|
||||
ast::TyI8 => disr as i8 as Disr == disr,
|
||||
ast::TyI16 => disr as i16 as Disr == disr,
|
||||
ast::TyI32 => disr as i32 as Disr == disr,
|
||||
ast::TyI64 => disr as i64 as Disr == disr,
|
||||
ast::TyIs => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr)
|
||||
}
|
||||
}
|
||||
match ty {
|
||||
|
@ -14,6 +14,7 @@
|
||||
use middle::def_id::{DefId, LOCAL_CRATE};
|
||||
use middle::traits;
|
||||
use middle::ty;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::hir;
|
||||
@ -119,84 +120,84 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
|
||||
"*mut T",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(hir::TyI8) => {
|
||||
ty::TyInt(ast::TyI8) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i8_impl(),
|
||||
"i8",
|
||||
"i8",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(hir::TyI16) => {
|
||||
ty::TyInt(ast::TyI16) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i16_impl(),
|
||||
"i16",
|
||||
"i16",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(hir::TyI32) => {
|
||||
ty::TyInt(ast::TyI32) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i32_impl(),
|
||||
"i32",
|
||||
"i32",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(hir::TyI64) => {
|
||||
ty::TyInt(ast::TyI64) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.i64_impl(),
|
||||
"i64",
|
||||
"i64",
|
||||
item.span);
|
||||
}
|
||||
ty::TyInt(hir::TyIs) => {
|
||||
ty::TyInt(ast::TyIs) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.isize_impl(),
|
||||
"isize",
|
||||
"isize",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(hir::TyU8) => {
|
||||
ty::TyUint(ast::TyU8) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u8_impl(),
|
||||
"u8",
|
||||
"u8",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(hir::TyU16) => {
|
||||
ty::TyUint(ast::TyU16) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u16_impl(),
|
||||
"u16",
|
||||
"u16",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(hir::TyU32) => {
|
||||
ty::TyUint(ast::TyU32) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u32_impl(),
|
||||
"u32",
|
||||
"u32",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(hir::TyU64) => {
|
||||
ty::TyUint(ast::TyU64) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.u64_impl(),
|
||||
"u64",
|
||||
"u64",
|
||||
item.span);
|
||||
}
|
||||
ty::TyUint(hir::TyUs) => {
|
||||
ty::TyUint(ast::TyUs) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.usize_impl(),
|
||||
"usize",
|
||||
"usize",
|
||||
item.span);
|
||||
}
|
||||
ty::TyFloat(hir::TyF32) => {
|
||||
ty::TyFloat(ast::TyF32) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.f32_impl(),
|
||||
"f32",
|
||||
"f32",
|
||||
item.span);
|
||||
}
|
||||
ty::TyFloat(hir::TyF64) => {
|
||||
ty::TyFloat(ast::TyF64) => {
|
||||
self.check_primitive_impl(def_id,
|
||||
self.tcx.lang_items.f64_impl(),
|
||||
"f64",
|
||||
|
@ -93,12 +93,12 @@ use std::rc::Rc;
|
||||
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::special_idents;
|
||||
use syntax::ptr::P;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::print::pprust;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -13,7 +13,7 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use syntax::ast;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use rustc_front::hir;
|
||||
|
||||
use rustc::metadata::csearch;
|
||||
|
@ -27,6 +27,8 @@ pub use self::FunctionRetTy::*;
|
||||
use syntax;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::attr::{AttributeMethods, AttrMetaMethods};
|
||||
use syntax::codemap;
|
||||
use syntax::codemap::{DUMMY_SP, Pos, Spanned};
|
||||
use syntax::parse::token::{self, InternedString, special_idents};
|
||||
@ -43,9 +45,6 @@ use rustc::middle::ty;
|
||||
use rustc::middle::stability;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
use rustc_front::attr::{AttributeMethods, AttrMetaMethods};
|
||||
use rustc_front::lowering::unlower_attribute;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
@ -143,8 +142,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
||||
|
||||
// Figure out the name of this crate
|
||||
let input = &cx.input;
|
||||
let attrs: Vec<_> = self.attrs.iter().map(|a| unlower_attribute(a)).collect();
|
||||
let name = link::find_crate_name(None, &attrs, input);
|
||||
let name = link::find_crate_name(None, &self.attrs, input);
|
||||
|
||||
// Clean the crate, translating the entire libsyntax AST to one that is
|
||||
// understood by rustdoc.
|
||||
@ -437,21 +435,21 @@ pub enum Attribute {
|
||||
NameValue(String, String)
|
||||
}
|
||||
|
||||
impl Clean<Attribute> for hir::MetaItem {
|
||||
impl Clean<Attribute> for ast::MetaItem {
|
||||
fn clean(&self, cx: &DocContext) -> Attribute {
|
||||
match self.node {
|
||||
hir::MetaWord(ref s) => Word(s.to_string()),
|
||||
hir::MetaList(ref s, ref l) => {
|
||||
ast::MetaWord(ref s) => Word(s.to_string()),
|
||||
ast::MetaList(ref s, ref l) => {
|
||||
List(s.to_string(), l.clean(cx))
|
||||
}
|
||||
hir::MetaNameValue(ref s, ref v) => {
|
||||
ast::MetaNameValue(ref s, ref v) => {
|
||||
NameValue(s.to_string(), lit_to_string(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clean<Attribute> for hir::Attribute {
|
||||
impl Clean<Attribute> for ast::Attribute {
|
||||
fn clean(&self, cx: &DocContext) -> Attribute {
|
||||
self.with_desugared_doc(|a| a.node.value.clean(cx))
|
||||
}
|
||||
@ -475,13 +473,13 @@ impl attr::AttrMetaMethods for Attribute {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<hir::MetaItem>]> { None }
|
||||
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
|
||||
fn span(&self) -> codemap::Span { unimplemented!() }
|
||||
}
|
||||
impl<'a> attr::AttrMetaMethods for &'a Attribute {
|
||||
fn name(&self) -> InternedString { (**self).name() }
|
||||
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
|
||||
fn meta_item_list(&self) -> Option<&[P<hir::MetaItem>]> { None }
|
||||
fn meta_item_list(&self) -> Option<&[P<ast::MetaItem>]> { None }
|
||||
fn span(&self) -> codemap::Span { unimplemented!() }
|
||||
}
|
||||
|
||||
@ -1626,18 +1624,18 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
||||
match self.sty {
|
||||
ty::TyBool => Primitive(Bool),
|
||||
ty::TyChar => Primitive(Char),
|
||||
ty::TyInt(hir::TyIs) => Primitive(Isize),
|
||||
ty::TyInt(hir::TyI8) => Primitive(I8),
|
||||
ty::TyInt(hir::TyI16) => Primitive(I16),
|
||||
ty::TyInt(hir::TyI32) => Primitive(I32),
|
||||
ty::TyInt(hir::TyI64) => Primitive(I64),
|
||||
ty::TyUint(hir::TyUs) => Primitive(Usize),
|
||||
ty::TyUint(hir::TyU8) => Primitive(U8),
|
||||
ty::TyUint(hir::TyU16) => Primitive(U16),
|
||||
ty::TyUint(hir::TyU32) => Primitive(U32),
|
||||
ty::TyUint(hir::TyU64) => Primitive(U64),
|
||||
ty::TyFloat(hir::TyF32) => Primitive(F32),
|
||||
ty::TyFloat(hir::TyF64) => Primitive(F64),
|
||||
ty::TyInt(ast::TyIs) => Primitive(Isize),
|
||||
ty::TyInt(ast::TyI8) => Primitive(I8),
|
||||
ty::TyInt(ast::TyI16) => Primitive(I16),
|
||||
ty::TyInt(ast::TyI32) => Primitive(I32),
|
||||
ty::TyInt(ast::TyI64) => Primitive(I64),
|
||||
ty::TyUint(ast::TyUs) => Primitive(Usize),
|
||||
ty::TyUint(ast::TyU8) => Primitive(U8),
|
||||
ty::TyUint(ast::TyU16) => Primitive(U16),
|
||||
ty::TyUint(ast::TyU32) => Primitive(U32),
|
||||
ty::TyUint(ast::TyU64) => Primitive(U64),
|
||||
ty::TyFloat(ast::TyF32) => Primitive(F32),
|
||||
ty::TyFloat(ast::TyF64) => Primitive(F64),
|
||||
ty::TyStr => Primitive(Str),
|
||||
ty::TyBox(t) => {
|
||||
let box_did = cx.tcx_opt().and_then(|tcx| {
|
||||
@ -2515,11 +2513,11 @@ impl ToSource for syntax::codemap::Span {
|
||||
}
|
||||
}
|
||||
|
||||
fn lit_to_string(lit: &hir::Lit) -> String {
|
||||
fn lit_to_string(lit: &ast::Lit) -> String {
|
||||
match lit.node {
|
||||
hir::LitStr(ref st, _) => st.to_string(),
|
||||
hir::LitByteStr(ref data) => format!("{:?}", data),
|
||||
hir::LitByte(b) => {
|
||||
ast::LitStr(ref st, _) => st.to_string(),
|
||||
ast::LitByteStr(ref data) => format!("{:?}", data),
|
||||
ast::LitByte(b) => {
|
||||
let mut res = String::from("b'");
|
||||
for c in (b as char).escape_default() {
|
||||
res.push(c);
|
||||
@ -2527,11 +2525,11 @@ fn lit_to_string(lit: &hir::Lit) -> String {
|
||||
res.push('\'');
|
||||
res
|
||||
},
|
||||
hir::LitChar(c) => format!("'{}'", c),
|
||||
hir::LitInt(i, _t) => i.to_string(),
|
||||
hir::LitFloat(ref f, _t) => f.to_string(),
|
||||
hir::LitFloatUnsuffixed(ref f) => f.to_string(),
|
||||
hir::LitBool(b) => b.to_string(),
|
||||
ast::LitChar(c) => format!("'{}'", c),
|
||||
ast::LitInt(i, _t) => i.to_string(),
|
||||
ast::LitFloat(ref f, _t) => f.to_string(),
|
||||
ast::LitFloatUnsuffixed(ref f) => f.to_string(),
|
||||
ast::LitBool(b) => b.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -2594,18 +2592,18 @@ fn resolve_type(cx: &DocContext,
|
||||
hir::TyStr => return Primitive(Str),
|
||||
hir::TyBool => return Primitive(Bool),
|
||||
hir::TyChar => return Primitive(Char),
|
||||
hir::TyInt(hir::TyIs) => return Primitive(Isize),
|
||||
hir::TyInt(hir::TyI8) => return Primitive(I8),
|
||||
hir::TyInt(hir::TyI16) => return Primitive(I16),
|
||||
hir::TyInt(hir::TyI32) => return Primitive(I32),
|
||||
hir::TyInt(hir::TyI64) => return Primitive(I64),
|
||||
hir::TyUint(hir::TyUs) => return Primitive(Usize),
|
||||
hir::TyUint(hir::TyU8) => return Primitive(U8),
|
||||
hir::TyUint(hir::TyU16) => return Primitive(U16),
|
||||
hir::TyUint(hir::TyU32) => return Primitive(U32),
|
||||
hir::TyUint(hir::TyU64) => return Primitive(U64),
|
||||
hir::TyFloat(hir::TyF32) => return Primitive(F32),
|
||||
hir::TyFloat(hir::TyF64) => return Primitive(F64),
|
||||
hir::TyInt(ast::TyIs) => return Primitive(Isize),
|
||||
hir::TyInt(ast::TyI8) => return Primitive(I8),
|
||||
hir::TyInt(ast::TyI16) => return Primitive(I16),
|
||||
hir::TyInt(ast::TyI32) => return Primitive(I32),
|
||||
hir::TyInt(ast::TyI64) => return Primitive(I64),
|
||||
hir::TyUint(ast::TyUs) => return Primitive(Usize),
|
||||
hir::TyUint(ast::TyU8) => return Primitive(U8),
|
||||
hir::TyUint(ast::TyU16) => return Primitive(U16),
|
||||
hir::TyUint(ast::TyU32) => return Primitive(U32),
|
||||
hir::TyUint(ast::TyU64) => return Primitive(U64),
|
||||
hir::TyFloat(ast::TyF32) => return Primitive(F32),
|
||||
hir::TyFloat(ast::TyF64) => return Primitive(F64),
|
||||
},
|
||||
def::DefSelfTy(..) if path.segments.len() == 1 => {
|
||||
return Generic(special_idents::type_self.name.to_string());
|
||||
|
@ -18,13 +18,13 @@ use syntax::codemap::Span;
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Ident, NodeId};
|
||||
use syntax::attr;
|
||||
use syntax::ptr::P;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::attr;
|
||||
|
||||
pub struct Module {
|
||||
pub name: Option<Ident>,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub where_outer: Span,
|
||||
pub where_inner: Span,
|
||||
pub extern_crates: Vec<ExternCrate>,
|
||||
@ -100,7 +100,7 @@ pub struct Struct {
|
||||
pub struct_type: StructType,
|
||||
pub name: Ident,
|
||||
pub generics: hir::Generics,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub fields: Vec<hir::StructField>,
|
||||
pub whence: Span,
|
||||
}
|
||||
@ -110,7 +110,7 @@ pub struct Enum {
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub variants: Vec<Variant>,
|
||||
pub generics: hir::Generics,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub id: NodeId,
|
||||
pub whence: Span,
|
||||
pub name: Ident,
|
||||
@ -118,7 +118,7 @@ pub struct Enum {
|
||||
|
||||
pub struct Variant {
|
||||
pub name: Ident,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub kind: hir::VariantKind,
|
||||
pub id: ast::NodeId,
|
||||
pub vis: hir::Visibility,
|
||||
@ -128,7 +128,7 @@ pub struct Variant {
|
||||
|
||||
pub struct Function {
|
||||
pub decl: hir::FnDecl,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub id: NodeId,
|
||||
pub name: Ident,
|
||||
pub vis: hir::Visibility,
|
||||
@ -145,7 +145,7 @@ pub struct Typedef {
|
||||
pub gen: hir::Generics,
|
||||
pub name: Ident,
|
||||
pub id: ast::NodeId,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub whence: Span,
|
||||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
@ -157,7 +157,7 @@ pub struct Static {
|
||||
pub mutability: hir::Mutability,
|
||||
pub expr: P<hir::Expr>,
|
||||
pub name: Ident,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub id: ast::NodeId,
|
||||
@ -168,7 +168,7 @@ pub struct Constant {
|
||||
pub type_: P<hir::Ty>,
|
||||
pub expr: P<hir::Expr>,
|
||||
pub name: Ident,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub id: ast::NodeId,
|
||||
@ -181,7 +181,7 @@ pub struct Trait {
|
||||
pub items: Vec<P<hir::TraitItem>>, //should be TraitItem
|
||||
pub generics: hir::Generics,
|
||||
pub bounds: Vec<hir::TyParamBound>,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub id: ast::NodeId,
|
||||
pub whence: Span,
|
||||
pub vis: hir::Visibility,
|
||||
@ -195,7 +195,7 @@ pub struct Impl {
|
||||
pub trait_: Option<hir::TraitRef>,
|
||||
pub for_: P<hir::Ty>,
|
||||
pub items: Vec<P<hir::ImplItem>>,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub whence: Span,
|
||||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
@ -206,14 +206,14 @@ pub struct DefaultImpl {
|
||||
pub unsafety: hir::Unsafety,
|
||||
pub trait_: hir::TraitRef,
|
||||
pub id: ast::NodeId,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub whence: Span,
|
||||
}
|
||||
|
||||
pub struct Macro {
|
||||
pub name: Ident,
|
||||
pub id: ast::NodeId,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub whence: Span,
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub imported_from: Option<Ident>,
|
||||
@ -223,14 +223,14 @@ pub struct ExternCrate {
|
||||
pub name: Ident,
|
||||
pub path: Option<String>,
|
||||
pub vis: hir::Visibility,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub whence: Span,
|
||||
}
|
||||
|
||||
pub struct Import {
|
||||
pub id: NodeId,
|
||||
pub vis: hir::Visibility,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub node: hir::ViewPath_,
|
||||
pub whence: Span,
|
||||
}
|
||||
|
@ -52,10 +52,10 @@ use std::sync::Arc;
|
||||
use externalfiles::ExternalHtml;
|
||||
|
||||
use serialize::json::{self, ToJson};
|
||||
use syntax::{abi, ast};
|
||||
use syntax::{abi, ast, attr};
|
||||
use rustc::middle::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::util::nodemap::NodeSet;
|
||||
use rustc_front::{hir, attr};
|
||||
use rustc_front::hir;
|
||||
|
||||
use clean::{self, SelfTy};
|
||||
use doctree;
|
||||
|
@ -124,8 +124,8 @@ pub fn run(input: &str,
|
||||
|
||||
// Look for #![doc(test(no_crate_inject))], used by crates in the std facade
|
||||
fn scrape_test_config(krate: &::rustc_front::hir::Crate) -> TestOptions {
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use rustc_front::print::pprust;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::print::pprust;
|
||||
|
||||
let mut opts = TestOptions {
|
||||
no_crate_inject: false,
|
||||
|
@ -16,14 +16,14 @@ use std::mem;
|
||||
|
||||
use syntax::abi;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use rustc::front::map as hir_map;
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::stability;
|
||||
|
||||
use rustc_front::attr;
|
||||
use rustc_front::attr::AttrMetaMethods;
|
||||
use rustc_front::hir;
|
||||
|
||||
use core;
|
||||
@ -39,7 +39,7 @@ use doctree::*;
|
||||
|
||||
pub struct RustdocVisitor<'a, 'tcx: 'a> {
|
||||
pub module: Module,
|
||||
pub attrs: Vec<hir::Attribute>,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub cx: &'a core::DocContext<'a, 'tcx>,
|
||||
pub analysis: Option<&'a core::CrateAnalysis>,
|
||||
view_item_stack: HashSet<ast::NodeId>,
|
||||
@ -146,7 +146,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_mod_contents(&mut self, span: Span, attrs: Vec<hir::Attribute> ,
|
||||
pub fn visit_mod_contents(&mut self, span: Span, attrs: Vec<ast::Attribute> ,
|
||||
vis: hir::Visibility, id: ast::NodeId,
|
||||
m: &hir::Mod,
|
||||
name: Option<ast::Ident>) -> Module {
|
||||
|
@ -54,8 +54,8 @@ impl PpAnn for NoAnn {}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct CurrentCommentAndLiteral {
|
||||
cur_cmnt: usize,
|
||||
cur_lit: usize,
|
||||
pub cur_cmnt: usize,
|
||||
pub cur_lit: usize,
|
||||
}
|
||||
|
||||
pub struct State<'a> {
|
||||
@ -450,26 +450,361 @@ fn needs_parentheses(expr: &ast::Expr) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> State<'a> {
|
||||
pub fn ibox(&mut self, u: usize) -> io::Result<()> {
|
||||
self.boxes.push(pp::Breaks::Inconsistent);
|
||||
pp::ibox(&mut self.s, u)
|
||||
pub trait PrintState<'a> {
|
||||
fn writer(&mut self) -> &mut pp::Printer<'a>;
|
||||
fn boxes(&mut self) -> &mut Vec<pp::Breaks>;
|
||||
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>>;
|
||||
fn cur_cmnt_and_lit(&mut self) -> &mut CurrentCommentAndLiteral;
|
||||
fn literals(&self) -> &Option<Vec<comments::Literal>>;
|
||||
|
||||
fn word_space(&mut self, w: &str) -> io::Result<()> {
|
||||
try!(word(self.writer(), w));
|
||||
space(self.writer())
|
||||
}
|
||||
|
||||
pub fn end(&mut self) -> io::Result<()> {
|
||||
self.boxes.pop().unwrap();
|
||||
pp::end(&mut self.s)
|
||||
fn popen(&mut self) -> io::Result<()> { word(self.writer(), "(") }
|
||||
|
||||
fn pclose(&mut self) -> io::Result<()> { word(self.writer(), ")") }
|
||||
|
||||
fn is_begin(&mut self) -> bool {
|
||||
match self.writer().last_token() {
|
||||
pp::Token::Begin(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cbox(&mut self, u: usize) -> io::Result<()> {
|
||||
self.boxes.push(pp::Breaks::Consistent);
|
||||
pp::cbox(&mut self.s, u)
|
||||
fn is_end(&mut self) -> bool {
|
||||
match self.writer().last_token() {
|
||||
pp::Token::End => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// is this the beginning of a line?
|
||||
fn is_bol(&mut self) -> bool {
|
||||
self.writer().last_token().is_eof() || self.writer().last_token().is_hardbreak_tok()
|
||||
}
|
||||
|
||||
fn hardbreak_if_not_bol(&mut self) -> io::Result<()> {
|
||||
if !self.is_bol() {
|
||||
try!(hardbreak(self.writer()))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// "raw box"
|
||||
pub fn rbox(&mut self, u: usize, b: pp::Breaks) -> io::Result<()> {
|
||||
self.boxes.push(b);
|
||||
pp::rbox(&mut self.s, u, b)
|
||||
fn rbox(&mut self, u: usize, b: pp::Breaks) -> io::Result<()> {
|
||||
self.boxes().push(b);
|
||||
pp::rbox(self.writer(), u, b)
|
||||
}
|
||||
|
||||
fn ibox(&mut self, u: usize) -> io::Result<()> {
|
||||
self.boxes().push(pp::Breaks::Inconsistent);
|
||||
pp::ibox(self.writer(), u)
|
||||
}
|
||||
|
||||
fn end(&mut self) -> io::Result<()> {
|
||||
self.boxes().pop().unwrap();
|
||||
pp::end(self.writer())
|
||||
}
|
||||
|
||||
fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> io::Result<()>
|
||||
where F: FnMut(&mut Self, &T) -> io::Result<()>,
|
||||
{
|
||||
try!(self.rbox(0, b));
|
||||
let mut first = true;
|
||||
for elt in elts {
|
||||
if first { first = false; } else { try!(self.word_space(",")); }
|
||||
try!(op(self, elt));
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
|
||||
|
||||
fn next_lit(&mut self, pos: BytePos) -> Option<comments::Literal> {
|
||||
let mut cur_lit = self.cur_cmnt_and_lit().cur_lit;
|
||||
|
||||
let mut result = None;
|
||||
|
||||
if let &Some(ref lits) = self.literals()
|
||||
{
|
||||
while cur_lit < lits.len() {
|
||||
let ltrl = (*lits)[cur_lit].clone();
|
||||
if ltrl.pos > pos { break; }
|
||||
cur_lit += 1;
|
||||
if ltrl.pos == pos {
|
||||
result = Some(ltrl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.cur_cmnt_and_lit().cur_lit = cur_lit;
|
||||
result
|
||||
}
|
||||
|
||||
fn maybe_print_comment(&mut self, pos: BytePos) -> io::Result<()> {
|
||||
loop {
|
||||
match self.next_comment() {
|
||||
Some(ref cmnt) => {
|
||||
if (*cmnt).pos < pos {
|
||||
try!(self.print_comment(cmnt));
|
||||
self.cur_cmnt_and_lit().cur_cmnt += 1;
|
||||
} else { break; }
|
||||
}
|
||||
_ => break
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_comment(&mut self,
|
||||
cmnt: &comments::Comment) -> io::Result<()> {
|
||||
match cmnt.style {
|
||||
comments::Mixed => {
|
||||
assert_eq!(cmnt.lines.len(), 1);
|
||||
try!(zerobreak(self.writer()));
|
||||
try!(word(self.writer(), &cmnt.lines[0]));
|
||||
zerobreak(self.writer())
|
||||
}
|
||||
comments::Isolated => {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
for line in &cmnt.lines {
|
||||
// Don't print empty lines because they will end up as trailing
|
||||
// whitespace
|
||||
if !line.is_empty() {
|
||||
try!(word(self.writer(), &line[..]));
|
||||
}
|
||||
try!(hardbreak(self.writer()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
comments::Trailing => {
|
||||
try!(word(self.writer(), " "));
|
||||
if cmnt.lines.len() == 1 {
|
||||
try!(word(self.writer(), &cmnt.lines[0]));
|
||||
hardbreak(self.writer())
|
||||
} else {
|
||||
try!(self.ibox(0));
|
||||
for line in &cmnt.lines {
|
||||
if !line.is_empty() {
|
||||
try!(word(self.writer(), &line[..]));
|
||||
}
|
||||
try!(hardbreak(self.writer()));
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
}
|
||||
comments::BlankLine => {
|
||||
// We need to do at least one, possibly two hardbreaks.
|
||||
let is_semi = match self.writer().last_token() {
|
||||
pp::Token::String(s, _) => ";" == s,
|
||||
_ => false
|
||||
};
|
||||
if is_semi || self.is_begin() || self.is_end() {
|
||||
try!(hardbreak(self.writer()));
|
||||
}
|
||||
hardbreak(self.writer())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn next_comment(&mut self) -> Option<comments::Comment> {
|
||||
let cur_cmnt = self.cur_cmnt_and_lit().cur_cmnt;
|
||||
match *self.comments() {
|
||||
Some(ref cmnts) => {
|
||||
if cur_cmnt < cmnts.len() {
|
||||
Some(cmnts[cur_cmnt].clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> {
|
||||
try!(self.maybe_print_comment(lit.span.lo));
|
||||
match self.next_lit(lit.span.lo) {
|
||||
Some(ref ltrl) => {
|
||||
return word(self.writer(), &(*ltrl).lit);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
match lit.node {
|
||||
ast::LitStr(ref st, style) => self.print_string(&st, style),
|
||||
ast::LitByte(byte) => {
|
||||
let mut res = String::from("b'");
|
||||
res.extend(ascii::escape_default(byte).map(|c| c as char));
|
||||
res.push('\'');
|
||||
word(self.writer(), &res[..])
|
||||
}
|
||||
ast::LitChar(ch) => {
|
||||
let mut res = String::from("'");
|
||||
res.extend(ch.escape_default());
|
||||
res.push('\'');
|
||||
word(self.writer(), &res[..])
|
||||
}
|
||||
ast::LitInt(i, t) => {
|
||||
match t {
|
||||
ast::SignedIntLit(st, ast::Plus) => {
|
||||
word(self.writer(),
|
||||
&ast_util::int_ty_to_string(st, Some(i as i64)))
|
||||
}
|
||||
ast::SignedIntLit(st, ast::Minus) => {
|
||||
let istr = ast_util::int_ty_to_string(st, Some(-(i as i64)));
|
||||
word(self.writer(),
|
||||
&format!("-{}", istr))
|
||||
}
|
||||
ast::UnsignedIntLit(ut) => {
|
||||
word(self.writer(), &ast_util::uint_ty_to_string(ut, Some(i)))
|
||||
}
|
||||
ast::UnsuffixedIntLit(ast::Plus) => {
|
||||
word(self.writer(), &format!("{}", i))
|
||||
}
|
||||
ast::UnsuffixedIntLit(ast::Minus) => {
|
||||
word(self.writer(), &format!("-{}", i))
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::LitFloat(ref f, t) => {
|
||||
word(self.writer(),
|
||||
&format!(
|
||||
"{}{}",
|
||||
&f,
|
||||
&ast_util::float_ty_to_string(t)))
|
||||
}
|
||||
ast::LitFloatUnsuffixed(ref f) => word(self.writer(), &f[..]),
|
||||
ast::LitBool(val) => {
|
||||
if val { word(self.writer(), "true") } else { word(self.writer(), "false") }
|
||||
}
|
||||
ast::LitByteStr(ref v) => {
|
||||
let mut escaped: String = String::new();
|
||||
for &ch in v.iter() {
|
||||
escaped.extend(ascii::escape_default(ch)
|
||||
.map(|c| c as char));
|
||||
}
|
||||
word(self.writer(), &format!("b\"{}\"", escaped))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn print_string(&mut self, st: &str,
|
||||
style: ast::StrStyle) -> io::Result<()> {
|
||||
let st = match style {
|
||||
ast::CookedStr => {
|
||||
(format!("\"{}\"", st.escape_default()))
|
||||
}
|
||||
ast::RawStr(n) => {
|
||||
(format!("r{delim}\"{string}\"{delim}",
|
||||
delim=repeat("#", n),
|
||||
string=st))
|
||||
}
|
||||
};
|
||||
word(self.writer(), &st[..])
|
||||
}
|
||||
|
||||
fn print_inner_attributes(&mut self,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
ast::AttrInner => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
_ => {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_outer_attributes(&mut self,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
ast::AttrOuter => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
_ => {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_attribute(&mut self, attr: &ast::Attribute) -> io::Result<()> {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(attr.span.lo));
|
||||
if attr.node.is_sugared_doc {
|
||||
word(self.writer(), &attr.value_str().unwrap())
|
||||
} else {
|
||||
match attr.node.style {
|
||||
ast::AttrInner => try!(word(self.writer(), "#![")),
|
||||
ast::AttrOuter => try!(word(self.writer(), "#[")),
|
||||
}
|
||||
try!(self.print_meta_item(&*attr.meta()));
|
||||
word(self.writer(), "]")
|
||||
}
|
||||
}
|
||||
|
||||
fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> {
|
||||
try!(self.ibox(indent_unit));
|
||||
match item.node {
|
||||
ast::MetaWord(ref name) => {
|
||||
try!(word(self.writer(), &name));
|
||||
}
|
||||
ast::MetaNameValue(ref name, ref value) => {
|
||||
try!(self.word_space(&name[..]));
|
||||
try!(self.word_space("="));
|
||||
try!(self.print_literal(value));
|
||||
}
|
||||
ast::MetaList(ref name, ref items) => {
|
||||
try!(word(self.writer(), &name));
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Consistent,
|
||||
&items[..],
|
||||
|s, i| s.print_meta_item(&**i)));
|
||||
try!(self.pclose());
|
||||
}
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PrintState<'a> for State<'a> {
|
||||
fn writer(&mut self) -> &mut pp::Printer<'a> {
|
||||
&mut self.s
|
||||
}
|
||||
|
||||
fn boxes(&mut self) -> &mut Vec<pp::Breaks> {
|
||||
&mut self.boxes
|
||||
}
|
||||
|
||||
fn comments(&mut self) -> &mut Option<Vec<comments::Comment>> {
|
||||
&mut self.comments
|
||||
}
|
||||
|
||||
fn cur_cmnt_and_lit(&mut self) -> &mut CurrentCommentAndLiteral {
|
||||
&mut self.cur_cmnt_and_lit
|
||||
}
|
||||
|
||||
fn literals(&self) -> &Option<Vec<comments::Literal>> {
|
||||
&self.literals
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> State<'a> {
|
||||
pub fn cbox(&mut self, u: usize) -> io::Result<()> {
|
||||
self.boxes.push(pp::Breaks::Consistent);
|
||||
pp::cbox(&mut self.s, u)
|
||||
}
|
||||
|
||||
pub fn nbsp(&mut self) -> io::Result<()> { word(&mut self.s, " ") }
|
||||
@ -479,15 +814,6 @@ impl<'a> State<'a> {
|
||||
self.nbsp()
|
||||
}
|
||||
|
||||
pub fn word_space(&mut self, w: &str) -> io::Result<()> {
|
||||
try!(word(&mut self.s, w));
|
||||
space(&mut self.s)
|
||||
}
|
||||
|
||||
pub fn popen(&mut self) -> io::Result<()> { word(&mut self.s, "(") }
|
||||
|
||||
pub fn pclose(&mut self) -> io::Result<()> { word(&mut self.s, ")") }
|
||||
|
||||
pub fn head(&mut self, w: &str) -> io::Result<()> {
|
||||
// outer-box is consistent
|
||||
try!(self.cbox(indent_unit));
|
||||
@ -523,25 +849,6 @@ impl<'a> State<'a> {
|
||||
self.bclose_(span, indent_unit)
|
||||
}
|
||||
|
||||
pub fn is_begin(&mut self) -> bool {
|
||||
match self.s.last_token() {
|
||||
pp::Token::Begin(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_end(&mut self) -> bool {
|
||||
match self.s.last_token() {
|
||||
pp::Token::End => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
// is this the beginning of a line?
|
||||
pub fn is_bol(&mut self) -> bool {
|
||||
self.s.last_token().is_eof() || self.s.last_token().is_hardbreak_tok()
|
||||
}
|
||||
|
||||
pub fn in_cbox(&self) -> bool {
|
||||
match self.boxes.last() {
|
||||
Some(&last_box) => last_box == pp::Breaks::Consistent,
|
||||
@ -549,12 +856,6 @@ impl<'a> State<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn hardbreak_if_not_bol(&mut self) -> io::Result<()> {
|
||||
if !self.is_bol() {
|
||||
try!(hardbreak(&mut self.s))
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn space_if_not_bol(&mut self) -> io::Result<()> {
|
||||
if !self.is_bol() { try!(space(&mut self.s)); }
|
||||
Ok(())
|
||||
@ -584,17 +885,6 @@ impl<'a> State<'a> {
|
||||
word(&mut self.s, "*/")
|
||||
}
|
||||
|
||||
pub fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> io::Result<()> where
|
||||
F: FnMut(&mut State, &T) -> io::Result<()>,
|
||||
{
|
||||
try!(self.rbox(0, b));
|
||||
let mut first = true;
|
||||
for elt in elts {
|
||||
if first { first = false; } else { try!(self.word_space(",")); }
|
||||
try!(op(self, elt));
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
|
||||
|
||||
pub fn commasep_cmnt<T, F, G>(&mut self,
|
||||
@ -1326,58 +1616,6 @@ impl<'a> State<'a> {
|
||||
self.ann.post(self, NodeSubItem(ii.id))
|
||||
}
|
||||
|
||||
pub fn print_outer_attributes(&mut self,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
ast::AttrOuter => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
_ => {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_inner_attributes(&mut self,
|
||||
attrs: &[ast::Attribute]) -> io::Result<()> {
|
||||
let mut count = 0;
|
||||
for attr in attrs {
|
||||
match attr.node.style {
|
||||
ast::AttrInner => {
|
||||
try!(self.print_attribute(attr));
|
||||
count += 1;
|
||||
}
|
||||
_ => {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_attribute(&mut self, attr: &ast::Attribute) -> io::Result<()> {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(attr.span.lo));
|
||||
if attr.node.is_sugared_doc {
|
||||
word(&mut self.s, &attr.value_str().unwrap())
|
||||
} else {
|
||||
match attr.node.style {
|
||||
ast::AttrInner => try!(word(&mut self.s, "#![")),
|
||||
ast::AttrOuter => try!(word(&mut self.s, "#[")),
|
||||
}
|
||||
try!(self.print_meta_item(&*attr.meta()));
|
||||
word(&mut self.s, "]")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> {
|
||||
try!(self.maybe_print_comment(st.span.lo));
|
||||
match st.node {
|
||||
@ -2620,29 +2858,6 @@ impl<'a> State<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> {
|
||||
try!(self.ibox(indent_unit));
|
||||
match item.node {
|
||||
ast::MetaWord(ref name) => {
|
||||
try!(word(&mut self.s, &name));
|
||||
}
|
||||
ast::MetaNameValue(ref name, ref value) => {
|
||||
try!(self.word_space(&name[..]));
|
||||
try!(self.word_space("="));
|
||||
try!(self.print_literal(value));
|
||||
}
|
||||
ast::MetaList(ref name, ref items) => {
|
||||
try!(word(&mut self.s, &name));
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Consistent,
|
||||
&items[..],
|
||||
|s, i| s.print_meta_item(&**i)));
|
||||
try!(self.pclose());
|
||||
}
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
|
||||
pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> io::Result<()> {
|
||||
match vp.node {
|
||||
ast::ViewPathSimple(ident, ref path) => {
|
||||
@ -2832,181 +3047,6 @@ impl<'a> State<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> {
|
||||
try!(self.maybe_print_comment(lit.span.lo));
|
||||
match self.next_lit(lit.span.lo) {
|
||||
Some(ref ltrl) => {
|
||||
return word(&mut self.s, &(*ltrl).lit);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
match lit.node {
|
||||
ast::LitStr(ref st, style) => self.print_string(&st, style),
|
||||
ast::LitByte(byte) => {
|
||||
let mut res = String::from("b'");
|
||||
res.extend(ascii::escape_default(byte).map(|c| c as char));
|
||||
res.push('\'');
|
||||
word(&mut self.s, &res[..])
|
||||
}
|
||||
ast::LitChar(ch) => {
|
||||
let mut res = String::from("'");
|
||||
res.extend(ch.escape_default());
|
||||
res.push('\'');
|
||||
word(&mut self.s, &res[..])
|
||||
}
|
||||
ast::LitInt(i, t) => {
|
||||
match t {
|
||||
ast::SignedIntLit(st, ast::Plus) => {
|
||||
word(&mut self.s,
|
||||
&ast_util::int_ty_to_string(st, Some(i as i64)))
|
||||
}
|
||||
ast::SignedIntLit(st, ast::Minus) => {
|
||||
let istr = ast_util::int_ty_to_string(st, Some(-(i as i64)));
|
||||
word(&mut self.s,
|
||||
&format!("-{}", istr))
|
||||
}
|
||||
ast::UnsignedIntLit(ut) => {
|
||||
word(&mut self.s, &ast_util::uint_ty_to_string(ut, Some(i)))
|
||||
}
|
||||
ast::UnsuffixedIntLit(ast::Plus) => {
|
||||
word(&mut self.s, &format!("{}", i))
|
||||
}
|
||||
ast::UnsuffixedIntLit(ast::Minus) => {
|
||||
word(&mut self.s, &format!("-{}", i))
|
||||
}
|
||||
}
|
||||
}
|
||||
ast::LitFloat(ref f, t) => {
|
||||
word(&mut self.s,
|
||||
&format!(
|
||||
"{}{}",
|
||||
&f,
|
||||
&ast_util::float_ty_to_string(t)))
|
||||
}
|
||||
ast::LitFloatUnsuffixed(ref f) => word(&mut self.s, &f[..]),
|
||||
ast::LitBool(val) => {
|
||||
if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") }
|
||||
}
|
||||
ast::LitByteStr(ref v) => {
|
||||
let mut escaped: String = String::new();
|
||||
for &ch in v.iter() {
|
||||
escaped.extend(ascii::escape_default(ch)
|
||||
.map(|c| c as char));
|
||||
}
|
||||
word(&mut self.s, &format!("b\"{}\"", escaped))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_lit(&mut self, pos: BytePos) -> Option<comments::Literal> {
|
||||
match self.literals {
|
||||
Some(ref lits) => {
|
||||
while self.cur_cmnt_and_lit.cur_lit < lits.len() {
|
||||
let ltrl = (*lits)[self.cur_cmnt_and_lit.cur_lit].clone();
|
||||
if ltrl.pos > pos { return None; }
|
||||
self.cur_cmnt_and_lit.cur_lit += 1;
|
||||
if ltrl.pos == pos { return Some(ltrl); }
|
||||
}
|
||||
None
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_print_comment(&mut self, pos: BytePos) -> io::Result<()> {
|
||||
loop {
|
||||
match self.next_comment() {
|
||||
Some(ref cmnt) => {
|
||||
if (*cmnt).pos < pos {
|
||||
try!(self.print_comment(cmnt));
|
||||
self.cur_cmnt_and_lit.cur_cmnt += 1;
|
||||
} else { break; }
|
||||
}
|
||||
_ => break
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn print_comment(&mut self,
|
||||
cmnt: &comments::Comment) -> io::Result<()> {
|
||||
match cmnt.style {
|
||||
comments::Mixed => {
|
||||
assert_eq!(cmnt.lines.len(), 1);
|
||||
try!(zerobreak(&mut self.s));
|
||||
try!(word(&mut self.s, &cmnt.lines[0]));
|
||||
zerobreak(&mut self.s)
|
||||
}
|
||||
comments::Isolated => {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
for line in &cmnt.lines {
|
||||
// Don't print empty lines because they will end up as trailing
|
||||
// whitespace
|
||||
if !line.is_empty() {
|
||||
try!(word(&mut self.s, &line[..]));
|
||||
}
|
||||
try!(hardbreak(&mut self.s));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
comments::Trailing => {
|
||||
try!(word(&mut self.s, " "));
|
||||
if cmnt.lines.len() == 1 {
|
||||
try!(word(&mut self.s, &cmnt.lines[0]));
|
||||
hardbreak(&mut self.s)
|
||||
} else {
|
||||
try!(self.ibox(0));
|
||||
for line in &cmnt.lines {
|
||||
if !line.is_empty() {
|
||||
try!(word(&mut self.s, &line[..]));
|
||||
}
|
||||
try!(hardbreak(&mut self.s));
|
||||
}
|
||||
self.end()
|
||||
}
|
||||
}
|
||||
comments::BlankLine => {
|
||||
// We need to do at least one, possibly two hardbreaks.
|
||||
let is_semi = match self.s.last_token() {
|
||||
pp::Token::String(s, _) => ";" == s,
|
||||
_ => false
|
||||
};
|
||||
if is_semi || self.is_begin() || self.is_end() {
|
||||
try!(hardbreak(&mut self.s));
|
||||
}
|
||||
hardbreak(&mut self.s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_string(&mut self, st: &str,
|
||||
style: ast::StrStyle) -> io::Result<()> {
|
||||
let st = match style {
|
||||
ast::CookedStr => {
|
||||
(format!("\"{}\"", st.escape_default()))
|
||||
}
|
||||
ast::RawStr(n) => {
|
||||
(format!("r{delim}\"{string}\"{delim}",
|
||||
delim=repeat("#", n),
|
||||
string=st))
|
||||
}
|
||||
};
|
||||
word(&mut self.s, &st[..])
|
||||
}
|
||||
|
||||
pub fn next_comment(&mut self) -> Option<comments::Comment> {
|
||||
match self.comments {
|
||||
Some(ref cmnts) => {
|
||||
if self.cur_cmnt_and_lit.cur_cmnt < cmnts.len() {
|
||||
Some(cmnts[self.cur_cmnt_and_lit.cur_cmnt].clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_opt_abi_and_extern_if_nondefault(&mut self,
|
||||
opt_abi: Option<abi::Abi>)
|
||||
-> io::Result<()> {
|
||||
|
@ -15,10 +15,12 @@
|
||||
|
||||
#[macro_use] extern crate rustc;
|
||||
extern crate rustc_front;
|
||||
extern crate syntax;
|
||||
|
||||
use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
|
||||
use rustc::plugin::Registry;
|
||||
use rustc_front::{hir, attr};
|
||||
use rustc_front::hir;
|
||||
use syntax::attr;
|
||||
|
||||
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user