Skip to content

Commit 55ede7e

Browse files
committed
Auto merge of #27234 - oli-obk:move_get_name_get_ident_to_impl, r=eddyb
this has quite some fallout. but also made lots of stuff more readable imo [breaking-change] for plugin authors
2 parents ba9224f + 00a5e66 commit 55ede7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+433
-534
lines changed

src/doc/trpl/compiler-plugins.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
6161
("I", 1)];
6262
6363
let text = match args {
64-
[TtToken(_, token::Ident(s, _))] => token::get_ident(s).to_string(),
64+
[TtToken(_, token::Ident(s, _))] => s.to_string(),
6565
_ => {
6666
cx.span_err(sp, "argument should be a single identifier");
6767
return DummyResult::any(sp);
@@ -186,8 +186,7 @@ impl LintPass for Pass {
186186
}
187187
188188
fn check_item(&mut self, cx: &Context, it: &ast::Item) {
189-
let name = token::get_ident(it.ident);
190-
if name.get() == "lintme" {
189+
if it.ident.name == "lintme" {
191190
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
192191
}
193192
}

src/librustc/ast_map/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ impl PathElem {
4747

4848
impl fmt::Display for PathElem {
4949
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50-
let slot = token::get_name(self.name());
51-
write!(f, "{}", slot)
50+
write!(f, "{}", self.name())
5251
}
5352
}
5453

@@ -1073,18 +1072,18 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
10731072
match ii.node {
10741073
ConstImplItem(..) => {
10751074
format!("assoc const {} in {}{}",
1076-
token::get_ident(ii.ident),
1075+
ii.ident,
10771076
map.path_to_string(id),
10781077
id_str)
10791078
}
10801079
MethodImplItem(..) => {
10811080
format!("method {} in {}{}",
1082-
token::get_ident(ii.ident),
1081+
ii.ident,
10831082
map.path_to_string(id), id_str)
10841083
}
10851084
TypeImplItem(_) => {
10861085
format!("assoc type {} in {}{}",
1087-
token::get_ident(ii.ident),
1086+
ii.ident,
10881087
map.path_to_string(id),
10891088
id_str)
10901089
}
@@ -1103,13 +1102,13 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
11031102

11041103
format!("{} {} in {}{}",
11051104
kind,
1106-
token::get_ident(ti.ident),
1105+
ti.ident,
11071106
map.path_to_string(id),
11081107
id_str)
11091108
}
11101109
Some(NodeVariant(ref variant)) => {
11111110
format!("variant {} in {}{}",
1112-
token::get_ident(variant.node.name),
1111+
variant.node.name,
11131112
map.path_to_string(id), id_str)
11141113
}
11151114
Some(NodeExpr(ref expr)) => {

src/librustc/metadata/creader.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use syntax::attr::AttrMetaMethods;
3333
use syntax::codemap::{self, Span, mk_sp, Pos};
3434
use syntax::parse;
3535
use syntax::parse::token::InternedString;
36-
use syntax::parse::token;
3736
use syntax::visit;
3837
use log;
3938

@@ -181,19 +180,18 @@ impl<'a> CrateReader<'a> {
181180
fn extract_crate_info(&self, i: &ast::Item) -> Option<CrateInfo> {
182181
match i.node {
183182
ast::ItemExternCrate(ref path_opt) => {
184-
let ident = token::get_ident(i.ident);
185183
debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
186-
ident, path_opt);
184+
i.ident, path_opt);
187185
let name = match *path_opt {
188186
Some(name) => {
189-
validate_crate_name(Some(self.sess), name.as_str(),
187+
validate_crate_name(Some(self.sess), &name.as_str(),
190188
Some(i.span));
191-
name.as_str().to_string()
189+
name.to_string()
192190
}
193-
None => ident.to_string(),
191+
None => i.ident.to_string(),
194192
};
195193
Some(CrateInfo {
196-
ident: ident.to_string(),
194+
ident: i.ident.to_string(),
197195
name: name,
198196
id: i.id,
199197
should_link: should_link(i),

src/librustc/metadata/encoder.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use syntax::attr;
4040
use syntax::attr::AttrMetaMethods;
4141
use syntax::diagnostic::SpanHandler;
4242
use syntax::parse::token::special_idents;
43-
use syntax::parse::token;
4443
use syntax::print::pprust;
4544
use syntax::ptr::P;
4645
use syntax::visit::Visitor;
@@ -83,11 +82,11 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
8382
}
8483

8584
fn encode_name(rbml_w: &mut Encoder, name: ast::Name) {
86-
rbml_w.wr_tagged_str(tag_paths_data_name, &token::get_name(name));
85+
rbml_w.wr_tagged_str(tag_paths_data_name, &name.as_str());
8786
}
8887

8988
fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Name) {
90-
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &token::get_name(name));
89+
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &name.as_str());
9190
}
9291

9392
fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
@@ -349,7 +348,7 @@ fn encode_path<PI: Iterator<Item=PathElem>>(rbml_w: &mut Encoder, path: PI) {
349348
ast_map::PathMod(_) => tag_path_elem_mod,
350349
ast_map::PathName(_) => tag_path_elem_name
351350
};
352-
rbml_w.wr_tagged_str(tag, &token::get_name(pe.name()));
351+
rbml_w.wr_tagged_str(tag, &pe.name().as_str());
353352
}
354353
rbml_w.end_tag();
355354
}
@@ -359,13 +358,13 @@ fn encode_reexported_static_method(rbml_w: &mut Encoder,
359358
method_def_id: DefId,
360359
method_name: ast::Name) {
361360
debug!("(encode reexported static method) {}::{}",
362-
exp.name, token::get_name(method_name));
361+
exp.name, method_name);
363362
rbml_w.start_tag(tag_items_data_item_reexport);
364363
rbml_w.wr_tagged_u64(tag_items_data_item_reexport_def_id,
365364
def_to_u64(method_def_id));
366365
rbml_w.wr_tagged_str(tag_items_data_item_reexport_name,
367366
&format!("{}::{}", exp.name,
368-
token::get_name(method_name)));
367+
method_name));
369368
rbml_w.end_tag();
370369
}
371370

