Skip to content

Commit

Permalink
Replace Name and Symbol with Spanned<Name> and Spanned<Symbol>
Browse files Browse the repository at this point in the history
As per nagisa's review comment. WIP.
  • Loading branch information
estebank committed Dec 17, 2016
1 parent 3e1608c commit 8a383b1
Show file tree
Hide file tree
Showing 43 changed files with 254 additions and 207 deletions.
10 changes: 7 additions & 3 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)

pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_vis(&item.vis);
visitor.visit_name(item.span, item.name);
visitor.visit_name(item.span, item.name.node);
match item.node {
ItemExternCrate(opt_name) => {
visitor.visit_id(item.id);
Expand All @@ -428,7 +428,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_expr(expr);
}
ItemFn(ref declaration, unsafety, constness, abi, ref generics, body_id) => {
visitor.visit_fn(FnKind::ItemFn(item.name,
visitor.visit_fn(FnKind::ItemFn(item.name.node,
generics,
unsafety,
constness,
Expand Down Expand Up @@ -475,7 +475,11 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
ItemUnion(ref struct_definition, ref generics) => {
visitor.visit_generics(generics);
visitor.visit_id(item.id);
visitor.visit_variant_data(struct_definition, item.name, generics, item.id, item.span);
visitor.visit_variant_data(struct_definition,
item.name.node,
generics,
item.id,
item.span);
}
ItemTrait(_, ref generics, ref bounds, ref methods) => {
visitor.visit_id(item.id);
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use std::mem;
use syntax::ast::*;
use syntax::errors;
use syntax::ptr::P;
use syntax::codemap::{self, respan, Spanned};
use syntax::codemap::{self, dummy_spanned, respan, Spanned};
use syntax::std_inject;
use syntax::symbol::{Symbol, keywords};
use syntax::util::small_vector::SmallVector;
Expand Down Expand Up @@ -314,7 +314,7 @@ impl<'a> LoweringContext<'a> {
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
Spanned {
node: hir::Variant_ {
name: v.node.name.name,
name: v.node.name.node.name,
attrs: self.lower_attrs(&v.node.attrs),
data: self.lower_variant_data(&v.node.data),
disr_expr: v.node.disr_expr.as_ref().map(|e| P(self.lower_expr(e))),
Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'a> LoweringContext<'a> {
path.span = span;
self.items.insert(import.id, hir::Item {
id: import.id,
name: import.rename.unwrap_or(ident).name,
name: dummy_spanned(import.rename.unwrap_or(ident).name),
attrs: attrs.clone(),
node: hir::ItemUse(P(path), hir::UseKind::Single),
vis: vis.clone(),
Expand Down Expand Up @@ -900,7 +900,7 @@ impl<'a> LoweringContext<'a> {
self.with_parent_def(i.id, |this| {
hir::TraitItem {
id: i.id,
name: i.ident.name,
name: i.ident.node.name,
attrs: this.lower_attrs(&i.attrs),
node: match i.node {
TraitItemKind::Const(ref ty, ref default) => {
Expand Down Expand Up @@ -930,7 +930,7 @@ impl<'a> LoweringContext<'a> {
self.with_parent_def(i.id, |this| {
hir::ImplItem {
id: i.id,
name: i.ident.name,
name: i.ident.node.name,
attrs: this.lower_attrs(&i.attrs),
vis: this.lower_visibility(&i.vis),
defaultness: this.lower_defaultness(i.defaultness, true /* [1] */),
Expand All @@ -957,7 +957,7 @@ impl<'a> LoweringContext<'a> {
fn lower_impl_item_ref(&mut self, i: &ImplItem) -> hir::ImplItemRef {
hir::ImplItemRef {
id: hir::ImplItemId { node_id: i.id },
name: i.ident.name,
name: i.ident.node.name,
span: i.span,
vis: self.lower_visibility(&i.vis),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
Expand Down Expand Up @@ -1004,11 +1004,11 @@ impl<'a> LoweringContext<'a> {
}

pub fn lower_item(&mut self, i: &Item) -> hir::Item {
let mut name = i.ident.name;
let mut name = i.spanned_symbol();
let attrs = self.lower_attrs(&i.attrs);
let mut vis = self.lower_visibility(&i.vis);
let node = self.with_parent_def(i.id, |this| {
this.lower_item_kind(i.id, &mut name, &attrs, &mut vis, &i.node)
this.lower_item_kind(i.id, &mut name.node, &attrs, &mut vis, &i.node)
});

hir::Item {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use hir::{Expr, FnDecl};
use hir::intravisit::FnKind;
use syntax::abi;
use syntax::ast::{Attribute, Name, NodeId};
use syntax::codemap::Spanned;
use syntax_pos::Span;

/// An FnLikeNode is a Node that is like a fn, in that it has a decl
Expand Down Expand Up @@ -108,7 +109,7 @@ impl<'a> Code<'a> {
/// These are all the components one can extract from a fn item for
/// use when implementing FnLikeNode operations.
struct ItemFnParts<'a> {
name: Name,
name: Spanned<Name>,
decl: &'a ast::FnDecl,
unsafety: ast::Unsafety,
constness: ast::Constness,
Expand Down Expand Up @@ -210,7 +211,7 @@ impl<'a> FnLikeNode<'a> {

pub fn kind(self) -> FnKind<'a> {
let item = |p: ItemFnParts<'a>| -> FnKind<'a> {
FnKind::ItemFn(p.name, p.generics, p.unsafety, p.constness, p.abi, p.vis, p.attrs)
FnKind::ItemFn(p.name.node, p.generics, p.unsafety, p.constness, p.abi, p.vis, p.attrs)
};
let closure = |c: ClosureParts<'a>| {
FnKind::Closure(c.attrs)
Expand Down
26 changes: 13 additions & 13 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
DefPathData::Impl,
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
DefPathData::TypeNs(i.ident.name.as_str()),
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
DefPathData::TypeNs(i.ident.node.name.as_str()),
ItemKind::Mod(..) if i.ident.node == keywords::Invalid.ident() => {
return visit::walk_item(self, i);
}
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
ItemKind::Mod(..) => DefPathData::Module(i.ident.node.name.as_str()),
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
DefPathData::ValueNs(i.ident.name.as_str()),
DefPathData::ValueNs(i.ident.node.name.as_str()),
ItemKind::Mac(..) if i.id == DUMMY_NODE_ID => return, // Scope placeholder
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id, false),
ItemKind::Use(ref view_path) => {
Expand All @@ -176,9 +176,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
match i.node {
ItemKind::Enum(ref enum_definition, _) => {
for v in &enum_definition.variants {
let variant_def_index =
this.create_def(v.node.data.id(),
DefPathData::EnumVariant(v.node.name.name.as_str()));
let variant_def_index = this.create_def(
v.node.data.id(),
DefPathData::EnumVariant(v.node.name.node.name.as_str()));
this.with_parent(variant_def_index, |this| {
for (index, field) in v.node.data.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
Expand Down Expand Up @@ -231,8 +231,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
let def_data = match ti.node {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.name.as_str()),
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
DefPathData::ValueNs(ti.ident.node.name.as_str()),
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.node.name.as_str()),
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id, false),
};

Expand All @@ -249,8 +249,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
let def_data = match ii.node {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.name.as_str()),
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
DefPathData::ValueNs(ii.ident.node.name.as_str()),
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.node.name.as_str()),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id, false),
};

Expand Down Expand Up @@ -349,9 +349,9 @@ impl<'ast> Visitor<'ast> for DefCollector<'ast> {
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) |
hir::ItemTrait(..) | hir::ItemExternCrate(..) | hir::ItemMod(..) |
hir::ItemForeignMod(..) | hir::ItemTy(..) =>
DefPathData::TypeNs(i.name.as_str()),
DefPathData::TypeNs(i.name.node.as_str()),
hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) =>
DefPathData::ValueNs(i.name.as_str()),
DefPathData::ValueNs(i.name.node.as_str()),
hir::ItemUse(..) => DefPathData::Misc,
};
let def = self.create_def(i.id, def_data);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ impl<'ast> Map<'ast> {
/// Returns the name associated with the given NodeId's AST.
pub fn name(&self, id: NodeId) -> Name {
match self.get(id) {
NodeItem(i) => i.name,
NodeItem(i) => i.name.node,
NodeForeignItem(i) => i.name,
NodeImplItem(ii) => ii.name,
NodeTraitItem(ti) => ti.name,
Expand Down Expand Up @@ -764,7 +764,7 @@ impl<'ast> Map<'ast> {
pub fn span(&self, id: NodeId) -> Span {
self.read(id); // reveals span from node
match self.find_entry(id) {
Some(EntryItem(_, item)) => item.span,
Some(EntryItem(_, item)) => item.name.span,
Some(EntryForeignItem(_, foreign_item)) => foreign_item.span,
Some(EntryTraitItem(_, trait_method)) => trait_method.span,
Some(EntryImplItem(_, impl_item)) => impl_item.span,
Expand Down Expand Up @@ -843,7 +843,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
match map.find(id) {
None => return None,
Some(NodeItem(item)) if item_is_mod(&item) =>
return Some((id, item.name)),
return Some((id, item.name.node)),
_ => {}
}
let parent = map.get_parent(id);
Expand Down Expand Up @@ -899,7 +899,7 @@ trait Named {

impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } }

impl Named for Item { fn name(&self) -> Name { self.name } }
impl Named for Item { fn name(&self) -> Name { self.name.node } }
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
impl Named for StructField { fn name(&self) -> Name { self.name } }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ pub struct ItemId {
/// The name might be a dummy name in case of anonymous items
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Item {
pub name: Name,
pub name: Spanned<Name>,
pub attrs: HirVec<Attribute>,
pub id: NodeId,
pub node: Item_,
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl<'a> State<'a> {
word(&mut self.s, "as")?;
space(&mut self.s)?;
}
self.print_name(item.name)?;
self.print_name(item.name.node)?;
word(&mut self.s, ";")?;
self.end()?; // end inner head-block
self.end()?; // end outer head-block
Expand All @@ -684,10 +684,10 @@ impl<'a> State<'a> {

match kind {
hir::UseKind::Single => {
if path.segments.last().unwrap().name != item.name {
if path.segments.last().unwrap().name != item.name.node {
space(&mut self.s)?;
self.word_space("as")?;
self.print_name(item.name)?;
self.print_name(item.name.node)?;
}
word(&mut self.s, ";")?;
}
Expand All @@ -702,7 +702,7 @@ impl<'a> State<'a> {
if m == hir::MutMutable {
self.word_space("mut")?;
}
self.print_name(item.name)?;
self.print_name(item.name.node)?;
self.word_space(":")?;
self.print_type(&ty)?;
space(&mut self.s)?;
Expand All @@ -715,7 +715,7 @@ impl<'a> State<'a> {
}
hir::ItemConst(ref ty, ref expr) => {
self.head(&visibility_qualified(&item.vis, "const"))?;
self.print_name(item.name)?;
self.print_name(item.name.node)?;
self.word_space(":")?;
self.print_type(&ty)?;
space(&mut self.s)?;
Expand All @@ -732,7 +732,7 @@ impl<'a> State<'a> {
unsafety,
constness,
abi,
Some(item.name),
Some(item.name.node),
typarams,
&item.vis)?;
word(&mut self.s, " ")?;
Expand All @@ -742,7 +742,7 @@ impl<'a> State<'a> {
}
hir::ItemMod(ref _mod) => {
self.head(&visibility_qualified(&item.vis, "mod"))?;
self.print_name(item.name)?;
self.print_name(item.name.node)?;
self.nbsp()?;
self.bopen()?;
self.print_mod(_mod, &item.attrs)?;
Expand All @@ -759,7 +759,7 @@ impl<'a> State<'a> {
self.ibox(indent_unit)?;
self.ibox(0)?;
self.word_nbsp(&visibility_qualified(&item.vis, "type"))?;
self.print_name(item.name)?;
self.print_name(item.name.node)?;
self.print_generics(params)?;
self.end()?; // end the inner ibox

Expand All @@ -771,15 +771,15 @@ impl<'a> State<'a> {
self.end()?; // end the outer ibox
}
hir::ItemEnum(ref enum_definition, ref params) => {
self.print_enum_def(enum_definition, params, item.name, item.span, &item.vis)?;
self.print_enum_def(enum_definition, params, item.name.node, item.span, &item.vis)?;
}
hir::ItemStruct(ref struct_def, ref generics) => {
self.head(&visibility_qualified(&item.vis, "struct"))?;
self.print_struct(struct_def, generics, item.name, item.span, true)?;
self.print_struct(struct_def, generics, item.name.node, item.span, true)?;
}
hir::ItemUnion(ref struct_def, ref generics) => {
self.head(&visibility_qualified(&item.vis, "union"))?;
self.print_struct(struct_def, generics, item.name, item.span, true)?;
self.print_struct(struct_def, generics, item.name.node, item.span, true)?;
}
hir::ItemDefaultImpl(unsafety, ref trait_ref) => {
self.head("")?;
Expand Down Expand Up @@ -841,7 +841,7 @@ impl<'a> State<'a> {
self.print_visibility(&item.vis)?;
self.print_unsafety(unsafety)?;
self.word_nbsp("trait")?;
self.print_name(item.name)?;
self.print_name(item.name.node)?;
self.print_generics(generics)?;
let mut real_bounds = Vec::with_capacity(bounds.len());
for b in bounds.iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
ast_map::NodeItem(ref item) => {
match item.node {
hir::ItemFn(ref fn_decl, unsafety, constness, _, ref gen, _) => {
Some((fn_decl, gen, unsafety, constness, item.name, item.span))
Some((fn_decl, gen, unsafety, constness, item.name.node, item.span))
}
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
self.warn_dead_code(
item.id,
item.span,
item.name,
item.name.node,
item.node.descriptive_variant()
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
EntryPointType::Start
} else if attr::contains_name(&item.attrs, "main") {
EntryPointType::MainAttr
} else if item.name == "main" {
} else if item.name.node == "main" {
if at_root {
// This is a top-level function so can be 'main'
EntryPointType::MainNamed
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes {
match it.node {
hir::ItemTy(..) |
hir::ItemStruct(..) |
hir::ItemUnion(..) => self.check_case(cx, "type", it.name, it.span),
hir::ItemTrait(..) => self.check_case(cx, "trait", it.name, it.span),
hir::ItemUnion(..) => self.check_case(cx, "type", it.name.node, it.span),
hir::ItemTrait(..) => self.check_case(cx, "trait", it.name.node, it.span),
hir::ItemEnum(ref enum_definition, _) => {
if has_extern_repr {
return;
}
self.check_case(cx, "type", it.name, it.span);
self.check_case(cx, "type", it.name.node, it.span);
for variant in &enum_definition.variants {
self.check_case(cx, "variant", variant.node.name, variant.span);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {

fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
if let hir::ItemMod(_) = it.node {
self.check_snake_case(cx, "module", &it.name.as_str(), Some(it.span));
self.check_snake_case(cx, "module", &it.name.node.as_str(), Some(it.span));
}
}

Expand Down Expand Up @@ -352,10 +352,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
match it.node {
hir::ItemStatic(..) => {
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name.node, it.span);
}
hir::ItemConst(..) => {
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name, it.span);
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name.node, it.span);
}
_ => {}
}
Expand Down
Loading

0 comments on commit 8a383b1

Please sign in to comment.