From 67794612945e1987dd53ba6ac1a4b495176e812c Mon Sep 17 00:00:00 2001 From: Osama Abdelkader Date: Mon, 27 Oct 2025 00:59:18 +0300 Subject: [PATCH] Remove redundant .to_string().as_str() calls The pattern .to_string().as_str() creates a temporary String that is immediately borrowed and then dropped, which is inefficient. Replace with &.to_string() for cleaner, more idiomatic code. Changes: - compiler/rustc_builtin_macros/src/autodiff.rs: Simplify identifier creation - compiler/rustc_codegen_llvm/src/context.rs: Simplify error message formatting Signed-off-by: Osama Abdelkader --- compiler/rustc_builtin_macros/src/autodiff.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs index ddc59bfe1414a..3d3b63ba48768 100644 --- a/compiler/rustc_builtin_macros/src/autodiff.rs +++ b/compiler/rustc_builtin_macros/src/autodiff.rs @@ -49,7 +49,7 @@ mod llvm_enzyme { match l.kind { ast::LitKind::Int(val, _) => { // get an Ident from a lit - return rustc_span::Ident::from_str(val.get().to_string().as_str()); + return rustc_span::Ident::from_str(&val.get().to_string()); } _ => {} } diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 808aaceab4d20..43529932ac740 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -216,7 +216,7 @@ pub(crate) unsafe fn create_module<'ll>( if target_data_layout != llvm_data_layout { tcx.dcx().emit_err(crate::errors::MismatchedDataLayout { - rustc_target: sess.opts.target_triple.to_string().as_str(), + rustc_target: &sess.opts.target_triple.to_string(), rustc_layout: target_data_layout.as_str(), llvm_target: sess.target.llvm_target.borrow(), llvm_layout: llvm_data_layout,