@@ -499,15 +498,12 @@ fn encode_reexports(ecx: &EncodeContext,
499498
rbml_w.wr_tagged_u64(tag_items_data_item_reexport_def_id,
500499
def_to_u64(exp.def_id));
501500
rbml_w.wr_tagged_str(tag_items_data_item_reexport_name,
502-
exp.name.as_str());
501+
&exp.name.as_str());
503502
rbml_w.end_tag();
504503
encode_reexported_static_methods(ecx, rbml_w, path.clone(), exp);
505504
}
506-
}
507-
None => {
508-
debug!("(encoding info for module) found no reexports for {}",
509-
id);
510-
}
505+
},
506+
None => debug!("(encoding info for module) found no reexports for {}", id),
511507
}
512508
}
513509

@@ -539,7 +535,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
539535
if let ast::ItemImpl(..) = item.node {
540536
let (ident, did) = (item.ident, item.id);
541537
debug!("(encoding info for module) ... encoding impl {} ({}/{})",
542-
token::get_ident(ident),
538+
ident,
543539
did, ecx.tcx.map.node_to_string(did));
544540

545541
rbml_w.wr_tagged_u64(tag_mod_impl, def_to_u64(local_def(did)));
@@ -656,7 +652,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
656652
});
657653
rbml_w.start_tag(tag_items_data_item);
658654
debug!("encode_info_for_struct: doing {} {}",
659-
token::get_name(nm), id);
655+
nm, id);
660656
encode_struct_field_family(rbml_w, field.vis);
661657
encode_name(rbml_w, nm);
662658
encode_bounds_and_type_for_item(rbml_w, ecx, id);
@@ -816,7 +812,7 @@ fn encode_info_for_associated_const(ecx: &EncodeContext,
816812
impl_item_opt: Option<&ast::ImplItem>) {
817813
debug!("encode_info_for_associated_const({:?},{:?})",
818814
associated_const.def_id,
819-
token::get_name(associated_const.name));
815+
associated_const.name);
820816

821817
rbml_w.start_tag(tag_items_data_item);
822818

@@ -854,7 +850,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
854850
impl_item_opt: Option<&ast::ImplItem>) {
855851

856852
debug!("encode_info_for_method: {:?} {:?}", m.def_id,
857-
token::get_name(m.name));
853+
m.name);
858854
rbml_w.start_tag(tag_items_data_item);
859855

