Skip to content

Commit a41a692

Browse files
committed
Auto merge of rust-lang#91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr` This was originally proposed in rust-lang#74554 (comment). As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2 parents 8f54061 + b1c934e commit a41a692

File tree

140 files changed

+354
-415
lines changed

Some content is hidden

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

140 files changed

+354
-415
lines changed

compiler/rustc_ast/src/util/literal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ impl LitKind {
3535
LitKind::Bool(symbol == kw::True)
3636
}
3737
token::Byte => {
38-
return unescape_byte(&symbol.as_str())
38+
return unescape_byte(symbol.as_str())
3939
.map(LitKind::Byte)
4040
.map_err(|_| LitError::LexerError);
4141
}
4242
token::Char => {
43-
return unescape_char(&symbol.as_str())
43+
return unescape_char(symbol.as_str())
4444
.map(LitKind::Char)
4545
.map_err(|_| LitError::LexerError);
4646
}

compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1278,7 +1278,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12781278
}
12791279

12801280
pub(super) fn lower_abi(&mut self, abi: StrLit) -> abi::Abi {
1281-
abi::lookup(&abi.symbol_unescaped.as_str()).unwrap_or_else(|| {
1281+
abi::lookup(abi.symbol_unescaped.as_str()).unwrap_or_else(|| {
12821282
self.error_on_invalid_abi(abi);
12831283
abi::Abi::Rust
12841284
})

compiler/rustc_ast_passes/src/ast_validation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ impl<'a> AstValidator<'a> {
580580

581581
/// An item in `extern { ... }` cannot use non-ascii identifier.
582582
fn check_foreign_item_ascii_only(&self, ident: Ident) {
583-
let symbol_str = ident.as_str();
584-
if !symbol_str.is_ascii() {
583+
if !ident.as_str().is_ascii() {
585584
let n = 83942;
586585
self.err_handler()
587586
.struct_span_err(

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a> PostExpansionVisitor<'a> {
6161
fn check_abi(&self, abi: ast::StrLit) {
6262
let ast::StrLit { symbol_unescaped, span, .. } = abi;
6363

64-
match &*symbol_unescaped.as_str() {
64+
match symbol_unescaped.as_str() {
6565
// Stable
6666
"Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64"
6767
| "system" => {}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub fn literal_to_string(lit: token::Lit) -> String {
204204
};
205205

206206
if let Some(suffix) = suffix {
207-
out.push_str(&suffix.as_str())
207+
out.push_str(suffix.as_str())
208208
}
209209

210210
out
@@ -384,7 +384,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
384384
}
385385

386386
fn print_symbol(&mut self, sym: Symbol, style: ast::StrStyle) {
387-
self.print_string(&sym.as_str(), style);
387+
self.print_string(sym.as_str(), style);
388388
}
389389

390390
fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) {

compiler/rustc_attr/src/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ where
236236

237237
// These unwraps are safe because `get` ensures the meta item
238238
// is a name/value pair string literal.
239-
issue_num = match &*issue.unwrap().as_str() {
239+
issue_num = match issue.unwrap().as_str() {
240240
"none" => None,
241241
issue => {
242242
let emit_diag = |msg: &str| {
@@ -301,7 +301,7 @@ where
301301

302302
match (feature, reason, issue) {
303303
(Some(feature), reason, Some(_)) => {
304-
if !rustc_lexer::is_ident(&feature.as_str()) {
304+
if !rustc_lexer::is_ident(feature.as_str()) {
305305
handle_errors(
306306
&sess.parse_sess,
307307
attr.span,
@@ -535,7 +535,7 @@ pub fn eval_condition(
535535
return false;
536536
}
537537
};
538-
let min_version = match parse_version(&min_version.as_str(), false) {
538+
let min_version = match parse_version(min_version.as_str(), false) {
539539
Some(ver) => ver,
540540
None => {
541541
sess.span_diagnostic

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
416416
tcx,
417417
generics,
418418
&mut err,
419-
&param.name.as_str(),
419+
param.name.as_str(),
420420
"Copy",
421421
None,
422422
);

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
206206
{
207207
let local_info = &self.body.local_decls[local].local_info;
208208
if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info {
209-
buf.push_str(&self.infcx.tcx.item_name(def_id).as_str());
209+
buf.push_str(self.infcx.tcx.item_name(def_id).as_str());
210210
} else {
211211
unreachable!();
212212
}
@@ -318,7 +318,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
318318
let decl = &self.body.local_decls[local];
319319
match self.local_names[local] {
320320
Some(name) if !decl.from_compiler_desugaring() => {
321-
buf.push_str(&name.as_str());
321+
buf.push_str(name.as_str());
322322
Ok(())
323323
}
324324
_ => Err(()),

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
573573
template_snippet.as_ref().map(|s| Symbol::intern(s)),
574574
template_sp,
575575
));
576-
let template_str = &template_str.as_str();
576+
let template_str = template_str.as_str();
577577

578578
if let Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) = ecx.sess.asm_arch {
579579
let find_span = |needle: &str| -> Span {

compiler/rustc_builtin_macros/src/concat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn expand_concat(
2121
match e.kind {
2222
ast::ExprKind::Lit(ref lit) => match lit.kind {
2323
ast::LitKind::Str(ref s, _) | ast::LitKind::Float(ref s, _) => {
24-
accumulator.push_str(&s.as_str());
24+
accumulator.push_str(s.as_str());
2525
}
2626
ast::LitKind::Char(c) => {
2727
accumulator.push(c);

compiler/rustc_builtin_macros/src/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn expand_concat_idents<'cx>(
2929
} else {
3030
if let TokenTree::Token(token) = e {
3131
if let Some((ident, _)) = token.ident() {
32-
res_str.push_str(&ident.name.as_str());
32+
res_str.push_str(ident.name.as_str());
3333
continue;
3434
}
3535
}

compiler/rustc_builtin_macros/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn report_bad_target(sess: &Session, item: &Annotatable, span: Span) -> bool {
121121

122122
fn report_unexpected_literal(sess: &Session, lit: &ast::Lit) {
123123
let help_msg = match lit.token.kind {
124-
token::Str if rustc_lexer::is_ident(&lit.token.symbol.as_str()) => {
124+
token::Str if rustc_lexer::is_ident(lit.token.symbol.as_str()) => {
125125
format!("try using `#[derive({})]`", lit.token.symbol)
126126
}
127127
_ => "for example, write `#[derive(Debug)]` for `Debug`".to_string(),

compiler/rustc_builtin_macros/src/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ pub fn expand_env<'cx>(
8080
}
8181

8282
let sp = cx.with_def_site_ctxt(sp);
83-
let value = env::var(&*var.as_str()).ok().as_deref().map(Symbol::intern);
83+
let value = env::var(var.as_str()).ok().as_deref().map(Symbol::intern);
8484
cx.sess.parse_sess.env_depinfo.borrow_mut().insert((var, value));
8585
let e = match value {
8686
None => {
87-
cx.span_err(sp, &msg.as_str());
87+
cx.span_err(sp, msg.as_str());
8888
return DummyResult::any(sp);
8989
}
9090
Some(value) => cx.expr_str(sp, value),

compiler/rustc_builtin_macros/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ pub fn expand_preparsed_format_args(
955955
ast::StrStyle::Raw(raw) => Some(raw as usize),
956956
};
957957

958-
let fmt_str = &fmt_str.as_str(); // for the suggestions below
958+
let fmt_str = fmt_str.as_str(); // for the suggestions below
959959
let fmt_snippet = ecx.source_map().span_to_snippet(fmt_sp).ok();
960960
let mut parser = parse::Parser::new(
961961
fmt_str,

compiler/rustc_codegen_cranelift/src/constant.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
369369
TodoItem::Static(def_id) => {
370370
//println!("static {:?}", def_id);
371371

372-
let section_name = tcx.codegen_fn_attrs(def_id).link_section.map(|s| s.as_str());
372+
let section_name = tcx.codegen_fn_attrs(def_id).link_section;
373373

374374
let alloc = tcx.eval_static_initializer(def_id).unwrap();
375375

@@ -388,6 +388,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
388388

389389
if let Some(section_name) = section_name {
390390
let (segment_name, section_name) = if tcx.sess.target.is_like_osx {
391+
let section_name = section_name.as_str();
391392
if let Some(names) = section_name.split_once(',') {
392393
names
393394
} else {
@@ -397,7 +398,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
397398
));
398399
}
399400
} else {
400-
("", &*section_name)
401+
("", section_name.as_str())
401402
};
402403
data_ctx.set_segment_section(segment_name, section_name);
403404
}

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn reuse_workproduct_for_cgu(
8484
let work_product = cgu.work_product(tcx);
8585
if let Some(saved_file) = &work_product.saved_file {
8686
let obj_out =
87-
tcx.output_filenames(()).temp_path(OutputType::Object, Some(&cgu.name().as_str()));
87+
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu.name().as_str()));
8888
object = Some(obj_out.clone());
8989
let source_file = rustc_incremental::in_incr_comp_dir_sess(&tcx.sess, &saved_file);
9090
if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) {
@@ -176,7 +176,7 @@ fn module_codegen(
176176
)
177177
});
178178

179-
codegen_global_asm(tcx, &cgu.name().as_str(), &cx.global_asm);
179+
codegen_global_asm(tcx, cgu.name().as_str(), &cx.global_asm);
180180

181181
codegen_result
182182
}
@@ -207,7 +207,7 @@ pub(crate) fn run_aot(
207207
cgus.iter()
208208
.map(|cgu| {
209209
let cgu_reuse = determine_cgu_reuse(tcx, cgu);
210-
tcx.sess.cgu_reuse_tracker.set_actual_reuse(&cgu.name().as_str(), cgu_reuse);
210+
tcx.sess.cgu_reuse_tracker.set_actual_reuse(cgu.name().as_str(), cgu_reuse);
211211

212212
match cgu_reuse {
213213
_ if backend_config.disable_incr_cache => {}

compiler/rustc_codegen_gcc/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
3333
return value;
3434
}
3535

36-
let global = self.global_string(&*symbol.as_str());
36+
let global = self.global_string(symbol.as_str());
3737

3838
self.const_cstr_cache.borrow_mut().insert(symbol, global);
3939
global

compiler/rustc_codegen_gcc/src/declare.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
1717
global.set_tls_model(self.tls_model);
1818
}
1919
if let Some(link_section) = link_section {
20-
global.set_link_section(&link_section.as_str());
20+
global.set_link_section(link_section.as_str());
2121
}
2222
global
2323
}
@@ -53,7 +53,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
5353
global.set_tls_model(self.tls_model);
5454
}
5555
if let Some(link_section) = link_section {
56-
global.set_link_section(&link_section.as_str());
56+
global.set_link_section(link_section.as_str());
5757
}
5858
let global_address = global.get_address(None);
5959
self.globals.borrow_mut().insert(name.to_string(), global_address);

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
8888
let arg_tys = sig.inputs();
8989
let ret_ty = sig.output();
9090
let name = tcx.item_name(def_id);
91-
let name_str = &*name.as_str();
91+
let name_str = name.as_str();
9292

9393
let llret_ty = self.layout_of(ret_ty).gcc_type(self, true);
9494
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>,
5252
let sig =
5353
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
5454
let arg_tys = sig.inputs();
55-
let name_str = &*name.as_str();
55+
let name_str = name.as_str();
5656

5757
// every intrinsic below takes a SIMD vector as its first argument
5858
require_simd!(arg_tys[0], "input");

compiler/rustc_codegen_llvm/src/attributes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
326326
.target_features
327327
.iter()
328328
.flat_map(|f| {
329-
let feature = &f.as_str();
329+
let feature = f.as_str();
330330
llvm_util::to_llvm_feature(cx.tcx.sess, feature)
331331
.into_iter()
332332
.map(|f| format!("+{}", f))
@@ -351,7 +351,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
351351

352352
let name =
353353
codegen_fn_attrs.link_name.unwrap_or_else(|| cx.tcx.item_name(instance.def_id()));
354-
let name = CString::new(&name.as_str()[..]).unwrap();
354+
let name = CString::new(name.as_str()).unwrap();
355355
llvm::AddFunctionAttrStringValue(
356356
llfn,
357357
llvm::AttributePlace::Function,

compiler/rustc_codegen_llvm/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
7979
&[cgu_name.to_string(), cgu.size_estimate().to_string()],
8080
);
8181
// Instantiate monomorphizations without filling out definitions yet...
82-
let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
82+
let llvm_module = ModuleLlvm::new(tcx, cgu_name.as_str());
8383
{
8484
let cx = CodegenCx::new(tcx, cgu, &llvm_module);
8585
let mono_items = cx.codegen_unit.items_in_deterministic_order(cx.tcx);
@@ -143,7 +143,7 @@ pub fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) {
143143
None => return,
144144
};
145145
unsafe {
146-
let buf = SmallCStr::new(&sect.as_str());
146+
let buf = SmallCStr::new(sect.as_str());
147147
llvm::LLVMSetSection(llval, buf.as_ptr());
148148
}
149149
}

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
320320

321321
let dbg_cx = if tcx.sess.opts.debuginfo != DebugInfo::None {
322322
let dctx = debuginfo::CrateDebugContext::new(llmod);
323-
debuginfo::metadata::compile_unit_metadata(tcx, &codegen_unit.name().as_str(), &dctx);
323+
debuginfo::metadata::compile_unit_metadata(tcx, codegen_unit.name().as_str(), &dctx);
324324
Some(dctx)
325325
} else {
326326
None

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ pub fn compile_unit_metadata<'ll, 'tcx>(
10371037
) -> &'ll DIDescriptor {
10381038
let mut name_in_debuginfo = match tcx.sess.local_crate_source_file {
10391039
Some(ref path) => path.clone(),
1040-
None => PathBuf::from(&*tcx.crate_name(LOCAL_CRATE).as_str()),
1040+
None => PathBuf::from(tcx.crate_name(LOCAL_CRATE).as_str()),
10411041
};
10421042

10431043
// To avoid breaking split DWARF, we need to ensure that each codegen unit
@@ -1371,7 +1371,7 @@ fn closure_saved_names_of_captured_variables(tcx: TyCtxt<'_>, def_id: DefId) ->
13711371
_ => return None,
13721372
};
13731373
let prefix = if is_ref { "_ref__" } else { "" };
1374-
Some(prefix.to_owned() + &var.name.as_str())
1374+
Some(prefix.to_owned() + var.name.as_str())
13751375
})
13761376
.collect::<Vec<_>>()
13771377
}
@@ -1949,7 +1949,7 @@ enum VariantInfo<'a, 'tcx> {
19491949
impl<'tcx> VariantInfo<'_, 'tcx> {
19501950
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
19511951
match self {
1952-
VariantInfo::Adt(variant) => f(&variant.ident.as_str()),
1952+
VariantInfo::Adt(variant) => f(variant.ident.as_str()),
19531953
VariantInfo::Generator { variant_index, .. } => {
19541954
f(&GeneratorSubsts::variant_name(*variant_index))
19551955
}
@@ -2114,8 +2114,8 @@ fn prepare_enum_metadata<'ll, 'tcx>(
21142114
let item_name;
21152115
let discriminant_name = match enum_type.kind() {
21162116
ty::Adt(..) => {
2117-
item_name = tcx.item_name(enum_def_id).as_str();
2118-
&*item_name
2117+
item_name = tcx.item_name(enum_def_id);
2118+
item_name.as_str()
21192119
}
21202120
ty::Generator(..) => enum_name.as_str(),
21212121
_ => bug!(),
@@ -2448,7 +2448,7 @@ fn compute_type_parameters<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -
24482448
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
24492449
let actual_type_metadata =
24502450
type_metadata(cx, actual_type, rustc_span::DUMMY_SP);
2451-
let name = &name.as_str();
2451+
let name = name.as_str();
24522452
Some(unsafe {
24532453
Some(llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
24542454
DIB(cx),
@@ -2590,7 +2590,8 @@ pub fn create_global_var_metadata<'ll>(cx: &CodegenCx<'ll, '_>, def_id: DefId, g
25902590
let is_local_to_unit = is_node_local_to_unit(cx, def_id);
25912591
let variable_type = Instance::mono(cx.tcx, def_id).ty(cx.tcx, ty::ParamEnv::reveal_all());
25922592
let type_metadata = type_metadata(cx, variable_type, span);
2593-
let var_name = tcx.item_name(def_id).as_str();
2593+
let var_name = tcx.item_name(def_id);
2594+
let var_name = var_name.as_str();
25942595
let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name;
25952596
// When empty, linkage_name field is omitted,
25962597
// which is what we want for no_mangle statics

compiler/rustc_codegen_ssa/src/back/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Command {
4848
}
4949

5050
pub fn sym_arg(&mut self, arg: Symbol) -> &mut Command {
51-
self.arg(&*arg.as_str());
51+
self.arg(arg.as_str());
5252
self
5353
}
5454

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
8888
sess,
8989
crate_type,
9090
outputs,
91-
&codegen_results.crate_info.local_crate_name.as_str(),
91+
codegen_results.crate_info.local_crate_name.as_str(),
9292
);
9393
match crate_type {
9494
CrateType::Rlib => {

0 commit comments

Comments
 (0)