]> git.lizzy.rs Git - rust.git/commitdiff
Expand one-liners, rename is_like_msvc to cpp_like_names and explain.
authorMaulingMonkey <git@maulingmonkey.com>
Wed, 19 Jul 2017 23:36:09 +0000 (16:36 -0700)
committerMaulingMonkey <git@maulingmonkey.com>
Wed, 19 Jul 2017 23:36:09 +0000 (16:36 -0700)
src/librustc_trans/debuginfo/type_names.rs

index 9ab5bc4a5a94171ee813bef23f1a695937ccc93d..6e36073107b561ef60747cf558001443bcf2f860 100644 (file)
@@ -36,6 +36,10 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                                           t: Ty<'tcx>,
                                           qualified: bool,
                                           output: &mut String) {
+    // When targeting MSVC, emit C++ style type names for compatability with
+    // .natvis visualizers (and perhaps other existing native debuggers?)
+    let cpp_like_names = cx.sess().target.target.options.is_like_msvc;
+
     match t.sty {
         ty::TyBool => output.push_str("bool"),
         ty::TyChar => output.push_str("char"),
@@ -61,27 +65,33 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             output.push(')');
         },
         ty::TyRawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
-            let is_like_msvc = cx.sess().target.target.options.is_like_msvc;
-
-            if !is_like_msvc {output.push('*');}
+            if !cpp_like_names {
+                output.push('*');
+            }
             match mutbl {
                 hir::MutImmutable => output.push_str("const "),
                 hir::MutMutable => output.push_str("mut "),
             }
 
             push_debuginfo_type_name(cx, inner_type, true, output);
-            if is_like_msvc {output.push('*');}
+
+            if cpp_like_names {
+                output.push('*');
+            }
         },
         ty::TyRef(_, ty::TypeAndMut { ty: inner_type, mutbl }) => {
-            let is_like_msvc = cx.sess().target.target.options.is_like_msvc;
-
-            if !is_like_msvc {output.push('&');}
+            if !cpp_like_names {
+                output.push('&');
+            }
             if mutbl == hir::MutMutable {
                 output.push_str("mut ");
             }
 
             push_debuginfo_type_name(cx, inner_type, true, output);
-            if is_like_msvc {output.push('*');}
+
+            if cpp_like_names {
+                output.push('*');
+            }
         },
         ty::TyArray(inner_type, len) => {
             output.push('[');
@@ -90,10 +100,19 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
             output.push(']');
         },
         ty::TySlice(inner_type) => {
-            let is_like_msvc = cx.sess().target.target.options.is_like_msvc;
-            output.push_str(if is_like_msvc {"slice<"} else {"["});
+            if cpp_like_names {
+                output.push_str("slice<");
+            } else {
+                output.push('[');
+            }
+
             push_debuginfo_type_name(cx, inner_type, true, output);
-            output.push(if is_like_msvc {'>'} else {']'});
+
+            if cpp_like_names {
+                output.push('>');
+            } else {
+                output.push(']');
+            }
         },
         ty::TyDynamic(ref trait_data, ..) => {
             if let Some(principal) = trait_data.principal() {