Skip to content

Commit 06869b8

Browse files
committed
rustc_codegen_ssa: change set_var_name back to taking a &str.
1 parent 5f4ee36 commit 06869b8

File tree

3 files changed

+10
-34
lines changed

3 files changed

+10
-34
lines changed

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
225225
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
226226
}
227227

228-
fn set_var_name(&mut self, value: &'ll Value, name: impl ToString) {
228+
fn set_var_name(&mut self, value: &'ll Value, name: &str) {
229229
// Avoid wasting time if LLVM value names aren't even enabled.
230230
if self.sess().fewer_names() {
231231
return;
@@ -255,7 +255,7 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
255255
Err(_) => return,
256256
}
257257

258-
let cname = CString::new(name.to_string()).unwrap();
258+
let cname = SmallCStr::new(name);
259259
unsafe {
260260
llvm::LLVMSetValueName(value, cname.as_ptr());
261261
}

src/librustc_codegen_ssa/mir/debuginfo.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc::ty::layout::HasTyCtxt;
77
use rustc_target::abi::{Variants, VariantIdx};
88
use crate::traits::*;
99

10-
use std::fmt;
1110
use syntax_pos::{DUMMY_SP, BytePos, Span};
1211
use syntax::symbol::kw;
1312

@@ -92,29 +91,6 @@ impl<D> DebugScope<D> {
9291
}
9392
}
9493

95-
// HACK(eddyb) helpers for `set_var_name` calls, move elsewhere?
96-
enum Either<T, U> {
97-
Left(T),
98-
Right(U),
99-
}
100-
101-
impl<T: fmt::Display, U: fmt::Display> fmt::Display for Either<T, U> {
102-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103-
match self {
104-
Either::Left(x) => x.fmt(f),
105-
Either::Right(x) => x.fmt(f),
106-
}
107-
}
108-
}
109-
110-
struct DisplayViaDebug<T>(T);
111-
112-
impl<T: fmt::Debug> fmt::Display for DisplayViaDebug<T> {
113-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114-
self.0.fmt(f)
115-
}
116-
}
117-
11894
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11995
pub fn set_debug_loc(
12096
&mut self,
@@ -207,26 +183,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
207183

208184
let local_ref = &self.locals[local];
209185

210-
{
186+
if !bx.sess().fewer_names() {
211187
let name = match name {
212-
Some(name) if name != kw::Invalid => Either::Left(name),
213-
_ => Either::Right(DisplayViaDebug(local)),
188+
Some(name) if name != kw::Invalid => name.to_string(),
189+
_ => format!("{:?}", local),
214190
};
215191
match local_ref {
216192
LocalRef::Place(place) |
217193
LocalRef::UnsizedPlace(place) => {
218-
bx.set_var_name(place.llval, name);
194+
bx.set_var_name(place.llval, &name);
219195
}
220196
LocalRef::Operand(Some(operand)) => match operand.val {
221197
OperandValue::Ref(x, ..) |
222198
OperandValue::Immediate(x) => {
223-
bx.set_var_name(x, name);
199+
bx.set_var_name(x, &name);
224200
}
225201
OperandValue::Pair(a, b) => {
226202
// FIXME(eddyb) these are scalar components,
227203
// maybe extract the high-level fields?
228-
bx.set_var_name(a, format_args!("{}.0", name));
229-
bx.set_var_name(b, format_args!("{}.1", name));
204+
bx.set_var_name(a, &(name.clone() + ".0"));
205+
bx.set_var_name(b, &(name + ".1"));
230206
}
231207
}
232208
LocalRef::Operand(None) => {}

src/librustc_codegen_ssa/traits/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {
5757
span: Span,
5858
);
5959
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
60-
fn set_var_name(&mut self, value: Self::Value, name: impl ToString);
60+
fn set_var_name(&mut self, value: Self::Value, name: &str);
6161
}

0 commit comments

Comments
 (0)