Skip to content

Commit 1e4269c

Browse files
committed
Add Ident::as_str helper
1 parent 189c0a1 commit 1e4269c

File tree

25 files changed

+50
-46
lines changed

25 files changed

+50
-46
lines changed

src/doc/unstable-book/src/language-features/plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl LintPass for Pass {
208208
209209
impl EarlyLintPass for Pass {
210210
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
211-
if it.ident.name.as_str() == "lintme" {
211+
if it.ident.as_str() == "lintme" {
212212
cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");
213213
}
214214
}

src/libproc_macro/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,14 +1214,14 @@ impl TokenTree {
12141214
SingleQuote => op!('\''),
12151215

12161216
Ident(ident, false) => {
1217-
tt!(self::Ident::new(&ident.name.as_str(), Span(span)))
1217+
tt!(self::Ident::new(&ident.as_str(), Span(span)))
12181218
}
12191219
Ident(ident, true) => {
1220-
tt!(self::Ident::new_raw(&ident.name.as_str(), Span(span)))
1220+
tt!(self::Ident::new_raw(&ident.as_str(), Span(span)))
12211221
}
12221222
Lifetime(ident) => {
12231223
let ident = ident.without_first_quote();
1224-
stack.push(tt!(self::Ident::new(&ident.name.as_str(), Span(span))));
1224+
stack.push(tt!(self::Ident::new(&ident.as_str(), Span(span))));
12251225
tt!(Punct::new('\'', Spacing::Joint))
12261226
}
12271227
Literal(lit, suffix) => tt!(self::Literal { lit, suffix, span: Span(span) }),

src/librustc/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ pub struct StructField {
19831983
impl StructField {
19841984
// Still necessary in couple of places
19851985
pub fn is_positional(&self) -> bool {
1986-
let first = self.ident.name.as_str().as_bytes()[0];
1986+
let first = self.ident.as_str().as_bytes()[0];
19871987
first >= b'0' && first <= b'9'
19881988
}
19891989
}

src/librustc/hir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ impl<'a> State<'a> {
15651565
if ident.is_raw_guess() {
15661566
self.s.word(&format!("r#{}", ident.name))?;
15671567
} else {
1568-
self.s.word(&ident.name.as_str())?;
1568+
self.s.word(&ident.as_str())?;
15691569
}
15701570
self.ann.post(self, NodeName(&ident.name))
15711571
}

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
17741774
CtorKind::Fictive => {
17751775
let mut struct_fmt = fmt.debug_struct("");
17761776
for (field, place) in variant_def.fields.iter().zip(places) {
1777-
struct_fmt.field(&field.ident.name.as_str(), place);
1777+
struct_fmt.field(&field.ident.as_str(), place);
17781778
}
17791779
struct_fmt.finish()
17801780
}

src/librustc_codegen_utils/symbol_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl SymbolPathBuffer {
363363
result: String::with_capacity(64),
364364
temp_buf: String::with_capacity(16),
365365
};
366-
result.result.push_str(&symbol.name.as_str());
366+
result.result.push_str(&symbol.as_str());
367367
result
368368
}
369369

src/librustc_lint/bad_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
324324
_: &hir::Generics,
325325
_: ast::NodeId) {
326326
for sf in s.fields() {
327-
self.check_snake_case(cx, "structure field", &sf.ident.name.as_str(), Some(sf.span));
327+
self.check_snake_case(cx, "structure field", &sf.ident.as_str(), Some(sf.span));
328328
}
329329
}
330330
}

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
772772
debug!("CodegenUnit {}:", cgu.name());
773773

774774
for (mono_item, linkage) in cgu.items() {
775-
let symbol_name = mono_item.symbol_name(tcx).name.as_str();
775+
let symbol_name = mono_item.symbol_name(tcx).as_str();
776776
let symbol_hash_start = symbol_name.rfind('h');
777777
let symbol_hash = symbol_hash_start.map(|i| &symbol_name[i ..])
778778
.unwrap_or("<no hash>");

src/librustc_resolve/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ impl<'a> ModuleData<'a> {
10601060
fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
10611061
let resolutions = self.resolutions.borrow();
10621062
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
1063-
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.name.as_str(), ns));
1063+
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.as_str(), ns));
10641064
for &(&(ident, ns), &resolution) in resolutions.iter() {
10651065
resolution.borrow().binding.map(|binding| f(ident, ns, binding));
10661066
}
@@ -2608,7 +2608,7 @@ impl<'a> Resolver<'a> {
26082608
self,
26092609
ident.span,
26102610
ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(
2611-
&ident.name.as_str())
2611+
&ident.as_str())
26122612
);
26132613
}
26142614
Some(..) if pat_src == PatternSource::FnParam => {
@@ -2617,7 +2617,7 @@ impl<'a> Resolver<'a> {
26172617
self,
26182618
ident.span,
26192619
ResolutionError::IdentifierBoundMoreThanOnceInParameterList(
2620-
&ident.name.as_str())
2620+
&ident.as_str())
26212621
);
26222622
}
26232623
Some(..) if pat_src == PatternSource::Match ||
@@ -3765,12 +3765,12 @@ impl<'a> Resolver<'a> {
37653765
// the closest match
37663766
let close_match = self.search_label(label.ident, |rib, ident| {
37673767
let names = rib.bindings.iter().map(|(id, _)| &id.name);
3768-
find_best_match_for_name(names, &*ident.name.as_str(), None)
3768+
find_best_match_for_name(names, &*ident.as_str(), None)
37693769
});
37703770
self.record_def(expr.id, err_path_resolution());
37713771
resolve_error(self,
37723772
label.ident.span,
3773-
ResolutionError::UndeclaredLabel(&label.ident.name.as_str(),
3773+
ResolutionError::UndeclaredLabel(&label.ident.as_str(),
37743774
close_match));
37753775
}
37763776
Some(Def::Label(id)) => {
@@ -4380,7 +4380,7 @@ fn names_to_string(idents: &[Ident]) -> String {
43804380
if i > 0 {
43814381
result.push_str("::");
43824382
}
4383-
result.push_str(&ident.name.as_str());
4383+
result.push_str(&ident.as_str());
43844384
}
43854385
result
43864386
}

src/librustc_resolve/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'a> Resolver<'a> {
649649
format!("cannot find derive macro `{}` in this scope", ident),
650650
};
651651
let mut err = self.session.struct_span_err(span, &msg);
652-
self.suggest_macro_name(&ident.name.as_str(), kind, &mut err, span);
652+
self.suggest_macro_name(&ident.as_str(), kind, &mut err, span);
653653
err.emit();
654654
},
655655
_ => {},

0 commit comments

Comments
 (0)