Skip to content

Commit 4692d46

Browse files
committed
Add additional option checks
1 parent a4833a8 commit 4692d46

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,14 +1221,20 @@ fn build_closure_env_di_node<'ll, 'tcx>(
12211221
let containing_scope = get_namespace_for_item(cx, def_id);
12221222
let type_name = compute_debuginfo_type_name(cx.tcx, closure_env_type, false);
12231223

1224+
let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo {
1225+
Some(file_metadata_from_def_id(cx, Some(def_id)))
1226+
} else {
1227+
None
1228+
};
1229+
12241230
type_map::build_type_with_children(
12251231
cx,
12261232
type_map::stub(
12271233
cx,
12281234
Stub::Struct,
12291235
unique_type_id,
12301236
&type_name,
1231-
Some(file_metadata_from_def_id(cx, Some(def_id))),
1237+
def_location,
12321238
cx.size_and_align_of(closure_env_type),
12331239
Some(containing_scope),
12341240
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,20 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
5656

5757
assert!(!wants_c_like_enum_debuginfo(cx.tcx, enum_type_and_layout));
5858

59+
let def_location = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo {
60+
Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did())))
61+
} else {
62+
None
63+
};
64+
5965
type_map::build_type_with_children(
6066
cx,
6167
type_map::stub(
6268
cx,
6369
Stub::Struct,
6470
unique_type_id,
6571
&enum_type_name,
66-
Some(file_metadata_from_def_id(cx, Some(enum_adt_def.did()))),
72+
def_location,
6773
size_and_align_of(enum_type_and_layout),
6874
Some(containing_scope),
6975
visibility_flags,
@@ -86,18 +92,29 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
8692
enum_type_and_layout.for_variant(cx, variant_index),
8793
visibility_flags,
8894
),
89-
source_info: Some(file_metadata_from_def_id(
90-
cx,
91-
Some(enum_adt_def.variant(variant_index).def_id),
92-
)),
95+
source_info: if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo
96+
{
97+
Some(file_metadata_from_def_id(
98+
cx,
99+
Some(enum_adt_def.variant(variant_index).def_id),
100+
))
101+
} else {
102+
None
103+
},
93104
})
94105
.collect();
95106

107+
let enum_adt_def_id = if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo
108+
{
109+
Some(enum_adt_def.did())
110+
} else {
111+
None
112+
};
96113
smallvec![build_enum_variant_part_di_node(
97114
cx,
98115
enum_type_and_layout,
99116
enum_type_di_node,
100-
enum_adt_def.did(),
117+
enum_adt_def_id,
101118
&variant_member_infos[..],
102119
)]
103120
},
@@ -210,6 +227,12 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
210227
})
211228
.collect();
212229

230+
let generator_def_id =
231+
if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo {
232+
Some(generator_def_id)
233+
} else {
234+
None
235+
};
213236
smallvec![build_enum_variant_part_di_node(
214237
cx,
215238
coroutine_type_and_layout,
@@ -242,7 +265,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>(
242265
cx: &CodegenCx<'ll, 'tcx>,
243266
enum_type_and_layout: TyAndLayout<'tcx>,
244267
enum_type_di_node: &'ll DIType,
245-
enum_type_def_id: rustc_span::def_id::DefId,
268+
enum_type_def_id: Option<rustc_span::def_id::DefId>,
246269
variant_member_infos: &[VariantMemberInfo<'_, 'll>],
247270
) -> &'ll DIType {
248271
let tag_member_di_node =
@@ -253,7 +276,7 @@ fn build_enum_variant_part_di_node<'ll, 'tcx>(
253276

254277
let (file_metadata, line_number) =
255278
if cx.sess().opts.unstable_opts.more_source_locations_in_debuginfo {
256-
file_metadata_from_def_id(cx, Some(enum_type_def_id))
279+
file_metadata_from_def_id(cx, enum_type_def_id)
257280
} else {
258281
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
259282
};

0 commit comments

Comments
 (0)