Skip to content

Commit 7ebf9bc

Browse files
committed
Auto merge of #21505 - GuillaumeGomez:interned_string, r=alexcrichton
It's in order to make the code more homogeneous.
2 parents d3732a1 + a2e01c6 commit 7ebf9bc

Some content is hidden

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

67 files changed

+295
-300
lines changed

src/librustc/lint/builtin.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ impl LintPass for UnusedAttributes {
699699

700700
if !attr::is_used(attr) {
701701
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
702-
if CRATE_ATTRS.contains(&attr.name().get()) {
702+
if CRATE_ATTRS.contains(&&attr.name()[]) {
703703
let msg = match attr.node.style {
704704
ast::AttrOuter => "crate-level attribute should be an inner \
705705
attribute: add an exclamation mark: #![foo]",
@@ -801,10 +801,10 @@ impl LintPass for UnusedResults {
801801
None => {}
802802
Some(s) => {
803803
msg.push_str(": ");
804-
msg.push_str(s.get());
804+
msg.push_str(&s);
805805
}
806806
}
807-
cx.span_lint(UNUSED_MUST_USE, sp, &msg[]);
807+
cx.span_lint(UNUSED_MUST_USE, sp, &msg);
808808
return true;
809809
}
810810
}
@@ -826,8 +826,8 @@ impl NonCamelCaseTypes {
826826
fn check_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
827827
fn is_camel_case(ident: ast::Ident) -> bool {
828828
let ident = token::get_ident(ident);
829-
if ident.get().is_empty() { return true; }
830-
let ident = ident.get().trim_matches('_');
829+
if ident.is_empty() { return true; }
830+
let ident = ident.trim_matches('_');
831831

832832
// start with a non-lowercase letter rather than non-uppercase
833833
// ones (some scripts don't have a concept of upper/lowercase)
@@ -844,7 +844,7 @@ impl NonCamelCaseTypes {
844844
let s = token::get_ident(ident);
845845

846846
if !is_camel_case(ident) {
847-
let c = to_camel_case(s.get());
847+
let c = to_camel_case(&s);
848848
let m = if c.is_empty() {
849849
format!("{} `{}` should have a camel case name such as `CamelCase`", sort, s)
850850
} else {
@@ -977,8 +977,8 @@ impl NonSnakeCase {
977977
fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
978978
fn is_snake_case(ident: ast::Ident) -> bool {
979979
let ident = token::get_ident(ident);
980-
if ident.get().is_empty() { return true; }
981-
let ident = ident.get().trim_left_matches('\'');
980+
if ident.is_empty() { return true; }
981+
let ident = ident.trim_left_matches('\'');
982982
let ident = ident.trim_matches('_');
983983

984984
let mut allow_underscore = true;
@@ -996,8 +996,8 @@ impl NonSnakeCase {
996996
let s = token::get_ident(ident);
997997

998998
if !is_snake_case(ident) {
999-
let sc = NonSnakeCase::to_snake_case(s.get());
1000-
if sc != s.get() {
999+
let sc = NonSnakeCase::to_snake_case(&s);
1000+
if sc != &s[] {
10011001
cx.span_lint(NON_SNAKE_CASE, span,
10021002
&*format!("{} `{}` should have a snake case name such as `{}`",
10031003
sort, s, sc));
@@ -1077,10 +1077,10 @@ impl NonUpperCaseGlobals {
10771077
fn check_upper_case(cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
10781078
let s = token::get_ident(ident);
10791079

1080-
if s.get().chars().any(|c| c.is_lowercase()) {
1081-
let uc: String = NonSnakeCase::to_snake_case(s.get()).chars()
1080+
if s.chars().any(|c| c.is_lowercase()) {
1081+
let uc: String = NonSnakeCase::to_snake_case(&s).chars()
10821082
.map(|c| c.to_uppercase()).collect();
1083-
if uc != s.get() {
1083+
if uc != &s[] {
10841084
cx.span_lint(NON_UPPER_CASE_GLOBALS, span,
10851085
&format!("{} `{}` should have an upper case name such as `{}`",
10861086
sort, s, uc));
@@ -1241,7 +1241,7 @@ impl LintPass for UnusedImportBraces {
12411241
match items[0].node {
12421242
ast::PathListIdent {ref name, ..} => {
12431243
let m = format!("braces around {} is unnecessary",
1244-
token::get_ident(*name).get());
1244+
&token::get_ident(*name));
12451245
cx.span_lint(UNUSED_IMPORT_BRACES, item.span,
12461246
&m[]);
12471247
},
@@ -1358,7 +1358,7 @@ impl UnusedMut {
13581358
pat_util::pat_bindings(&cx.tcx.def_map, &**p, |mode, id, _, path1| {
13591359
let ident = path1.node;
13601360
if let ast::BindByValue(ast::MutMutable) = mode {
1361-
if !token::get_ident(ident).get().starts_with("_") {
1361+
if !token::get_ident(ident).starts_with("_") {
13621362
match mutables.entry(ident.name.usize()) {
13631363
Vacant(entry) => { entry.insert(vec![id]); },
13641364
Occupied(mut entry) => { entry.get_mut().push(id); },

src/librustc/lint/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub fn gather_attrs(attrs: &[ast::Attribute])
341341
-> Vec<Result<(InternedString, Level, Span), Span>> {
342342
let mut out = vec!();
343343
for attr in attrs {
344-
let level = match Level::from_str(attr.name().get()) {
344+
let level = match Level::from_str(&attr.name()) {
345345
None => continue,
346346
Some(lvl) => lvl,
347347
};
@@ -499,10 +499,10 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
499499
continue;
500500
}
501501
Ok((lint_name, level, span)) => {
502-
match self.lints.find_lint(lint_name.get(), &self.tcx.sess, Some(span)) {
502+
match self.lints.find_lint(&lint_name, &self.tcx.sess, Some(span)) {
503503
Some(lint_id) => vec![(lint_id, level, span)],
504504
None => {
505-
match self.lints.lint_groups.get(lint_name.get()) {
505+
match self.lints.lint_groups.get(&lint_name[]) {
506506
Some(&(ref v, _)) => v.iter()
507507
.map(|lint_id: &LintId|
508508
(*lint_id, level, span))

src/librustc/metadata/creader.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> CrateReader<'a> {
170170
fn process_crate(&self, c: &ast::Crate) {
171171
for a in c.attrs.iter().filter(|m| m.name() == "link_args") {
172172
match a.value_str() {
173-
Some(ref linkarg) => self.sess.cstore.add_used_link_args(linkarg.get()),
173+
Some(ref linkarg) => self.sess.cstore.add_used_link_args(&linkarg),
174174
None => { /* fallthrough */ }
175175
}
176176
}
@@ -184,15 +184,15 @@ impl<'a> CrateReader<'a> {
184184
ident, path_opt);
185185
let name = match *path_opt {
186186
Some((ref path_str, _)) => {
187-
let name = path_str.get().to_string();
187+
let name = path_str.to_string();
188188
validate_crate_name(Some(self.sess), &name[],
189189
Some(i.span));
190190
name
191191
}
192-
None => ident.get().to_string(),
192+
None => ident.to_string(),
193193
};
194194
Some(CrateInfo {
195-
ident: ident.get().to_string(),
195+
ident: ident.to_string(),
196196
name: name,
197197
id: i.id,
198198
should_link: should_link(i),
@@ -237,7 +237,7 @@ impl<'a> CrateReader<'a> {
237237
.collect::<Vec<&ast::Attribute>>();
238238
for m in &link_args {
239239
match m.value_str() {
240-
Some(linkarg) => self.sess.cstore.add_used_link_args(linkarg.get()),
240+
Some(linkarg) => self.sess.cstore.add_used_link_args(&linkarg),
241241
None => { /* fallthrough */ }
242242
}
243243
}
@@ -289,7 +289,7 @@ impl<'a> CrateReader<'a> {
289289
}
290290
};
291291
register_native_lib(self.sess, Some(m.span),
292-
n.get().to_string(), kind);
292+
n.to_string(), kind);
293293
}
294294
None => {}
295295
}

src/librustc/metadata/csearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub fn is_staged_api(cstore: &cstore::CStore, def: ast::DefId) -> bool {
383383
let cdata = cstore.get_crate_data(def.krate);
384384
let attrs = decoder::get_crate_attributes(cdata.data());
385385
for attr in &attrs {
386-
if attr.name().get() == "staged_api" {
386+
if &attr.name()[] == "staged_api" {
387387
match attr.node.value.node { ast::MetaWord(_) => return true, _ => (/*pass*/) }
388388
}
389389
}

src/librustc/metadata/encoder.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
8686
}
8787

8888
fn encode_name(rbml_w: &mut Encoder, name: ast::Name) {
89-
rbml_w.wr_tagged_str(tag_paths_data_name, token::get_name(name).get());
89+
rbml_w.wr_tagged_str(tag_paths_data_name, &token::get_name(name));
9090
}
9191

9292
fn encode_impl_type_basename(rbml_w: &mut Encoder, name: ast::Ident) {
93-
rbml_w.wr_tagged_str(tag_item_impl_type_basename, token::get_ident(name).get());
93+
rbml_w.wr_tagged_str(tag_item_impl_type_basename, &token::get_ident(name));
9494
}
9595

9696
pub fn encode_def_id(rbml_w: &mut Encoder, id: DefId) {
@@ -372,7 +372,7 @@ fn encode_path<PI: Iterator<Item=PathElem>>(rbml_w: &mut Encoder, path: PI) {
372372
ast_map::PathMod(_) => tag_path_elem_mod,
373373
ast_map::PathName(_) => tag_path_elem_name
374374
};
375-
rbml_w.wr_tagged_str(tag, token::get_name(pe.name()).get());
375+
rbml_w.wr_tagged_str(tag, &token::get_name(pe.name()));
376376
}
377377
rbml_w.end_tag();
378378
}
@@ -915,7 +915,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
915915
rbml_w.start_tag(tag_method_argument_name);
916916
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
917917
let name = token::get_ident(path1.node);
918-
rbml_w.writer.write_all(name.get().as_bytes());
918+
rbml_w.writer.write_all(name.as_bytes());
919919
}
920920
rbml_w.end_tag();
921921
}
@@ -1636,7 +1636,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16361636
ast::MetaWord(ref name) => {
16371637
rbml_w.start_tag(tag_meta_item_word);
16381638
rbml_w.start_tag(tag_meta_item_name);
1639-
rbml_w.writer.write_all(name.get().as_bytes());
1639+
rbml_w.writer.write_all(name.as_bytes());
16401640
rbml_w.end_tag();
16411641
rbml_w.end_tag();
16421642
}
@@ -1645,10 +1645,10 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16451645
ast::LitStr(ref value, _) => {
16461646
rbml_w.start_tag(tag_meta_item_name_value);
16471647
rbml_w.start_tag(tag_meta_item_name);
1648-
rbml_w.writer.write_all(name.get().as_bytes());
1648+
rbml_w.writer.write_all(name.as_bytes());
16491649
rbml_w.end_tag();
16501650
rbml_w.start_tag(tag_meta_item_value);
1651-
rbml_w.writer.write_all(value.get().as_bytes());
1651+
rbml_w.writer.write_all(value.as_bytes());
16521652
rbml_w.end_tag();
16531653
rbml_w.end_tag();
16541654
}
@@ -1658,7 +1658,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16581658
ast::MetaList(ref name, ref items) => {
16591659
rbml_w.start_tag(tag_meta_item_list);
16601660
rbml_w.start_tag(tag_meta_item_name);
1661-
rbml_w.writer.write_all(name.get().as_bytes());
1661+
rbml_w.writer.write_all(name.as_bytes());
16621662
rbml_w.end_tag();
16631663
for inner_item in items {
16641664
encode_meta_item(rbml_w, &**inner_item);
@@ -1695,7 +1695,7 @@ fn encode_paren_sugar(rbml_w: &mut Encoder, paren_sugar: bool) {
16951695
fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
16961696
rbml_w.start_tag(tag_associated_type_names);
16971697
for &name in names {
1698-
rbml_w.wr_tagged_str(tag_associated_type_name, token::get_name(name).get());
1698+
rbml_w.wr_tagged_str(tag_associated_type_name, &token::get_name(name));
16991699
}
17001700
rbml_w.end_tag();
17011701
}

src/librustc/middle/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
249249
span_warn!(cx.tcx.sess, p.span, E0170,
250250
"pattern binding `{}` is named the same as one \
251251
of the variants of the type `{}`",
252-
token::get_ident(ident.node).get(), ty_to_string(cx.tcx, pat_ty));
252+
&token::get_ident(ident.node), ty_to_string(cx.tcx, pat_ty));
253253
span_help!(cx.tcx.sess, p.span,
254254
"if you meant to match on a variant, \
255255
consider making the path in the pattern qualified: `{}::{}`",
256-
ty_to_string(cx.tcx, pat_ty), token::get_ident(ident.node).get());
256+
ty_to_string(cx.tcx, pat_ty), &token::get_ident(ident.node));
257257
}
258258
}
259259
}

src/librustc/middle/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ pub fn lit_to_const(lit: &ast::Lit) -> const_val {
610610
ast::LitInt(n, ast::UnsignedIntLit(_)) => const_uint(n),
611611
ast::LitFloat(ref n, _) |
612612
ast::LitFloatUnsuffixed(ref n) => {
613-
const_float(n.get().parse::<f64>().unwrap() as f64)
613+
const_float(n.parse::<f64>().unwrap() as f64)
614614
}
615615
ast::LitBool(b) => const_bool(b)
616616
}

src/librustc/middle/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn has_allow_dead_code_or_lang_attr(attrs: &[ast::Attribute]) -> bool {
321321
for attr in lint::gather_attrs(attrs) {
322322
match attr {
323323
Ok((ref name, lint::Allow, _))
324-
if name.get() == dead_code => return true,
324+
if &name[] == dead_code => return true,
325325
_ => (),
326326
}
327327
}

src/librustc/middle/infer/error_reporting.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
514514
lifetime of captured variable `{}`...",
515515
ty::local_var_name_str(self.tcx,
516516
upvar_id.var_id)
517-
.get()
518517
.to_string());
519518
note_and_explain_region(
520519
self.tcx,
@@ -526,7 +525,6 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
526525
&format!("...but `{}` is only valid for ",
527526
ty::local_var_name_str(self.tcx,
528527
upvar_id.var_id)
529-
.get()
530528
.to_string())[],
531529
sup,
532530
"");
@@ -570,8 +568,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
570568
&format!("captured variable `{}` does not \
571569
outlive the enclosing closure",
572570
ty::local_var_name_str(self.tcx,
573-
id).get()
574-
.to_string())[]);
571+
id).to_string())[]);
575572
note_and_explain_region(
576573
self.tcx,
577574
"captured variable is valid for ",
@@ -959,7 +956,7 @@ impl<'a, 'tcx> Rebuilder<'a, 'tcx> {
959956
// choice of lifetime name deterministic and thus easier to test.
960957
let mut names = Vec::new();
961958
for rn in region_names {
962-
let lt_name = token::get_name(*rn).get().to_string();
959+
let lt_name = token::get_name(*rn).to_string();
963960
names.push(lt_name);
964961
}
965962
names.sort();
@@ -1438,15 +1435,15 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
14381435
}
14391436
infer::EarlyBoundRegion(_, name) => {
14401437
format!(" for lifetime parameter `{}`",
1441-
token::get_name(name).get())
1438+
&token::get_name(name))
14421439
}
14431440
infer::BoundRegionInCoherence(name) => {
14441441
format!(" for lifetime parameter `{}` in coherence check",
1445-
token::get_name(name).get())
1442+
&token::get_name(name))
14461443
}
14471444
infer::UpvarRegion(ref upvar_id, _) => {
14481445
format!(" for capture of `{}` by closure",
1449-
ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_string())
1446+
ty::local_var_name_str(self.tcx, upvar_id.var_id).to_string())
14501447
}
14511448
};
14521449

@@ -1527,7 +1524,6 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
15271524
&format!(
15281525
"...so that closure can access `{}`",
15291526
ty::local_var_name_str(self.tcx, upvar_id.var_id)
1530-
.get()
15311527
.to_string())[])
15321528
}
15331529
infer::InfStackClosure(span) => {
@@ -1553,7 +1549,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
15531549
does not outlive the enclosing closure",
15541550
ty::local_var_name_str(
15551551
self.tcx,
1556-
id).get().to_string())[]);
1552+
id).to_string())[]);
15571553
}
15581554
infer::IndexSlice(span) => {
15591555
self.tcx.sess.span_note(
@@ -1730,7 +1726,7 @@ impl LifeGiver {
17301726
fn with_taken(taken: &[ast::LifetimeDef]) -> LifeGiver {
17311727
let mut taken_ = HashSet::new();
17321728
for lt in taken {
1733-
let lt_name = token::get_name(lt.lifetime.name).get().to_string();
1729+
let lt_name = token::get_name(lt.lifetime.name).to_string();
17341730
taken_.insert(lt_name);
17351731
}
17361732
LifeGiver {

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
149149
fn visit_item(&mut self, item: &ast::Item) {
150150
match extract(&item.attrs) {
151151
Some(value) => {
152-
let item_index = self.item_refs.get(value.get()).map(|x| *x);
152+
let item_index = self.item_refs.get(&value[]).map(|x| *x);
153153

154154
match item_index {
155155
Some(item_index) => {

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
333333
fn variable_name(&self, var: Variable) -> String {
334334
match self.var_kinds[var.get()] {
335335
Local(LocalInfo { ident: nm, .. }) | Arg(_, nm) => {
336-
token::get_ident(nm).get().to_string()
336+
token::get_ident(nm).to_string()
337337
},
338338
ImplicitRet => "<implicit-ret>".to_string(),
339339
CleanExit => "<clean-exit>".to_string()

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ impl<'tcx> Repr<'tcx> for InteriorKind {
15431543
fn repr(&self, _tcx: &ty::ctxt) -> String {
15441544
match *self {
15451545
InteriorField(NamedField(fld)) => {
1546-
token::get_name(fld).get().to_string()
1546+
token::get_name(fld).to_string()
15471547
}
15481548
InteriorField(PositionalField(i)) => format!("#{}", i),
15491549
InteriorElement(_) => "[]".to_string(),

0 commit comments

Comments
 (0)