Skip to content

Commit cfc128c

Browse files
committed
Expand one-liners, rename is_like_msvc to cpp_like_names and explain.
1 parent 8e10c4d commit cfc128c

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/librustc_trans/debuginfo/type_names.rs

+30-11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
3636
t: Ty<'tcx>,
3737
qualified: bool,
3838
output: &mut String) {
39+
// When targeting MSVC, emit C++ style type names for compatability with
40+
// .natvis visualizers (and perhaps other existing native debuggers?)
41+
let cpp_like_names = cx.sess().target.target.options.is_like_msvc;
42+
3943
match t.sty {
4044
ty::TyBool => output.push_str("bool"),
4145
ty::TyChar => output.push_str("char"),
@@ -61,27 +65,33 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
6165
output.push(')');
6266
},
6367
ty::TyRawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
64-
let is_like_msvc = cx.sess().target.target.options.is_like_msvc;
65-
66-
if !is_like_msvc {output.push('*');}
68+
if !cpp_like_names {
69+
output.push('*');
70+
}
6771
match mutbl {
6872
hir::MutImmutable => output.push_str("const "),
6973
hir::MutMutable => output.push_str("mut "),
7074
}
7175

7276
push_debuginfo_type_name(cx, inner_type, true, output);
73-
if is_like_msvc {output.push('*');}
77+
78+
if cpp_like_names {
79+
output.push('*');
80+
}
7481
},
7582
ty::TyRef(_, ty::TypeAndMut { ty: inner_type, mutbl }) => {
76-
let is_like_msvc = cx.sess().target.target.options.is_like_msvc;
77-
78-
if !is_like_msvc {output.push('&');}
83+
if !cpp_like_names {
84+
output.push('&');
85+
}
7986
if mutbl == hir::MutMutable {
8087
output.push_str("mut ");
8188
}
8289

8390
push_debuginfo_type_name(cx, inner_type, true, output);
84-
if is_like_msvc {output.push('*');}
91+
92+
if cpp_like_names {
93+
output.push('*');
94+
}
8595
},
8696
ty::TyArray(inner_type, len) => {
8797
output.push('[');
@@ -90,10 +100,19 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
90100
output.push(']');
91101
},
92102
ty::TySlice(inner_type) => {
93-
let is_like_msvc = cx.sess().target.target.options.is_like_msvc;
94-
output.push_str(if is_like_msvc {"slice<"} else {"["});
103+
if cpp_like_names {
104+
output.push_str("slice<");
105+
} else {
106+
output.push('[');
107+
}
108+
95109
push_debuginfo_type_name(cx, inner_type, true, output);
96-
output.push(if is_like_msvc {'>'} else {']'});
110+
111+
if cpp_like_names {
112+
output.push('>');
113+
} else {
114+
output.push(']');
115+
}
97116
},
98117
ty::TyDynamic(ref trait_data, ..) => {
99118
if let Some(principal) = trait_data.principal() {

0 commit comments

Comments
 (0)