diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 625bde2ca8b67..33f62192fe43c 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -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); @@ -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, @@ -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); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 74876eb59ee9a..6092c6b006c9a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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; @@ -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))), @@ -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(), @@ -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) => { @@ -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] */), @@ -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] */), @@ -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 { diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 068e7ed8624ed..9fbd0db9d31a4 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -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 @@ -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, decl: &'a ast::FnDecl, unsafety: ast::Unsafety, constness: ast::Constness, @@ -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) diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index eb5a89f320e7b..6fac73a6eca6d 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -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) => { @@ -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) @@ -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), }; @@ -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), }; @@ -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); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 117edcf14a1d1..f7c4247727db8 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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, @@ -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, @@ -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); @@ -899,7 +899,7 @@ trait Named { impl Named for Spanned { 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 } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 4fd8f96ba046a..48c78aa13dfc6 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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, pub attrs: HirVec, pub id: NodeId, pub node: Item_, diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 74920b1328076..dfdc47255d510 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -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 @@ -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, ";")?; } @@ -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)?; @@ -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)?; @@ -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, " ")?; @@ -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)?; @@ -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 @@ -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("")?; @@ -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() { diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 90d752ae6ee29..2a5dad56c7c11 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -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, } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 1bf6b837fd998..968613f505639 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -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 { diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index e927843a984b8..7f199e9c2a1c4 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -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 diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 2aa74407afc5b..f24ca9abb0d7e 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -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); } @@ -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)); } } @@ -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); } _ => {} } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index d36242537b8e5..8b32c6f77768a 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -169,10 +169,10 @@ impl<'a> CrateLoader<'a> { Some(i.span)); name } - None => i.ident.name, + None => i.ident.node.name, }; Some(ExternCrateInfo { - ident: i.ident.name, + ident: i.ident.node.name, name: name, id: i.id, dep_kind: if attr::contains_name(&i.attrs, "no_link") { diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 25a37931ba31f..c98928009c066 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -102,7 +102,7 @@ impl<'b> Resolver<'b> { /// Constructs the reduced graph for one item. fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) { let parent = self.current_module; - let name = item.ident.name; + let name = item.ident.node.name; let sp = item.span; let vis = self.resolve_visibility(&item.vis); @@ -256,7 +256,7 @@ impl<'b> Resolver<'b> { self.process_legacy_macro_imports(item, module, expansion); } - ItemKind::Mod(..) if item.ident == keywords::Invalid.ident() => {} // Crate root + ItemKind::Mod(..) if item.ident.node == keywords::Invalid.ident() => {} // Crate root ItemKind::Mod(..) => { let def = Def::Mod(self.definitions.local_def_id(item.id)); @@ -365,7 +365,7 @@ impl<'b> Resolver<'b> { parent: Module<'b>, vis: ty::Visibility, expansion: Mark) { - let name = variant.node.name.name; + let name = variant.node.name.node.name; let def_id = self.definitions.local_def_id(variant.node.data.id()); // Define a name in the type namespace. @@ -756,10 +756,13 @@ impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> { TraitItemKind::Macro(_) => bug!(), // handled above }; - self.resolver.trait_item_map.insert((item.ident.name, def_id), is_static_method); + self.resolver.trait_item_map.insert((item.ident.node.name, def_id), is_static_method); let vis = ty::Visibility::Public; - self.resolver.define(parent, item.ident.name, ns, (def, vis, item.span, self.expansion)); + self.resolver.define(parent, + item.ident.node.name, + ns, + (def, vis, item.span, self.expansion)); self.resolver.current_module = parent.parent.unwrap(); // nearest normal ancestor visit::walk_trait_item(self, item); diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f7aaf2475f65e..2258e375126b9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -598,7 +598,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { // `visit::walk_variant` without the discriminant expression. self.visit_variant_data(&variant.node.data, - variant.node.name, + variant.node.name.node, generics, item_id, variant.span); @@ -1511,7 +1511,7 @@ impl<'a> Resolver<'a> { } fn resolve_item(&mut self, item: &Item) { - let name = item.ident.name; + let name = item.ident.node.name; debug!("(resolving item) resolving {}", name); @@ -1815,7 +1815,7 @@ impl<'a> Resolver<'a> { ImplItemKind::Const(..) => { // If this is a trait impl, ensure the const // exists in trait - this.check_trait_item(impl_item.ident.name, + this.check_trait_item(impl_item.ident.node.name, impl_item.span, |n, s| ResolutionError::ConstNotMemberOfTrait(n, s)); visit::walk_impl_item(this, impl_item); @@ -1823,7 +1823,7 @@ impl<'a> Resolver<'a> { ImplItemKind::Method(ref sig, _) => { // If this is a trait impl, ensure the method // exists in trait - this.check_trait_item(impl_item.ident.name, + this.check_trait_item(impl_item.ident.node.name, impl_item.span, |n, s| ResolutionError::MethodNotMemberOfTrait(n, s)); @@ -1839,7 +1839,7 @@ impl<'a> Resolver<'a> { ImplItemKind::Type(ref ty) => { // If this is a trait impl, ensure the type // exists in trait - this.check_trait_item(impl_item.ident.name, + this.check_trait_item(impl_item.ident.node.name, impl_item.span, |n, s| ResolutionError::TypeNotMemberOfTrait(n, s)); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index afa78a05a63a8..b90df5221f5e8 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -658,7 +658,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } for variant in &enum_definition.variants { - let name = variant.node.name.name.to_string(); + let name = variant.node.name.node.name.to_string(); let mut qualname = enum_data.qualname.clone(); qualname.push_str("::"); qualname.push_str(&name); @@ -1113,7 +1113,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { match trait_item.node { ast::TraitItemKind::Const(ref ty, Some(ref expr)) => { self.process_assoc_const(trait_item.id, - trait_item.ident.name, + trait_item.ident.node.name, trait_item.span, &ty, &expr, @@ -1125,7 +1125,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { self.process_method(sig, body.as_ref().map(|x| &**x), trait_item.id, - trait_item.ident.name, + trait_item.ident.node.name, Visibility::Public, &trait_item.attrs, trait_item.span); @@ -1141,7 +1141,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { match impl_item.node { ast::ImplItemKind::Const(ref ty, ref expr) => { self.process_assoc_const(impl_item.id, - impl_item.ident.name, + impl_item.ident.node.name, impl_item.span, &ty, &expr, @@ -1153,7 +1153,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { self.process_method(sig, Some(body), impl_item.id, - impl_item.ident.name, + impl_item.ident.node.name, From::from(&impl_item.vis), &impl_item.attrs, impl_item.span); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index fba77d171797e..8f7c3569246b7 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1002,7 +1002,7 @@ fn convert_struct_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, let did = ccx.tcx.map.local_def_id(it.id); // Use separate constructor id for unit/tuple structs and reuse did for braced structs. let ctor_id = if !def.is_struct() { Some(ccx.tcx.map.local_def_id(def.id())) } else { None }; - let variants = vec![convert_struct_variant(ccx, ctor_id.unwrap_or(did), it.name, + let variants = vec![convert_struct_variant(ccx, ctor_id.unwrap_or(did), it.name.node, ConstInt::Infer(0), def)]; let adt = ccx.tcx.alloc_adt_def(did, AdtKind::Struct, variants); if let Some(ctor_id) = ctor_id { @@ -1020,7 +1020,7 @@ fn convert_union_def<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, -> &'tcx ty::AdtDef { let did = ccx.tcx.map.local_def_id(it.id); - let variants = vec![convert_struct_variant(ccx, did, it.name, ConstInt::Infer(0), def)]; + let variants = vec![convert_struct_variant(ccx, did, it.name.node, ConstInt::Infer(0), def)]; let adt = ccx.tcx.alloc_adt_def(did, AdtKind::Union, variants); ccx.tcx.adt_defs.borrow_mut().insert(did, adt); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 4087b9a761f97..48c61865dbe81 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { pub fn visit_item(&mut self, item: &hir::Item, renamed: Option, om: &mut Module) { debug!("Visiting item {:?}", item); - let name = renamed.unwrap_or(item.name); + let name = renamed.unwrap_or(item.name.node); match item.node { hir::ItemForeignMod(ref fm) => { // If inlining we only want to include public functions. diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2a911aceb9d94..dee60b1cf3f21 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -18,7 +18,7 @@ pub use symbol::Symbol as Name; pub use util::ThinVec; use syntax_pos::{mk_sp, Span, DUMMY_SP, ExpnId}; -use codemap::{respan, Spanned}; +use codemap::{dummy_spanned, respan, Spanned}; use abi::Abi; use ext::hygiene::SyntaxContext; use print::pprust; @@ -51,6 +51,14 @@ impl Ident { pub fn from_str(s: &str) -> Ident { Ident::with_empty_ctxt(Symbol::intern(s)) } + + pub fn spanned(self, sp: Span) -> SpannedIdent { + respan(sp, self) + } + + pub fn dummy_spanned(self) -> SpannedIdent { + dummy_spanned(self) + } } impl fmt::Debug for Ident { @@ -1175,7 +1183,7 @@ pub struct MethodSig { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TraitItem { pub id: NodeId, - pub ident: Ident, + pub ident: SpannedIdent, pub attrs: Vec, pub node: TraitItemKind, pub span: Span, @@ -1192,7 +1200,7 @@ pub enum TraitItemKind { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct ImplItem { pub id: NodeId, - pub ident: Ident, + pub ident: SpannedIdent, pub vis: Visibility, pub defaultness: Defaultness, pub attrs: Vec, @@ -1656,7 +1664,7 @@ pub struct EnumDef { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Variant_ { - pub name: Ident, + pub name: SpannedIdent, pub attrs: Vec, pub data: VariantData, /// Explicit discriminant, e.g. `Foo = 1` @@ -1831,7 +1839,7 @@ impl VariantData { /// The name might be a dummy name in case of anonymous items #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Item { - pub ident: Ident, + pub ident: SpannedIdent, pub attrs: Vec, pub id: NodeId, pub node: ItemKind, @@ -1839,6 +1847,12 @@ pub struct Item { pub span: Span, } +impl Item { + pub fn spanned_symbol(&self) -> Spanned { + respan(self.ident.span, self.ident.node.name) + } +} + #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum ItemKind { /// An`extern crate` item, with optional original crate name. diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 12ce642891173..2a3cf542958cc 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -20,6 +20,7 @@ pub use self::ExpnFormat::*; use std::cell::RefCell; +use std::fmt; use std::path::{Path,PathBuf}; use std::rc::Rc; @@ -61,6 +62,12 @@ pub struct Spanned { pub span: Span, } +impl fmt::Display for Spanned where T: fmt::Display { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.node, f) + } +} + pub fn spanned(lo: BytePos, hi: BytePos, t: T) -> Spanned { respan(mk_sp(lo, hi), t) } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index fe5cb87ad59b5..184b2d5e91f44 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -14,6 +14,7 @@ use std::env; use ast; use ast::{Ident, Name}; +use codemap; use syntax_pos::Span; use ext::base::{ExtCtxt, MacEager, MacResult}; use ext::build::AstBuilder; @@ -227,7 +228,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, MacEager::items(SmallVector::many(vec![ P(ast::Item { - ident: name.clone(), + ident: codemap::dummy_spanned(name.clone()), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Const( diff --git a/src/libsyntax/entry.rs b/src/libsyntax/entry.rs index 93ca1948ed84b..640620c174906 100644 --- a/src/libsyntax/entry.rs +++ b/src/libsyntax/entry.rs @@ -28,7 +28,7 @@ pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType { EntryPointType::Start } else if attr::contains_name(&item.attrs, "main") { EntryPointType::MainAttr - } else if item.ident.name == "main" { + } else if item.ident.node.name == "main" { if depth == 1 { // This is a top-level function so can be 'main' EntryPointType::MainNamed diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a208b934d79e1..3b61d4296c566 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -234,7 +234,7 @@ pub trait AstBuilder { output: P, body: P) -> P; - fn variant(&self, span: Span, name: Ident, tys: Vec> ) -> ast::Variant; + fn variant(&self, span: Span, name: ast::SpannedIdent, tys: Vec> ) -> ast::Variant; fn item_enum_poly(&self, span: Span, name: Ident, @@ -1004,7 +1004,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { // FIXME: Would be nice if our generated code didn't violate // Rust coding conventions P(ast::Item { - ident: name, + ident: name.dummy_spanned(), attrs: attrs, id: ast::DUMMY_NODE_ID, node: node, @@ -1047,7 +1047,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { body) } - fn variant(&self, span: Span, name: Ident, tys: Vec> ) -> ast::Variant { + fn variant(&self, span: Span, name: ast::SpannedIdent, tys: Vec> ) -> ast::Variant { let fields: Vec<_> = tys.into_iter().map(|ty| { ast::StructField { span: ty.span, @@ -1169,7 +1169,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { vis: ast::Visibility, vp: P) -> P { P(ast::Item { id: ast::DUMMY_NODE_ID, - ident: keywords::Invalid.ident(), + ident: keywords::Invalid.ident().dummy_spanned(), attrs: vec![], node: ast::ItemKind::Use(vp), vis: vis, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e3979926680a1..f5ab6958052ca 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -201,7 +201,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { attrs: krate.attrs, span: krate.span, node: ast::ItemKind::Mod(krate.module), - ident: keywords::Invalid.ident(), + ident: keywords::Invalid.ident().dummy_spanned(), id: ast::DUMMY_NODE_ID, vis: ast::Visibility::Public, }))); @@ -752,7 +752,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { self.collect(ExpansionKind::Items, InvocationKind::Bang { mac: mac, attrs: item.attrs, - ident: Some(item.ident), + ident: Some(item.ident.node), span: item.span, }).make_items() } @@ -760,13 +760,13 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { }) } ast::ItemKind::Mod(ast::Mod { inner, .. }) => { - if item.ident == keywords::Invalid.ident() { + if item.ident.node == keywords::Invalid.ident() { return noop_fold_item(item, self); } let orig_directory_ownership = self.cx.current_expansion.directory_ownership; let mut module = (*self.cx.current_expansion.module).clone(); - module.mod_path.push(item.ident); + module.mod_path.push(item.ident.node); // Detect if this is an inline module (`mod m { ... }` as opposed to `mod m;`). // In the non-inline case, `inner` is never the dummy span (c.f. `parse_item_mod`). @@ -778,7 +778,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { self.cx.current_expansion.directory_ownership = DirectoryOwnership::Owned; module.directory.push(&*path.as_str()); } else { - module.directory.push(&*item.ident.name.as_str()); + module.directory.push(&*item.ident.node.name.as_str()); } } else { let mut path = diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 4fe57a8345e94..e730eacf94c53 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -43,15 +43,15 @@ pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion { ExpansionKind::Expr => Expansion::Expr(expr_placeholder()), ExpansionKind::OptExpr => Expansion::OptExpr(Some(expr_placeholder())), ExpansionKind::Items => Expansion::Items(SmallVector::one(P(ast::Item { - id: id, span: span, ident: ident, vis: vis, attrs: attrs, + id: id, span: span, ident: ident.dummy_spanned(), vis: vis, attrs: attrs, node: ast::ItemKind::Mac(mac_placeholder()), }))), ExpansionKind::TraitItems => Expansion::TraitItems(SmallVector::one(ast::TraitItem { - id: id, span: span, ident: ident, attrs: attrs, + id: id, span: span, ident: ident.dummy_spanned(), attrs: attrs, node: ast::TraitItemKind::Macro(mac_placeholder()), })), ExpansionKind::ImplItems => Expansion::ImplItems(SmallVector::one(ast::ImplItem { - id: id, span: span, ident: ident, vis: vis, attrs: attrs, + id: id, span: span, ident: ident.dummy_spanned(), vis: vis, attrs: attrs, node: ast::ImplItemKind::Macro(mac_placeholder()), defaultness: ast::Defaultness::Final, })), @@ -175,7 +175,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { // Scope placeholder if let ast::StmtKind::Item(ref item) = stmt.node { if let ast::ItemKind::Mac(..) = item.node { - macros.push(item.ident.ctxt.data().outer_mark); + macros.push(item.ident.node.ctxt.data().outer_mark); return None; } } @@ -217,7 +217,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> { pub fn reconstructed_macro_rules(def: &ast::MacroDef) -> Expansion { Expansion::Items(SmallVector::one(P(ast::Item { - ident: def.ident, + ident: def.ident.dummy_spanned(), attrs: def.attrs.clone(), id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Mac(ast::Mac { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6af8efb2a195c..09a7d94ab57ac 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -21,7 +21,7 @@ use ast::*; use ast; use syntax_pos::Span; -use codemap::{Spanned, respan}; +use codemap::{Spanned, respan, dummy_spanned}; use parse::token; use ptr::P; use symbol::keywords; @@ -144,6 +144,10 @@ pub trait Folder : Sized { noop_fold_ident(i, self) } + fn fold_spanned_ident(&mut self, i: SpannedIdent) -> SpannedIdent { + noop_fold_spanned_ident(i, self) + } + fn fold_usize(&mut self, i: usize) -> usize { noop_fold_usize(i, self) } @@ -429,6 +433,10 @@ pub fn noop_fold_ident(i: Ident, _: &mut T) -> Ident { i } +pub fn noop_fold_spanned_ident(i: SpannedIdent, _: &mut T) -> SpannedIdent { + i +} + pub fn noop_fold_usize(i: usize, _: &mut T) -> usize { i } @@ -922,7 +930,7 @@ pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) -> SmallVector { SmallVector::one(TraitItem { id: folder.new_id(i.id), - ident: folder.fold_ident(i.ident), + ident: folder.fold_spanned_ident(i.ident), attrs: fold_attrs(i.attrs, folder), node: match i.node { TraitItemKind::Const(ty, default) => { @@ -950,7 +958,7 @@ pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) SmallVector::one(ImplItem { id: folder.new_id(i.id), vis: folder.fold_vis(i.vis), - ident: folder.fold_ident(i.ident), + ident: folder.fold_spanned_ident(i.ident), attrs: fold_attrs(i.attrs, folder), defaultness: i.defaultness, node: match i.node { @@ -978,7 +986,7 @@ pub fn noop_fold_mod(Mod {inner, items}: Mod, folder: &mut T) -> Mod pub fn noop_fold_crate(Crate {module, attrs, mut exported_macros, span}: Crate, folder: &mut T) -> Crate { let mut items = folder.fold_item(P(ast::Item { - ident: keywords::Invalid.ident(), + ident: dummy_spanned(keywords::Invalid.ident()), attrs: attrs, id: ast::DUMMY_NODE_ID, vis: ast::Visibility::Public, @@ -1026,7 +1034,7 @@ pub fn noop_fold_item_simple(Item {id, ident, attrs, node, vis, span} Item { id: folder.new_id(id), vis: folder.fold_vis(vis), - ident: folder.fold_ident(ident), + ident: respan(ident.span, folder.fold_ident(ident.node)), attrs: fold_attrs(attrs, folder), node: folder.fold_item_kind(node), span: folder.new_span(span) diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index ded676da3c676..d6a5fa6878e94 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -229,7 +229,7 @@ impl<'a> Parser<'a> { ast::MetaItemKind::Word }; let hi = self.prev_span.hi; - Ok(ast::MetaItem { name: ident.name, node: node, span: mk_sp(lo, hi) }) + Ok(ast::MetaItem { name: ident.node.name, node: node, span: mk_sp(lo, hi) }) } /// matches meta_item_inner : (meta_item | UNSUFFIXED_LIT) ; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index e5b66f889583a..bf56616e5d101 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -609,7 +609,7 @@ mod tests { use super::*; use std::rc::Rc; use syntax_pos::{self, Span, BytePos, Pos, NO_EXPANSION}; - use codemap::Spanned; + use codemap::{Spanned, dummy_spanned}; use ast::{self, Ident, PatKind}; use abi::Abi; use attr::first_attr_value_str_by_name; @@ -833,7 +833,7 @@ mod tests { // this test depends on the intern order of "fn" and "i32" assert_eq!(string_to_item("fn a (b : i32) { b; }".to_string()), Some( - P(ast::Item{ident:Ident::from_str("a"), + P(ast::Item{dummy_spanned(ident:Ident::from_str("a")), attrs:Vec::new(), id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Fn(P(ast::FnDecl { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bdd1606805fef..82e5fa693f811 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -71,7 +71,7 @@ bitflags! { } } -type ItemInfo = (Ident, ItemKind, Option >); +type ItemInfo = (ast::SpannedIdent, ItemKind, Option>); /// How to parse a path. There are three different kinds of paths, all of which /// are parsed somewhat differently. @@ -466,13 +466,13 @@ impl<'a> Parser<'a> { }) } - pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> { + pub fn parse_ident(&mut self) -> PResult<'a, ast::SpannedIdent> { self.check_strict_keywords(); self.check_reserved_keywords(); match self.token { token::Ident(i) => { self.bump(); - Ok(i) + Ok(i.spanned(self.prev_span)) } _ => { Err(if self.prev_token_kind == PrevTokenKind::DocComment { @@ -1118,9 +1118,9 @@ impl<'a> Parser<'a> { let lo = self.span.lo; let (name, node) = if self.eat_keyword(keywords::Type) { - let TyParam {ident, bounds, default, ..} = self.parse_ty_param(vec![])?; + let TyParam {ident, bounds, default, span, ..} = self.parse_ty_param(vec![])?; self.expect(&token::Semi)?; - (ident, TraitItemKind::Type(bounds, default)) + (ident.spanned(span), TraitItemKind::Type(bounds, default)) } else if self.is_const_item() { self.expect_keyword(keywords::Const)?; let ident = self.parse_ident()?; @@ -1153,7 +1153,7 @@ impl<'a> Parser<'a> { } let mac = spanned(lo, self.prev_span.hi, Mac_ { path: pth, tts: tts }); - (keywords::Invalid.ident(), ast::TraitItemKind::Macro(mac)) + (keywords::Invalid.ident().dummy_spanned(), ast::TraitItemKind::Macro(mac)) } else { let (constness, unsafety, abi) = match self.parse_fn_front_matter() { Ok(cua) => cua, @@ -1585,7 +1585,7 @@ impl<'a> Parser<'a> { self.bump(); Ok(sid) } - _ => self.parse_ident(), + _ => self.parse_ident().map(|s| s.node), } } @@ -1947,7 +1947,7 @@ impl<'a> Parser<'a> { self.bump(); Ok(Ident::with_empty_ctxt(name)) } else { - self.parse_ident() + self.parse_ident().map(|s| s.node) } } @@ -1967,8 +1967,8 @@ impl<'a> Parser<'a> { hi = self.prev_span.hi; // Mimic `x: x` for the `x` field shorthand. - let path = ast::Path::from_ident(mk_sp(lo, hi), fieldname); - (fieldname, self.mk_expr(lo, hi, ExprKind::Path(None, path), ThinVec::new()), true) + let path = ast::Path::from_ident(mk_sp(lo, hi), fieldname.node); + (fieldname.node, self.mk_expr(lo, hi, ExprKind::Path(None, path), ThinVec::new()), true) }; Ok(ast::Field { ident: spanned(lo, hi, fieldname), @@ -2626,8 +2626,8 @@ impl<'a> Parser<'a> { sp = mk_sp(sp.lo, self.span.hi); self.parse_ident().unwrap_or_else(|mut e| { e.emit(); - keywords::Invalid.ident() - }) + keywords::Invalid.ident().dummy_spanned() + }).node } } token::SubstNt(name) => { @@ -2642,7 +2642,7 @@ impl<'a> Parser<'a> { self.bump(); sp = mk_sp(sp.lo, self.span.hi); let nt_kind = self.parse_ident()?; - Ok(TokenTree::Token(sp, MatchNt(name, nt_kind))) + Ok(TokenTree::Token(sp, MatchNt(name, nt_kind.node))) } else { Ok(TokenTree::Token(sp, SubstNt(name))) } @@ -3480,10 +3480,9 @@ impl<'a> Parser<'a> { (false, true) => BindingMode::ByValue(Mutability::Mutable), (false, false) => BindingMode::ByValue(Mutability::Immutable), }; - let fieldpath = codemap::Spanned{span:self.prev_span, node:fieldname}; let fieldpat = P(ast::Pat{ id: ast::DUMMY_NODE_ID, - node: PatKind::Ident(bind_type, fieldpath, None), + node: PatKind::Ident(bind_type, fieldname, None), span: mk_sp(boxed_span_lo, hi), }); @@ -3496,7 +3495,7 @@ impl<'a> Parser<'a> { } else { fieldpat }; - (subpat, fieldname, true) + (subpat, fieldname.node, true) }; fields.push(codemap::Spanned { span: mk_sp(lo, hi), @@ -3696,7 +3695,7 @@ impl<'a> Parser<'a> { "expected identifier, found enum pattern")) } - Ok(PatKind::Ident(binding_mode, name, sub)) + Ok(PatKind::Ident(binding_mode, name.node, sub)) } /// Parse a local variable declaration @@ -3730,7 +3729,7 @@ impl<'a> Parser<'a> { let ty = self.parse_ty_sum()?; Ok(StructField { span: mk_sp(lo, self.prev_span.hi), - ident: Some(name), + ident: Some(name.node), vis: vis, id: ast::DUMMY_NODE_ID, ty: ty, @@ -3871,7 +3870,10 @@ impl<'a> Parser<'a> { // it's a macro invocation let id = match self.token { token::OpenDelim(_) => keywords::Invalid.ident(), // no special identifier - _ => self.parse_ident()?, + _ => { + let id = self.parse_ident()?; + id.node + } }; // check that we're pointing at delimiters (need to check @@ -3956,7 +3958,7 @@ impl<'a> Parser<'a> { span: mk_sp(lo, hi), node: StmtKind::Item({ self.mk_item( - lo, hi, id /*id is good here*/, + lo, hi, codemap::dummy_spanned(id) /*id is good here*/, ItemKind::Mac(spanned(lo, hi, Mac_ { path: pth, tts: tts })), Visibility::Inherited, attrs) @@ -4209,7 +4211,7 @@ impl<'a> Parser<'a> { Ok(TyParam { attrs: preceding_attrs.into(), - ident: ident, + ident: ident.node, id: ast::DUMMY_NODE_ID, bounds: bounds, default: default, @@ -4342,7 +4344,7 @@ impl<'a> Parser<'a> { let hi = ty.span.hi; let span = mk_sp(lo, hi); return Ok(TypeBinding{id: ast::DUMMY_NODE_ID, - ident: ident, + ident: ident.node, ty: ty, span: span, }); @@ -4704,13 +4706,13 @@ impl<'a> Parser<'a> { } /// Parse the name and optional generic types of a function header. - fn parse_fn_header(&mut self) -> PResult<'a, (Ident, ast::Generics)> { + fn parse_fn_header(&mut self) -> PResult<'a, (ast::SpannedIdent, ast::Generics)> { let id = self.parse_ident()?; let generics = self.parse_generics()?; Ok((id, generics)) } - fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident, + fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: ast::SpannedIdent, node: ItemKind, vis: Visibility, attrs: Vec) -> P { P(Item { @@ -4838,7 +4840,8 @@ impl<'a> Parser<'a> { /// Parse a method or a macro invocation in a trait impl. fn parse_impl_method(&mut self, vis: &Visibility) - -> PResult<'a, (Ident, Vec, ast::ImplItemKind)> { + -> PResult<'a, (ast::SpannedIdent, + Vec, ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if self.token.is_path_start() { // method macro. @@ -4860,7 +4863,7 @@ impl<'a> Parser<'a> { } let mac = spanned(lo, self.prev_span.hi, Mac_ { path: pth, tts: tts }); - Ok((keywords::Invalid.ident(), vec![], ast::ImplItemKind::Macro(mac))) + Ok((keywords::Invalid.ident().dummy_spanned(), vec![], ast::ImplItemKind::Macro(mac))) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; let ident = self.parse_ident()?; @@ -4951,7 +4954,7 @@ impl<'a> Parser<'a> { self.expect(&token::OpenDelim(token::Brace))?; self.expect(&token::CloseDelim(token::Brace))?; - Ok((keywords::Invalid.ident(), + Ok((keywords::Invalid.ident().dummy_spanned(), ItemKind::DefaultImpl(unsafety, opt_trait.unwrap()), None)) } else { if opt_trait.is_some() { @@ -4967,7 +4970,7 @@ impl<'a> Parser<'a> { impl_items.push(self.parse_impl_item()?); } - Ok((keywords::Invalid.ident(), + Ok((keywords::Invalid.ident().dummy_spanned(), ItemKind::Impl(unsafety, polarity, generics, opt_trait, ty, impl_items), Some(attrs))) } @@ -5263,9 +5266,9 @@ impl<'a> Parser<'a> { if in_cfg { // This mod is in an external file. Let's go get it! let ModulePathSuccess { path, directory_ownership, warn } = - self.submod_path(id, &outer_attrs, id_span)?; + self.submod_path(id.node, &outer_attrs, id_span)?; let (module, mut attrs) = - self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?; + self.eval_src_mod(path, directory_ownership, id.node.to_string(), id_span)?; if warn { let attr = ast::Attribute { id: attr::mk_attr_id(), @@ -5288,7 +5291,7 @@ impl<'a> Parser<'a> { } } else { let old_directory = self.directory.clone(); - self.push_directory(id, &outer_attrs); + self.push_directory(id.node, &outer_attrs); self.expect(&token::OpenDelim(token::Brace))?; let mod_inner_lo = self.span.lo; let attrs = self.parse_inner_attributes()?; @@ -5457,7 +5460,7 @@ impl<'a> Parser<'a> { let hi = self.span.hi; self.expect(&token::Semi)?; Ok(ast::ForeignItem { - ident: ident, + ident: ident.node, attrs: attrs, node: ForeignItemKind::Fn(decl, generics), id: ast::DUMMY_NODE_ID, @@ -5478,7 +5481,7 @@ impl<'a> Parser<'a> { let hi = self.span.hi; self.expect(&token::Semi)?; Ok(ForeignItem { - ident: ident, + ident: ident.node, attrs: attrs, node: ForeignItemKind::Static(ty, mutbl), id: ast::DUMMY_NODE_ID, @@ -5501,7 +5504,7 @@ impl<'a> Parser<'a> { let crate_name = self.parse_ident()?; let (maybe_path, ident) = if let Some(ident) = self.parse_rename()? { - (Some(crate_name.name), ident) + (Some(crate_name.node.name), ident.dummy_spanned()) } else { (None, crate_name) }; @@ -5551,7 +5554,7 @@ impl<'a> Parser<'a> { }; Ok(self.mk_item(lo, prev_span.hi, - keywords::Invalid.ident(), + keywords::Invalid.ident().dummy_spanned(), ItemKind::ForeignMod(m), visibility, attrs)) @@ -5685,7 +5688,7 @@ impl<'a> Parser<'a> { let prev_span = self.prev_span; let item = self.mk_item(lo, prev_span.hi, - keywords::Invalid.ident(), + keywords::Invalid.ident().spanned(prev_span), item_, visibility, attrs); @@ -5997,7 +6000,7 @@ impl<'a> Parser<'a> { let id = if self.token.is_ident() { self.parse_ident()? } else { - keywords::Invalid.ident() // no special identifier + keywords::Invalid.ident().dummy_spanned() // no special identifier }; // eat a matched-delimiter token tree: let delim = self.expect_open_delim()?; @@ -6048,7 +6051,8 @@ impl<'a> Parser<'a> { let ident = if this.eat_keyword(keywords::SelfValue) { keywords::SelfValue.ident() } else { - this.parse_ident()? + let id = this.parse_ident()?; + id.node }; let rename = this.parse_rename()?; let node = ast::PathListItem_ { @@ -6113,7 +6117,7 @@ impl<'a> Parser<'a> { fn parse_rename(&mut self) -> PResult<'a, Option> { if self.eat_keyword(keywords::As) { - self.parse_ident().map(Some) + self.parse_ident().map(|s| Some(s.node)) } else { Ok(None) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c28b9d00501b7..a91c439ac16f9 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1150,7 +1150,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, "as")); try!(space(&mut self.s)); } - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(word(&mut self.s, ";")); try!(self.end()); // end inner head-block try!(self.end()); // end outer head-block @@ -1167,7 +1167,7 @@ impl<'a> State<'a> { if m == ast::Mutability::Mutable { try!(self.word_space("mut")); } - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(self.word_space(":")); try!(self.print_type(&ty)); try!(space(&mut self.s)); @@ -1180,7 +1180,7 @@ impl<'a> State<'a> { } ast::ItemKind::Const(ref ty, ref expr) => { try!(self.head(&visibility_qualified(&item.vis, "const"))); - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(self.word_space(":")); try!(self.print_type(&ty)); try!(space(&mut self.s)); @@ -1198,7 +1198,7 @@ impl<'a> State<'a> { unsafety, constness.node, abi, - Some(item.ident), + Some(item.ident.node), typarams, &item.vis )); @@ -1207,7 +1207,7 @@ impl<'a> State<'a> { } ast::ItemKind::Mod(ref _mod) => { try!(self.head(&visibility_qualified(&item.vis, "mod"))); - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(self.nbsp()); try!(self.bopen()); try!(self.print_mod(_mod, &item.attrs)); @@ -1224,7 +1224,7 @@ impl<'a> State<'a> { try!(self.ibox(INDENT_UNIT)); try!(self.ibox(0)); try!(self.word_nbsp(&visibility_qualified(&item.vis, "type"))); - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(self.print_generics(params)); try!(self.end()); // end the inner ibox @@ -1239,18 +1239,18 @@ impl<'a> State<'a> { try!(self.print_enum_def( enum_definition, params, - item.ident, + item.ident.node, item.span, &item.vis )); } ast::ItemKind::Struct(ref struct_def, ref generics) => { try!(self.head(&visibility_qualified(&item.vis, "struct"))); - try!(self.print_struct(&struct_def, generics, item.ident, item.span, true)); + try!(self.print_struct(&struct_def, generics, item.ident.node, item.span, true)); } ast::ItemKind::Union(ref struct_def, ref generics) => { try!(self.head(&visibility_qualified(&item.vis, "union"))); - try!(self.print_struct(&struct_def, generics, item.ident, item.span, true)); + try!(self.print_struct(&struct_def, generics, item.ident.node, item.span, true)); } ast::ItemKind::DefaultImpl(unsafety, ref trait_ref) => { try!(self.head("")); @@ -1309,7 +1309,7 @@ impl<'a> State<'a> { try!(self.print_visibility(&item.vis)); try!(self.print_unsafety(unsafety)); try!(self.word_nbsp("trait")); - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(self.print_generics(generics)); let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds.iter() { @@ -1334,7 +1334,7 @@ impl<'a> State<'a> { try!(self.print_visibility(&item.vis)); try!(self.print_path(&node.path, false, 0)); try!(word(&mut self.s, "! ")); - try!(self.print_ident(item.ident)); + try!(self.print_ident(item.ident.node)); try!(self.cbox(INDENT_UNIT)); try!(self.popen()); try!(self.print_tts(&node.tts[..])); @@ -1516,7 +1516,7 @@ impl<'a> State<'a> { pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> { try!(self.head("")); let generics = ast::Generics::default(); - try!(self.print_struct(&v.node.data, &generics, v.node.name, v.span, false)); + try!(self.print_struct(&v.node.data, &generics, v.node.name.node, v.span, false)); match v.node.disr_expr { Some(ref d) => { try!(space(&mut self.s)); @@ -1549,7 +1549,7 @@ impl<'a> State<'a> { try!(self.print_outer_attributes(&ti.attrs)); match ti.node { ast::TraitItemKind::Const(ref ty, ref default) => { - try!(self.print_associated_const(ti.ident, &ty, + try!(self.print_associated_const(ti.ident.node, &ty, default.as_ref().map(|expr| &**expr), &ast::Visibility::Inherited)); } @@ -1557,7 +1557,7 @@ impl<'a> State<'a> { if body.is_some() { try!(self.head("")); } - try!(self.print_method_sig(ti.ident, sig, &ast::Visibility::Inherited)); + try!(self.print_method_sig(ti.ident.node, sig, &ast::Visibility::Inherited)); if let Some(ref body) = *body { try!(self.nbsp()); try!(self.print_block_with_attrs(body, &ti.attrs)); @@ -1566,7 +1566,7 @@ impl<'a> State<'a> { } } ast::TraitItemKind::Type(ref bounds, ref default) => { - try!(self.print_associated_type(ti.ident, Some(bounds), + try!(self.print_associated_type(ti.ident.node, Some(bounds), default.as_ref().map(|ty| &**ty))); } ast::TraitItemKind::Macro(codemap::Spanned { ref node, .. }) => { @@ -1594,16 +1594,16 @@ impl<'a> State<'a> { } match ii.node { ast::ImplItemKind::Const(ref ty, ref expr) => { - try!(self.print_associated_const(ii.ident, &ty, Some(&expr), &ii.vis)); + try!(self.print_associated_const(ii.ident.node, &ty, Some(&expr), &ii.vis)); } ast::ImplItemKind::Method(ref sig, ref body) => { try!(self.head("")); - try!(self.print_method_sig(ii.ident, sig, &ii.vis)); + try!(self.print_method_sig(ii.ident.node, sig, &ii.vis)); try!(self.nbsp()); try!(self.print_block_with_attrs(body, &ii.attrs)); } ast::ImplItemKind::Type(ref ty) => { - try!(self.print_associated_type(ii.ident, None, Some(ty))); + try!(self.print_associated_type(ii.ident.node, None, Some(ty))); } ast::ImplItemKind::Macro(codemap::Spanned { ref node, .. }) => { // code copied from ItemKind::Mac: @@ -3107,7 +3107,7 @@ mod tests { let ident = ast::Ident::from_str("principal_skinner"); let var = codemap::respan(syntax_pos::DUMMY_SP, ast::Variant_ { - name: ident, + name: codemap::dummy_spanned(ident), attrs: Vec::new(), // making this up as I go.... ? data: ast::VariantData::Unit(ast::DUMMY_NODE_ID), diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 6a291ad9c408a..f0b21e23e7dd4 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -60,7 +60,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess, attr::mk_word_item(Symbol::intern("macro_use")))], vis: ast::Visibility::Inherited, node: ast::ItemKind::ExternCrate(Some(crate_name)), - ident: ast::Ident::from_str(name), + ident: ast::Ident::from_str(name).dummy_spanned(), id: ast::DUMMY_NODE_ID, span: DUMMY_SP, })); @@ -88,7 +88,7 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess, span: span, })))), id: ast::DUMMY_NODE_ID, - ident: keywords::Invalid.ident(), + ident: keywords::Invalid.ident().dummy_spanned(), span: span, })); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index fca89e265e4ed..6a57dba625dd8 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -114,8 +114,8 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { fn fold_item(&mut self, i: P) -> SmallVector> { let ident = i.ident; - if ident.name != keywords::Invalid.name() { - self.cx.path.push(ident); + if ident.node.name != keywords::Invalid.name() { + self.cx.path.push(ident.node); } debug!("current path: {}", path_name_i(&self.cx.path)); @@ -135,7 +135,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { should_panic: should_panic(&i, &self.cx) }; self.cx.testfns.push(test); - self.tests.push(i.ident); + self.tests.push(i.ident.node); } } } @@ -163,7 +163,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { } item.node = ast::ItemKind::Mod(mod_folded); } - if ident.name != keywords::Invalid.name() { + if ident.node.name != keywords::Invalid.name() { self.cx.path.pop(); } SmallVector::one(P(item)) @@ -254,7 +254,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt, let parent = if parent == ast::DUMMY_NODE_ID { ast::CRATE_NODE_ID } else { parent }; cx.ext_cx.current_expansion.mark = cx.ext_cx.resolver.get_module_scope(parent); let it = cx.ext_cx.monotonic_expander().fold_item(P(ast::Item { - ident: sym.clone(), + ident: sym.clone().dummy_spanned(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Mod(reexport_mod), @@ -471,7 +471,7 @@ fn mk_std(cx: &TestCtxt) -> P { }; P(ast::Item { id: ast::DUMMY_NODE_ID, - ident: ident, + ident: ident.dummy_spanned(), node: vi, attrs: vec![], vis: vis, @@ -511,7 +511,7 @@ fn mk_main(cx: &mut TestCtxt) -> P { dummy_spanned(ast::Constness::NotConst), ::abi::Abi::Rust, ast::Generics::default(), main_body); let main = P(ast::Item { - ident: Ident::from_str("main"), + ident: Ident::from_str("main").dummy_spanned(), attrs: vec![main_attr], id: ast::DUMMY_NODE_ID, node: main, @@ -543,7 +543,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option>) { let mut expander = cx.ext_cx.monotonic_expander(); let item = expander.fold_item(P(ast::Item { id: ast::DUMMY_NODE_ID, - ident: mod_ident, + ident: mod_ident.dummy_spanned(), attrs: vec![], node: item_, vis: ast::Visibility::Public, @@ -559,7 +559,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option>) { expander.fold_item(P(ast::Item { id: ast::DUMMY_NODE_ID, - ident: keywords::Invalid.ident(), + ident: keywords::Invalid.ident().dummy_spanned(), attrs: vec![], node: ast::ItemKind::Use(P(use_path)), vis: ast::Visibility::Inherited, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 3e0353d532d88..8cf2b04e014ba 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -220,7 +220,7 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_vis(&item.vis); - visitor.visit_ident(item.span, item.ident); + visitor.visit_ident(item.span, item.ident.node); match item.node { ItemKind::ExternCrate(opt_name) => { walk_opt_name(visitor, item.span, opt_name) @@ -248,7 +248,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_expr(expr); } ItemKind::Fn(ref declaration, unsafety, constness, abi, ref generics, ref body) => { - visitor.visit_fn(FnKind::ItemFn(item.ident, generics, unsafety, + visitor.visit_fn(FnKind::ItemFn(item.ident.node, generics, unsafety, constness, abi, &item.vis, body), declaration, item.span, @@ -284,7 +284,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { ItemKind::Struct(ref struct_definition, ref generics) | ItemKind::Union(ref struct_definition, ref generics) => { visitor.visit_generics(generics); - visitor.visit_variant_data(struct_definition, item.ident, + visitor.visit_variant_data(struct_definition, item.ident.node, generics, item.id, item.span); } ItemKind::Trait(_, ref generics, ref bounds, ref methods) => { @@ -310,8 +310,8 @@ pub fn walk_variant<'a, V>(visitor: &mut V, item_id: NodeId) where V: Visitor<'a>, { - visitor.visit_ident(variant.span, variant.node.name); - visitor.visit_variant_data(&variant.node.data, variant.node.name, + visitor.visit_ident(variant.span, variant.node.name.node); + visitor.visit_variant_data(&variant.node.data, variant.node.name.node, generics, item_id, variant.span); walk_list!(visitor, visit_expr, &variant.node.disr_expr); walk_list!(visitor, visit_attribute, &variant.node.attrs); @@ -553,7 +553,7 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl } pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a TraitItem) { - visitor.visit_ident(trait_item.span, trait_item.ident); + visitor.visit_ident(trait_item.span, trait_item.ident.node); walk_list!(visitor, visit_attribute, &trait_item.attrs); match trait_item.node { TraitItemKind::Const(ref ty, ref default) => { @@ -565,7 +565,7 @@ pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a Trai walk_fn_decl(visitor, &sig.decl); } TraitItemKind::Method(ref sig, Some(ref body)) => { - visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None, body), + visitor.visit_fn(FnKind::Method(trait_item.ident.node, sig, None, body), &sig.decl, trait_item.span, trait_item.id); } TraitItemKind::Type(ref bounds, ref default) => { @@ -580,7 +580,7 @@ pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a Trai pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplItem) { visitor.visit_vis(&impl_item.vis); - visitor.visit_ident(impl_item.span, impl_item.ident); + visitor.visit_ident(impl_item.span, impl_item.ident.node); walk_list!(visitor, visit_attribute, &impl_item.attrs); match impl_item.node { ImplItemKind::Const(ref ty, ref expr) => { @@ -588,7 +588,7 @@ pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplIt visitor.visit_expr(expr); } ImplItemKind::Method(ref sig, ref body) => { - visitor.visit_fn(FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), body), + visitor.visit_fn(FnKind::Method(impl_item.ident.node, sig, Some(&impl_item.vis), body), &sig.decl, impl_item.span, impl_item.id); } ImplItemKind::Type(ref ty) => { diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index d14b59d6c70e2..d0ed40b220da5 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -168,7 +168,7 @@ fn cs_clone(name: &str, vdata = vdata_; } EnumMatching(_, variant, ref af) => { - ctor_path = cx.path(trait_span, vec![substr.type_ident, variant.node.name]); + ctor_path = cx.path(trait_span, vec![substr.type_ident, variant.node.name.node]); all_fields = af; vdata = &variant.node.data; } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index a767716466cb1..2929fa9bb949c 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -60,7 +60,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P (substr.type_ident, vdata.is_struct()), - EnumMatching(_, v, _) => (v.node.name, v.node.data.is_struct()), + EnumMatching(_, v, _) => (v.node.name.node, v.node.data.is_struct()), EnumNonMatchingCollapsed(..) | StaticStruct(..) | StaticEnum(..) => cx.span_bug(span, "nonsensical .fields in `#[derive(Debug)]`"), diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs index 092738ab8a03d..66d965588e5cc 100644 --- a/src/libsyntax_ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -265,7 +265,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, } let blk = cx.lambda_stmts_1(trait_span, stmts, blkarg); - let name = cx.expr_str(trait_span, variant.node.name.name); + let name = cx.expr_str(trait_span, variant.node.name.node.name); let call = cx.expr_method_call(trait_span, blkencoder, cx.ident_of("emit_enum_variant"), diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 51199819dfcd7..ab2ac4a5b186d 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -414,15 +414,19 @@ impl<'a> TraitDef<'a> { Annotatable::Item(ref item) => { let newitem = match item.node { ast::ItemKind::Struct(ref struct_def, ref generics) => { - self.expand_struct_def(cx, &struct_def, item.ident, generics, from_scratch) + self.expand_struct_def(cx, + &struct_def, + item.ident.node, + generics, + from_scratch) } ast::ItemKind::Enum(ref enum_def, ref generics) => { self.expand_enum_def(cx, enum_def, &item.attrs, - item.ident, generics, from_scratch) + item.ident.node, generics, from_scratch) } ast::ItemKind::Union(ref struct_def, ref generics) => { if self.supports_unions { - self.expand_struct_def(cx, &struct_def, item.ident, + self.expand_struct_def(cx, &struct_def, item.ident.node, generics, from_scratch) } else { cx.span_err(mitem.span, @@ -502,7 +506,7 @@ impl<'a> TraitDef<'a> { ast::ImplItem { id: ast::DUMMY_NODE_ID, span: self.span, - ident: ident, + ident: ident.dummy_spanned(), vis: ast::Visibility::Inherited, defaultness: ast::Defaultness::Final, attrs: Vec::new(), @@ -921,7 +925,7 @@ impl<'a> MethodDef<'a> { span: trait_.span, vis: ast::Visibility::Inherited, defaultness: ast::Defaultness::Final, - ident: method_ident, + ident: method_ident.dummy_spanned(), node: ast::ImplItemKind::Method(ast::MethodSig { generics: fn_generics, abi: abi, @@ -1459,7 +1463,7 @@ impl<'a> MethodDef<'a> { let summary = enum_def.variants .iter() .map(|v| { - let ident = v.node.name; + let ident = v.node.name.node; let sp = Span { expn_id: trait_.span.expn_id, ..v.span }; let summary = trait_.summarise_struct(cx, &v.node.data); (ident, sp, summary) @@ -1578,7 +1582,7 @@ impl<'a> TraitDef<'a> { -> (P, Vec<(Span, Option, P, &'a [ast::Attribute])>) { let variant_ident = variant.node.name; let sp = Span { expn_id: self.span.expn_id, ..variant.span }; - let variant_path = cx.path(sp, vec![enum_ident, variant_ident]); + let variant_path = cx.path(sp, vec![enum_ident, variant_ident.node]); self.create_struct_pattern(cx, variant_path, &variant.node.data, prefix, mutbl) } } diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs index 8fbd11a7a6e03..ba9b9a578630e 100644 --- a/src/libsyntax_ext/proc_macro_registrar.rs +++ b/src/libsyntax_ext/proc_macro_registrar.rs @@ -231,7 +231,7 @@ impl<'a> Visitor<'a> for CollectCustomDerives<'a> { self.derives.push(CustomDerive { span: item.span, trait_name: trait_name, - function_name: item.ident, + function_name: item.ident.node, attrs: proc_attrs, }); } else { diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs index 490aa0d469312..6b3ce442c3a56 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs @@ -36,7 +36,7 @@ impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { - match &*it.name.as_str() { + match &*it.name.node.as_str() { "lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"), "pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"), _ => {} diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs index 8647797270f9a..29e84128b9300 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs @@ -36,7 +36,7 @@ impl LintPass for Pass { impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { - if it.ident.name == "lintme" { + if it.ident.node.name == "lintme" { cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); } } diff --git a/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs b/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs index dc88bfc40595f..7ae1aa2a89b08 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/macro_crate_test.rs @@ -18,6 +18,7 @@ extern crate rustc; extern crate rustc_plugin; use syntax::ast::{self, Item, MetaItem, ItemKind}; +use syntax::codemap::dummy_spanned; use syntax::ext::base::*; use syntax::parse; use syntax::ptr::P; @@ -122,19 +123,19 @@ fn expand_duplicate(cx: &mut ExtCtxt, Annotatable::Item(it) => { let mut new_it = (*it).clone(); new_it.attrs.clear(); - new_it.ident = copy_name; + new_it.ident = dummy_spanned(copy_name); push(Annotatable::Item(P(new_it))); } Annotatable::ImplItem(it) => { let mut new_it = (*it).clone(); new_it.attrs.clear(); - new_it.ident = copy_name; + new_it.ident = dummy_spanned(copy_name); push(Annotatable::ImplItem(P(new_it))); } Annotatable::TraitItem(tt) => { let mut new_it = (*tt).clone(); new_it.attrs.clear(); - new_it.ident = copy_name; + new_it.ident = dummy_spanned(copy_name); push(Annotatable::TraitItem(P(new_it))); } } diff --git a/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs b/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs index 490aa0d469312..6b3ce442c3a56 100644 --- a/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs +++ b/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs @@ -36,7 +36,7 @@ impl LintPass for Pass { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { - match &*it.name.as_str() { + match &*it.name.node.as_str() { "lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"), "pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"), _ => {} diff --git a/src/test/run-pass-fulldeps/auxiliary/lint_plugin_test.rs b/src/test/run-pass-fulldeps/auxiliary/lint_plugin_test.rs index 8647797270f9a..29e84128b9300 100644 --- a/src/test/run-pass-fulldeps/auxiliary/lint_plugin_test.rs +++ b/src/test/run-pass-fulldeps/auxiliary/lint_plugin_test.rs @@ -36,7 +36,7 @@ impl LintPass for Pass { impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { - if it.ident.name == "lintme" { + if it.ident.node.name == "lintme" { cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); } } diff --git a/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs b/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs index 29cc6b7db9474..6964abfdaeeec 100644 --- a/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs +++ b/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs @@ -18,7 +18,7 @@ extern crate rustc_plugin; extern crate syntax_pos; use syntax::ast::{self, Item, MetaItem, ItemKind}; -use syntax::codemap::DUMMY_SP; +use syntax::codemap::{DUMMY_SP, dummy_spanned}; use syntax::ext::base::*; use syntax::ext::quote::rt::ToTokens; use syntax::parse::{self, token}; @@ -128,19 +128,19 @@ fn expand_duplicate(cx: &mut ExtCtxt, Annotatable::Item(it) => { let mut new_it = (*it).clone(); new_it.attrs.clear(); - new_it.ident = copy_name; + new_it.ident = dummy_spanned(copy_name); push(Annotatable::Item(P(new_it))); } Annotatable::ImplItem(it) => { let mut new_it = (*it).clone(); new_it.attrs.clear(); - new_it.ident = copy_name; + new_it.ident = dummy_spanned(copy_name); push(Annotatable::ImplItem(P(new_it))); } Annotatable::TraitItem(tt) => { let mut new_it = (*tt).clone(); new_it.attrs.clear(); - new_it.ident = copy_name; + new_it.ident = dummy_spanned(copy_name); push(Annotatable::TraitItem(P(new_it))); } }