Skip to content

Commit 5bc7084

Browse files
committed
Convert x.as_str().to_string() to x.to_string() where possible.
1 parent 9cf59b5 commit 5bc7084

File tree

10 files changed

+16
-18
lines changed

10 files changed

+16
-18
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'tcx> DepNodeParams<'tcx> for CrateNum {
525525
}
526526

527527
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
528-
tcx.crate_name(*self).as_str().to_string()
528+
tcx.crate_name(*self).to_string()
529529
}
530530
}
531531

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,7 @@ pub fn is_range_literal(sess: &Session, expr: &hir::Expr) -> bool {
33823382
// either in std or core, i.e. has either a `::std::ops::Range` or
33833383
// `::core::ops::Range` prefix.
33843384
fn is_range_path(path: &Path) -> bool {
3385-
let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.as_str().to_string()).collect();
3385+
let segs: Vec<_> = path.segments.iter().map(|seg| seg.ident.to_string()).collect();
33863386
let segs: Vec<_> = segs.iter().map(|seg| &**seg).collect();
33873387

33883388
// "{{root}}" is the equivalent of `::` prefix in `Path`.

src/librustc/hir/print.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl<'a> State<'a> {
564564
}
565565
hir::ItemKind::GlobalAsm(ref ga) => {
566566
self.head(visibility_qualified(&item.vis, "global asm"));
567-
self.s.word(ga.asm.as_str().to_string());
567+
self.s.word(ga.asm.to_string());
568568
self.end()
569569
}
570570
hir::ItemKind::TyAlias(ref ty, ref generics) => {
@@ -1855,7 +1855,7 @@ impl<'a> State<'a> {
18551855
self.commasep(Inconsistent, &decl.inputs, |s, ty| {
18561856
s.ibox(INDENT_UNIT);
18571857
if let Some(arg_name) = arg_names.get(i) {
1858-
s.s.word(arg_name.as_str().to_string());
1858+
s.s.word(arg_name.to_string());
18591859
s.s.word(":");
18601860
s.s.space();
18611861
} else if let Some(body_id) = body_id {

src/librustc/traits/on_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'tcx> OnUnimplementedDirective {
180180
c.ident().map_or(false, |ident| {
181181
options.contains(&(
182182
ident.name,
183-
c.value_str().map(|s| s.as_str().to_string())
183+
c.value_str().map(|s| s.to_string())
184184
))
185185
})
186186
}) {

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'sess> OnDiskCache<'sess> {
264264
let sorted_cnums = sorted_cnums_including_local_crate(tcx);
265265
let prev_cnums: Vec<_> = sorted_cnums.iter()
266266
.map(|&cnum| {
267-
let crate_name = tcx.original_crate_name(cnum).as_str().to_string();
267+
let crate_name = tcx.original_crate_name(cnum).to_string();
268268
let crate_disambiguator = tcx.crate_disambiguator(cnum);
269269
(cnum.as_u32(), crate_name, crate_disambiguator)
270270
})

src/librustc_codegen_ssa/base.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
552552
} else if let Some(kind) = *tcx.sess.allocator_kind.get() {
553553
let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
554554
&["crate"],
555-
Some("allocator")).as_str()
556-
.to_string();
555+
Some("allocator")).to_string();
557556
let mut modules = backend.new_metadata(tcx, &llmod_id);
558557
time(tcx.sess, "write allocator module", || {
559558
backend.codegen_allocator(tcx, &mut modules, kind)
@@ -576,8 +575,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
576575
// Codegen the encoded metadata.
577576
let metadata_cgu_name = cgu_name_builder.build_cgu_name(LOCAL_CRATE,
578577
&["crate"],
579-
Some("metadata")).as_str()
580-
.to_string();
578+
Some("metadata")).to_string();
581579
let mut metadata_llvm_module = backend.new_metadata(tcx, &metadata_cgu_name);
582580
time(tcx.sess, "write compressed metadata", || {
583581
backend.write_compressed_metadata(tcx, &ongoing_codegen.metadata,

src/librustc_incremental/assert_module_sources.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ impl AssertModuleSource<'tcx> {
9494
return;
9595
}
9696

97-
let user_path = self.field(attr, sym::module).as_str().to_string();
98-
let crate_name = self.tcx.crate_name(LOCAL_CRATE).as_str().to_string();
97+
let user_path = self.field(attr, sym::module).to_string();
98+
let crate_name = self.tcx.crate_name(LOCAL_CRATE).to_string();
9999

100100
if !user_path.starts_with(&crate_name) {
101101
let msg = format!("Found malformed codegen unit name `{}`. \
@@ -131,7 +131,7 @@ impl AssertModuleSource<'tcx> {
131131
cgu_name,
132132
self.available_cgus
133133
.iter()
134-
.map(|cgu| cgu.as_str().to_string())
134+
.map(|cgu| cgu.to_string())
135135
.collect::<Vec<_>>()
136136
.join(", ")));
137137
}

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ fn external_path(cx: &DocContext<'_>, name: Symbol, trait_did: Option<DefId>, ha
11671167
global: false,
11681168
res: Res::Err,
11691169
segments: vec![PathSegment {
1170-
name: name.as_str().to_string(),
1170+
name: name.to_string(),
11711171
args: external_generic_args(cx, trait_did, has_self, bindings, substs)
11721172
}],
11731173
}

src/libsyntax/print/pprust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
623623
}
624624
self.maybe_print_comment(attr.span.lo());
625625
if attr.is_sugared_doc {
626-
self.word(attr.value_str().unwrap().as_str().to_string());
626+
self.word(attr.value_str().unwrap().to_string());
627627
self.hardbreak()
628628
} else {
629629
match attr.style {
@@ -1234,7 +1234,7 @@ impl<'a> State<'a> {
12341234
}
12351235
ast::ItemKind::GlobalAsm(ref ga) => {
12361236
self.head(visibility_qualified(&item.vis, "global_asm!"));
1237-
self.s.word(ga.asm.as_str().to_string());
1237+
self.s.word(ga.asm.to_string());
12381238
self.end();
12391239
}
12401240
ast::ItemKind::TyAlias(ref ty, ref generics) => {
@@ -2335,7 +2335,7 @@ impl<'a> State<'a> {
23352335
}
23362336

23372337
crate fn print_name(&mut self, name: ast::Name) {
2338-
self.s.word(name.as_str().to_string());
2338+
self.s.word(name.to_string());
23392339
self.ann.post(self, AnnNode::Name(&name))
23402340
}
23412341

src/libsyntax_expand/mbe/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn generic_extension<'cx>(
225225
};
226226
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false, None);
227227
p.root_module_name =
228-
cx.current_expansion.module.mod_path.last().map(|id| id.as_str().to_string());
228+
cx.current_expansion.module.mod_path.last().map(|id| id.to_string());
229229
p.last_type_ascription = cx.current_expansion.prior_type_ascription;
230230

231231
p.process_potential_macro_variable();

0 commit comments

Comments
 (0)