860856
encode_method_ty_fields(ecx, rbml_w, m);
@@ -899,7 +895,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
899895
impl_item_opt: Option<&ast::ImplItem>) {
900896
debug!("encode_info_for_associated_type({:?},{:?})",
901897
associated_type.def_id,
902-
token::get_name(associated_type.name));
898+
associated_type.name);
903899

904900
rbml_w.start_tag(tag_items_data_item);
905901

@@ -937,7 +933,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
937933
for arg in &decl.inputs {
938934
let tag = tag_method_argument_name;
939935
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
940-
let name = token::get_name(path1.node.name);
936+
let name = path1.node.name.as_str();
941937
rbml_w.wr_tagged_bytes(tag, name.as_bytes());
942938
} else {
943939
rbml_w.wr_tagged_bytes(tag, &[]);
@@ -1562,7 +1558,7 @@ fn my_visit_foreign_item(ni: &ast::ForeignItem,
15621558
index: &mut Vec<entry<i64>>) {
15631559
debug!("writing foreign item {}::{}",
15641560
ecx.tcx.map.path_to_string(ni.id),
1565-
token::get_ident(ni.ident));
1561+
ni.ident);
15661562

15671563
let abi = ecx.tcx.map.get_foreign_abi(ni.id);
15681564
ecx.tcx.map.with_path(ni.id, |path| {
@@ -1748,7 +1744,7 @@ fn encode_defaulted(rbml_w: &mut Encoder, is_defaulted: bool) {
17481744
fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
17491745
rbml_w.start_tag(tag_associated_type_names);
17501746
for &name in names {
1751-
rbml_w.wr_tagged_str(tag_associated_type_name, &token::get_name(name));
1747+
rbml_w.wr_tagged_str(tag_associated_type_name, &name.as_str());
17521748
}
17531749
rbml_w.end_tag();
17541750
}

src/librustc/metadata/macro_import.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ impl<'a> MacroLoader<'a> {
149149
let mut seen = HashSet::new();
150150

151151
for mut def in macros {
152-
let name = token::get_ident(def.ident);
153-
seen.insert(name.clone());
152+
let name = def.ident.name.as_str();
154153

155154
def.use_locally = match import.as_ref() {
156155
None => true,
@@ -161,18 +160,19 @@ impl<'a> MacroLoader<'a> {
161160
"allow_internal_unstable");
162161
debug!("load_macros: loaded: {:?}", def);
163162
self.macros.push(def);
163+
seen.insert(name);
164164
}
165165

166166
if let Some(sel) = import.as_ref() {
167167
for (name, span) in sel {
168-
if !seen.contains(name) {
168+
if !seen.contains(&name) {
169169
self.sess.span_err(*span, "imported macro not found");
170170
}
171171
}
172172
}
173173

174174
for (name, span) in &reexport {
175-
if !seen.contains(name) {
175+
if !seen.contains(&name) {
176176
self.sess.span_err(*span, "reexported macro not found");
177177
}
178178
}

src/librustc/metadata/tyencode.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use util::nodemap::FnvHashMap;
2626
use syntax::abi::Abi;
2727
use syntax::ast;
2828
use syntax::diagnostic::SpanHandler;
29-
use syntax::parse::token;
3029

3130
use rbml::writer::Encoder;
3231

@@ -136,7 +135,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
136135
cx.diag.handler().bug("cannot encode inference variable types");
137136
}
138137
ty::TyParam(ParamTy {space, idx, name}) => {
139-
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), token::get_name(name))
138+
mywrite!(w, "p[{}|{}|{}]", idx, space.to_uint(), name)
140139
}
141140
ty::TyStruct(def, substs) => {
142141
mywrite!(w, "a[{}|", (cx.ds)(def));
@@ -155,7 +154,7 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
155154
ty::TyProjection(ref data) => {
156155
mywrite!(w, "P[");
157156
enc_trait_ref(w, cx, data.trait_ref);
158-
mywrite!(w, "{}]", token::get_name(data.item_name));
157+
mywrite!(w, "{}]", data.item_name);
159158
}
160159
ty::TyError => {
161160
mywrite!(w, "e");
@@ -251,7 +250,7 @@ pub fn enc_region(w: &mut Encoder, cx: &ctxt, r: ty::Region) {
251250
data.param_id,
252251
data.space.to_uint(),
253252
data.index,
254-
token::get_name(data.name));
253+
data.name);
255254
}
256255
ty::ReFree(ref fr) => {
257256
mywrite!(w, "f[");
@@ -302,7 +301,7 @@ fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
302301
ty::BrNamed(d, name) => {
303302
mywrite!(w, "[{}|{}]",
304303
(cx.ds)(d),
305-
token::get_name(name));
304+
name);
306305
}
307306
ty::BrFresh(id) => {
308307
mywrite!(w, "f{}|", id);
@@ -410,7 +409,7 @@ pub fn enc_region_bounds<'a, 'tcx>(w: &mut Encoder,
410409
pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
411410
v: &ty::TypeParameterDef<'tcx>) {
412411
mywrite!(w, "{}:{}|{}|{}|{}|",
413-
token::get_name(v.name), (cx.ds)(v.def_id),
412+
v.name, (cx.ds)(v.def_id),
414413
v.space.to_uint(), v.index, (cx.ds)(v.default_def_id));
415414
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
416415
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
@@ -465,6 +464,6 @@ fn enc_projection_predicate<'a, 'tcx>(w: &mut Encoder,
465464
cx: &ctxt<'a, 'tcx>,
466465
data: &ty::ProjectionPredicate<'tcx>) {
467466
enc_trait_ref(w, cx, data.projection_ty.trait_ref);
468-
mywrite!(w, "{}|", token::get_name(data.projection_ty.item_name));
467+
mywrite!(w, "{}|", data.projection_ty.item_name);
469468
enc_ty(w, cx, data.ty);
470469
}

src/librustc/middle/astencode.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use middle::ty::{self, Ty};
3434
use syntax::{ast, ast_util, codemap, fold};
3535
use syntax::codemap::Span;
3636
use syntax::fold::Folder;
37-
use syntax::parse::token;
3837
use syntax::ptr::P;
3938
use syntax;
4039

@@ -156,10 +155,10 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
156155
ast::IITraitItem(_, ref ti) => ti.ident,
157156
ast::IIImplItem(_, ref ii) => ii.ident
158157
};
159-
debug!("Fn named: {}", token::get_ident(ident));
158+
debug!("Fn named: {}", ident);
160159
debug!("< Decoded inlined fn: {}::{}",
161160
path_as_str.unwrap(),
162-
token::get_ident(ident));
161+
ident);
163162
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii);
164163
decode_side_tables(dcx, ast_doc);
165164
match *ii {

src/librustc/middle/check_match.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use syntax::ast_util;
3535
use syntax::codemap::{Span, Spanned, DUMMY_SP};
3636
use syntax::fold::{Folder, noop_fold_pat};
3737
use syntax::print::pprust::pat_to_string;
38-
use syntax::parse::token;
3938
use syntax::ptr::P;
4039
use syntax::visit::{self, Visitor, FnKind};
4140
use util::nodemap::FnvHashMap;
@@ -239,17 +238,17 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
239238
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
240239
if let Some(DefLocal(_)) = def {
241240
if cx.tcx.enum_variants(def_id).iter().any(|variant|
242-
token::get_name(variant.name) == token::get_name(ident.node.name)
241+
variant.name == ident.node.name
243242
&& variant.args.is_empty()
244243
) {
245244
span_warn!(cx.tcx.sess, p.span, E0170,
246245
"pattern binding `{}` is named the same as one \
247246
of the variants of the type `{}`",
248-
&token::get_ident(ident.node), pat_ty);
247+
ident.node, pat_ty);
249248
fileline_help!(cx.tcx.sess, p.span,
250249
"if you meant to match on a variant, \
251250
consider making the path in the pattern qualified: `{}::{}`",
252-
pat_ty, &token::get_ident(ident.node));
251+
pat_ty, ident.node);
253252
}
254253
}
255254
}

src/librustc/middle/const_eval.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,9 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10361036
if let Struct(struct_id) = c {
10371037
if let ast::ExprStruct(_, ref fields, _) = tcx.map.expect_expr(struct_id).node {
10381038
// Check that the given field exists and evaluate it
1039-
if let Some(f) = fields.iter().find(|f| f.ident.node.as_str()
1040-
== field_name.node.as_str()) {
1039+
// if the idents are compared run-pass/issue-19244 fails
1040+
if let Some(f) = fields.iter().find(|f| f.ident.node.name
1041+
== field_name.node.name) {
10411042
return eval_const_expr_partial(tcx, &*f.expr, base_hint)
10421043
} else {
10431044
signal!(e, MissingStructField);

0 commit comments

Comments
 (0)