Skip to content

Commit d7551df

Browse files
committed
Change hir::Item.name to Spanned
1 parent 09905b1 commit d7551df

File tree

20 files changed

+59
-58
lines changed

20 files changed

+59
-58
lines changed

src/librustc/hir/fold.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use hir::*;
1515
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_};
1616
use syntax::ast::{NestedMetaItem, NestedMetaItemKind, MetaItem, MetaItemKind};
1717
use hir;
18-
use syntax_pos::Span;
18+
use syntax_pos::{DUMMY_SP, Span};
1919
use syntax::codemap::{respan, Spanned};
2020
use syntax::ptr::P;
2121
use syntax::parse::token::keywords;
@@ -850,7 +850,7 @@ pub fn noop_fold_crate<T: Folder>(Crate { module, attrs, config, span,
850850
let config = folder.fold_meta_items(config);
851851

852852
let crate_mod = folder.fold_item(hir::Item {
853-
name: keywords::Invalid.name(),
853+
name: respan(DUMMY_SP, keywords::Invalid.name()),
854854
attrs: attrs,
855855
id: DUMMY_NODE_ID,
856856
vis: hir::Public,
@@ -894,7 +894,7 @@ pub fn noop_fold_item<T: Folder>(item: Item, folder: &mut T) -> Item {
894894

895895
Item {
896896
id: id,
897-
name: folder.fold_name(name),
897+
name: respan(name.span, folder.fold_name(name.node)),
898898
attrs: fold_attrs(attrs, folder),
899899
node: node,
900900
vis: vis,

src/librustc/hir/intravisit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
276276

277277
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
278278
visitor.visit_vis(&item.vis);
279-
visitor.visit_name(item.span, item.name);
279+
visitor.visit_name(item.span, item.name.node);
280280
match item.node {
281281
ItemExternCrate(opt_name) => {
282282
visitor.visit_id(item.id);
@@ -307,7 +307,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
307307
visitor.visit_expr(expr);
308308
}
309309
ItemFn(ref declaration, unsafety, constness, abi, ref generics, ref body) => {
310-
visitor.visit_fn(FnKind::ItemFn(item.name,
310+
visitor.visit_fn(FnKind::ItemFn(item.name.node,
311311
generics,
312312
unsafety,
313313
constness,
@@ -352,7 +352,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
352352
ItemUnion(ref struct_definition, ref generics) => {
353353
visitor.visit_generics(generics);
354354
visitor.visit_id(item.id);
355-
visitor.visit_variant_data(struct_definition, item.name, generics, item.id, item.span);
355+
visitor.visit_variant_data(struct_definition, item.name.node, generics, item.id, item.span);
356356
}
357357
ItemTrait(_, ref generics, ref bounds, ref methods) => {
358358
visitor.visit_id(item.id);

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ use syntax::codemap::{respan, Spanned};
5656
use syntax::parse::token;
5757
use syntax::std_inject;
5858
use syntax::visit::{self, Visitor};
59-
use syntax_pos::Span;
59+
use syntax_pos::{Span, BytePos};
60+
use syntax::codemap::{spanned};
6061

6162
pub struct LoweringContext<'a> {
6263
crate_root: Option<&'static str>,
@@ -752,7 +753,7 @@ impl<'a> LoweringContext<'a> {
752753

753754
hir::Item {
754755
id: i.id,
755-
name: i.ident.name,
756+
name: spanned(BytePos(0), BytePos(0), i.ident.name),
756757
attrs: self.lower_attrs(&i.attrs),
757758
node: node,
758759
vis: self.lower_visibility(&i.vis),

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a> FnLikeNode<'a> {
225225
ast::ItemFn(ref decl, unsafety, constness, abi, ref generics, ref block) =>
226226
item_fn(ItemFnParts {
227227
id: i.id,
228-
name: i.name,
228+
name: i.name.node,
229229
decl: &decl,
230230
unsafety: unsafety,
231231
body: &block,

src/librustc/hir/map/def_collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ impl<'ast> intravisit::Visitor<'ast> for DefCollector<'ast> {
305305
hir::ItemEnum(..) | hir::ItemStruct(..) | hir::ItemUnion(..) |
306306
hir::ItemTrait(..) | hir::ItemExternCrate(..) | hir::ItemMod(..) |
307307
hir::ItemForeignMod(..) | hir::ItemTy(..) =>
308-
DefPathData::TypeNs(i.name.as_str()),
308+
DefPathData::TypeNs(i.name.node.as_str()),
309309
hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) =>
310-
DefPathData::ValueNs(i.name.as_str()),
310+
DefPathData::ValueNs(i.name.node.as_str()),
311311
hir::ItemUse(..) => DefPathData::Misc,
312312
};
313313
let def = self.create_def(i.id, def_data);

src/librustc/hir/map/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl<'ast> Map<'ast> {
632632
/// Returns the name associated with the given NodeId's AST.
633633
pub fn name(&self, id: NodeId) -> Name {
634634
match self.get(id) {
635-
NodeItem(i) => i.name,
635+
NodeItem(i) => i.name.node,
636636
NodeForeignItem(i) => i.name,
637637
NodeImplItem(ii) => ii.name,
638638
NodeTraitItem(ti) => ti.name,
@@ -770,7 +770,7 @@ impl<'a, 'ast> NodesMatchingSuffix<'a, 'ast> {
770770
match map.find(id) {
771771
None => return None,
772772
Some(NodeItem(item)) if item_is_mod(&item) =>
773-
return Some((id, item.name)),
773+
return Some((id, item.name.node)),
774774
_ => {}
775775
}
776776
let parent = map.get_parent(id);
@@ -826,7 +826,7 @@ trait Named {
826826

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

829-
impl Named for Item { fn name(&self) -> Name { self.name } }
829+
impl Named for Item { fn name(&self) -> Name { self.name.node } }
830830
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
831831
impl Named for Variant_ { fn name(&self) -> Name { self.name } }
832832
impl Named for TraitItem { fn name(&self) -> Name { self.name } }

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ pub struct ItemId {
14501450
/// The name might be a dummy name in case of anonymous items
14511451
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
14521452
pub struct Item {
1453-
pub name: Name,
1453+
pub name: Spanned<Name>,
14541454
pub attrs: HirVec<Attribute>,
14551455
pub id: NodeId,
14561456
pub node: Item_,

src/librustc/hir/print.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'a> State<'a> {
662662
word(&mut self.s, "as")?;
663663
space(&mut self.s)?;
664664
}
665-
self.print_name(item.name)?;
665+
self.print_name(item.name.node)?;
666666
word(&mut self.s, ";")?;
667667
self.end()?; // end inner head-block
668668
self.end()?; // end outer head-block
@@ -679,7 +679,7 @@ impl<'a> State<'a> {
679679
if m == hir::MutMutable {
680680
self.word_space("mut")?;
681681
}
682-
self.print_name(item.name)?;
682+
self.print_name(item.name.node)?;
683683
self.word_space(":")?;
684684
self.print_type(&ty)?;
685685
space(&mut self.s)?;
@@ -692,7 +692,7 @@ impl<'a> State<'a> {
692692
}
693693
hir::ItemConst(ref ty, ref expr) => {
694694
self.head(&visibility_qualified(&item.vis, "const"))?;
695-
self.print_name(item.name)?;
695+
self.print_name(item.name.node)?;
696696
self.word_space(":")?;
697697
self.print_type(&ty)?;
698698
space(&mut self.s)?;
@@ -709,15 +709,15 @@ impl<'a> State<'a> {
709709
unsafety,
710710
constness,
711711
abi,
712-
Some(item.name),
712+
Some(item.name.node),
713713
typarams,
714714
&item.vis)?;
715715
word(&mut self.s, " ")?;
716716
self.print_block_with_attrs(&body, &item.attrs)?;
717717
}
718718
hir::ItemMod(ref _mod) => {
719719
self.head(&visibility_qualified(&item.vis, "mod"))?;
720-
self.print_name(item.name)?;
720+
self.print_name(item.name.node)?;
721721
self.nbsp()?;
722722
self.bopen()?;
723723
self.print_mod(_mod, &item.attrs)?;
@@ -734,7 +734,7 @@ impl<'a> State<'a> {
734734
self.ibox(indent_unit)?;
735735
self.ibox(0)?;
736736
self.word_nbsp(&visibility_qualified(&item.vis, "type"))?;
737-
self.print_name(item.name)?;
737+
self.print_name(item.name.node)?;
738738
self.print_generics(params)?;
739739
self.end()?; // end the inner ibox
740740

@@ -746,15 +746,15 @@ impl<'a> State<'a> {
746746
self.end()?; // end the outer ibox
747747
}
748748
hir::ItemEnum(ref enum_definition, ref params) => {
749-
self.print_enum_def(enum_definition, params, item.name, item.span, &item.vis)?;
749+
self.print_enum_def(enum_definition, params, item.name.node, item.span, &item.vis)?;
750750
}
751751
hir::ItemStruct(ref struct_def, ref generics) => {
752752
self.head(&visibility_qualified(&item.vis, "struct"))?;
753-
self.print_struct(struct_def, generics, item.name, item.span, true)?;
753+
self.print_struct(struct_def, generics, item.name.node, item.span, true)?;
754754
}
755755
hir::ItemUnion(ref struct_def, ref generics) => {
756756
self.head(&visibility_qualified(&item.vis, "union"))?;
757-
self.print_struct(struct_def, generics, item.name, item.span, true)?;
757+
self.print_struct(struct_def, generics, item.name.node, item.span, true)?;
758758
}
759759
hir::ItemDefaultImpl(unsafety, ref trait_ref) => {
760760
self.head("")?;
@@ -816,7 +816,7 @@ impl<'a> State<'a> {
816816
self.print_visibility(&item.vis)?;
817817
self.print_unsafety(unsafety)?;
818818
self.word_nbsp("trait")?;
819-
self.print_name(item.name)?;
819+
self.print_name(item.name.node)?;
820820
self.print_generics(generics)?;
821821
let mut real_bounds = Vec::with_capacity(bounds.len());
822822
for b in bounds.iter() {

src/librustc/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
989989
ast_map::NodeItem(ref item) => {
990990
match item.node {
991991
hir::ItemFn(ref fn_decl, unsafety, constness, _, ref gen, _) => {
992-
Some((fn_decl, gen, unsafety, constness, item.name, item.span))
992+
Some((fn_decl, gen, unsafety, constness, item.name.node, item.span))
993993
},
994994
_ => None
995995
}

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
519519
self.warn_dead_code(
520520
item.id,
521521
item.span,
522-
item.name,
522+
item.name.node,
523523
item.node.descriptive_variant()
524524
);
525525
} else {

src/librustc/middle/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
8888
EntryPointType::Start
8989
} else if attr::contains_name(&item.attrs, "main") {
9090
EntryPointType::MainAttr
91-
} else if item.name.as_str() == "main" {
91+
} else if item.name.node.as_str() == "main" {
9292
if at_root {
9393
// This is a top-level function so can be 'main'
9494
EntryPointType::MainNamed

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
458458
// When compiling with --test we don't enforce stability on the
459459
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
460460
// name `__test`
461-
if item.span == DUMMY_SP && item.name.as_str() == "__test" { return }
461+
if item.span == DUMMY_SP && item.name.node.as_str() == "__test" { return }
462462

463463
check_item(self.tcx, item, true,
464464
&mut |id, sp, stab, depr| self.check(id, sp, stab, depr));

src/librustc_lint/bad_style.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ impl LateLintPass for NonCamelCaseTypes {
112112

113113
match it.node {
114114
hir::ItemTy(..) | hir::ItemStruct(..) | hir::ItemUnion(..) => {
115-
self.check_case(cx, "type", it.name, it.span)
115+
self.check_case(cx, "type", it.name.node, it.span)
116116
}
117117
hir::ItemTrait(..) => {
118-
self.check_case(cx, "trait", it.name, it.span)
118+
self.check_case(cx, "trait", it.name.node, it.span)
119119
}
120120
hir::ItemEnum(ref enum_definition, _) => {
121121
if has_extern_repr {
122122
return;
123123
}
124-
self.check_case(cx, "type", it.name, it.span);
124+
self.check_case(cx, "type", it.name.node, it.span);
125125
for variant in &enum_definition.variants {
126126
self.check_case(cx, "variant", variant.node.name, variant.span);
127127
}
@@ -257,7 +257,7 @@ impl LateLintPass for NonSnakeCase {
257257

258258
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
259259
if let hir::ItemMod(_) = it.node {
260-
self.check_snake_case(cx, "module", &it.name.as_str(), Some(it.span));
260+
self.check_snake_case(cx, "module", &it.name.node.as_str(), Some(it.span));
261261
}
262262
}
263263

@@ -329,10 +329,10 @@ impl LateLintPass for NonUpperCaseGlobals {
329329
match it.node {
330330
// only check static constants
331331
hir::ItemStatic(_, hir::MutImmutable, _) => {
332-
NonUpperCaseGlobals::check_upper_case(cx, "static constant", it.name, it.span);
332+
NonUpperCaseGlobals::check_upper_case(cx, "static constant", it.name.node, it.span);
333333
}
334334
hir::ItemConst(..) => {
335-
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name, it.span);
335+
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name.node, it.span);
336336
}
337337
_ => {}
338338
}

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ impl LateLintPass for InvalidNoMangleItems {
10411041
if attr::contains_name(&it.attrs, "no_mangle") {
10421042
if !cx.access_levels.is_reachable(it.id) {
10431043
let msg = format!("function {} is marked #[no_mangle], but not exported",
1044-
it.name);
1044+
it.name.node);
10451045
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, &msg);
10461046
}
10471047
if generics.is_parameterized() {
@@ -1055,7 +1055,7 @@ impl LateLintPass for InvalidNoMangleItems {
10551055
if attr::contains_name(&it.attrs, "no_mangle") &&
10561056
!cx.access_levels.is_reachable(it.id) {
10571057
let msg = format!("static {} is marked #[no_mangle], but not exported",
1058-
it.name);
1058+
it.name.node);
10591059
cx.span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, &msg);
10601060
}
10611061
},

src/librustc_metadata/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn decode_inlined_item<'a, 'tcx>(cdata: &cstore::CrateMetadata,
145145
decode_ast(ast_doc),
146146
dcx);
147147
let name = match *ii {
148-
InlinedItem::Item(_, ref i) => i.name,
148+
InlinedItem::Item(_, ref i) => i.name.node,
149149
InlinedItem::TraitItem(_, ref ti) => ti.name,
150150
InlinedItem::ImplItem(_, ref ii) => ii.name
151151
};

0 commit comments

Comments
 (0)