about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2019-10-22 12:36:00 +0300
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2019-10-31 20:25:54 +0200
commit06869b8d17d06818d8e2ac36834ba21827443985 (patch)
treed6db36d8bec15a121452d4d5de149e0886ee71ca
parent5f4ee36e0330ef6db36f3cf2fe4d3ea19f1f0eb4 (diff)
downloadrust-06869b8d17d06818d8e2ac36834ba21827443985.tar.gz
rust-06869b8d17d06818d8e2ac36834ba21827443985.zip
rustc_codegen_ssa: change set_var_name back to taking a &str.
-rw-r--r--src/librustc_codegen_llvm/debuginfo/mod.rs4
-rw-r--r--src/librustc_codegen_ssa/mir/debuginfo.rs38
-rw-r--r--src/librustc_codegen_ssa/traits/debuginfo.rs2
3 files changed, 10 insertions, 34 deletions
diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs
index d7706b3251b..0e6269fc7e1 100644
--- a/src/librustc_codegen_llvm/debuginfo/mod.rs
+++ b/src/librustc_codegen_llvm/debuginfo/mod.rs
@@ -225,7 +225,7 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
         gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
     }
 
-    fn set_var_name(&mut self, value: &'ll Value, name: impl ToString) {
+    fn set_var_name(&mut self, value: &'ll Value, name: &str) {
         // Avoid wasting time if LLVM value names aren't even enabled.
         if self.sess().fewer_names() {
             return;
@@ -255,7 +255,7 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
             Err(_) => return,
         }
 
-        let cname = CString::new(name.to_string()).unwrap();
+        let cname = SmallCStr::new(name);
         unsafe {
             llvm::LLVMSetValueName(value, cname.as_ptr());
         }
diff --git a/src/librustc_codegen_ssa/mir/debuginfo.rs b/src/librustc_codegen_ssa/mir/debuginfo.rs
index cd209717cc4..29c0d70b58a 100644
--- a/src/librustc_codegen_ssa/mir/debuginfo.rs
+++ b/src/librustc_codegen_ssa/mir/debuginfo.rs
@@ -7,7 +7,6 @@ use rustc::ty::layout::HasTyCtxt;
 use rustc_target::abi::{Variants, VariantIdx};
 use crate::traits::*;
 
-use std::fmt;
 use syntax_pos::{DUMMY_SP, BytePos, Span};
 use syntax::symbol::kw;
 
@@ -92,29 +91,6 @@ impl<D> DebugScope<D> {
     }
 }
 
-// HACK(eddyb) helpers for `set_var_name` calls, move elsewhere?
-enum Either<T, U> {
-    Left(T),
-    Right(U),
-}
-
-impl<T: fmt::Display, U: fmt::Display> fmt::Display for Either<T, U> {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match self {
-            Either::Left(x) => x.fmt(f),
-            Either::Right(x) => x.fmt(f),
-        }
-    }
-}
-
-struct DisplayViaDebug<T>(T);
-
-impl<T: fmt::Debug> fmt::Display for DisplayViaDebug<T> {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        self.0.fmt(f)
-    }
-}
-
 impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
     pub fn set_debug_loc(
         &mut self,
@@ -207,26 +183,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
 
         let local_ref = &self.locals[local];
 
-        {
+        if !bx.sess().fewer_names() {
             let name = match name {
-                Some(name) if name != kw::Invalid => Either::Left(name),
-                _ => Either::Right(DisplayViaDebug(local)),
+                Some(name) if name != kw::Invalid => name.to_string(),
+                _ => format!("{:?}", local),
             };
             match local_ref {
                 LocalRef::Place(place) |
                 LocalRef::UnsizedPlace(place) => {
-                    bx.set_var_name(place.llval, name);
+                    bx.set_var_name(place.llval, &name);
                 }
                 LocalRef::Operand(Some(operand)) => match operand.val {
                     OperandValue::Ref(x, ..) |
                     OperandValue::Immediate(x) => {
-                        bx.set_var_name(x, name);
+                        bx.set_var_name(x, &name);
                     }
                     OperandValue::Pair(a, b) => {
                         // FIXME(eddyb) these are scalar components,
                         // maybe extract the high-level fields?
-                        bx.set_var_name(a, format_args!("{}.0", name));
-                        bx.set_var_name(b, format_args!("{}.1", name));
+                        bx.set_var_name(a, &(name.clone() + ".0"));
+                        bx.set_var_name(b, &(name + ".1"));
                     }
                 }
                 LocalRef::Operand(None) => {}
diff --git a/src/librustc_codegen_ssa/traits/debuginfo.rs b/src/librustc_codegen_ssa/traits/debuginfo.rs
index 244fe845d7d..4712eff6796 100644
--- a/src/librustc_codegen_ssa/traits/debuginfo.rs
+++ b/src/librustc_codegen_ssa/traits/debuginfo.rs
@@ -57,5 +57,5 @@ pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {
         span: Span,
     );
     fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
-    fn set_var_name(&mut self, value: Self::Value, name: impl ToString);
+    fn set_var_name(&mut self, value: Self::Value, name: &str);
 }