@@ -192,14 +192,20 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
192192
193193 assert ! ( !wants_c_like_enum_debuginfo( cx. tcx, enum_type_and_layout) ) ;
194194
195+ let def_location = if cx. sess ( ) . opts . unstable_opts . more_source_locations_in_debuginfo {
196+ Some ( file_metadata_from_def_id ( cx, Some ( enum_adt_def. did ( ) ) ) )
197+ } else {
198+ None
199+ } ;
200+
195201 type_map:: build_type_with_children (
196202 cx,
197203 type_map:: stub (
198204 cx,
199205 type_map:: Stub :: Union ,
200206 unique_type_id,
201207 & enum_type_name,
202- Some ( file_metadata_from_def_id ( cx , Some ( enum_adt_def . did ( ) ) ) ) ,
208+ def_location ,
203209 cx. size_and_align_of ( enum_type) ,
204210 NO_SCOPE_METADATA ,
205211 visibility_di_flags ( cx, enum_adt_def. did ( ) , enum_adt_def. did ( ) ) ,
@@ -263,8 +269,13 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
263269 unique_type_id : UniqueTypeId < ' tcx > ,
264270) -> DINodeCreationResult < ' ll > {
265271 let coroutine_type = unique_type_id. expect_ty ( ) ;
266- let & ty:: Coroutine ( coroutine_def_id, _, _) = coroutine_type. kind ( ) else {
267- bug ! ( "build_coroutine_di_node() called with non-coroutine type: `{:?}`" , coroutine_type)
272+ let def_location = if cx. sess ( ) . opts . unstable_opts . more_source_locations_in_debuginfo {
273+ let & ty:: Coroutine ( coroutine_def_id, _) = coroutine_type. kind ( ) else {
274+ bug ! ( "build_coroutine_di_node() called with non-coroutine type: `{:?}`" , coroutine_type)
275+ } ;
276+ Some ( file_metadata_from_def_id ( cx, Some ( coroutine_def_id) ) )
277+ } else {
278+ None
268279 } ;
269280 let coroutine_type_and_layout = cx. layout_of ( coroutine_type) ;
270281 let coroutine_type_name = compute_debuginfo_type_name ( cx. tcx , coroutine_type, false ) ;
@@ -278,7 +289,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
278289 type_map:: Stub :: Union ,
279290 unique_type_id,
280291 & coroutine_type_name,
281- Some ( file_metadata_from_def_id ( cx , Some ( coroutine_def_id ) ) ) ,
292+ def_location ,
282293 size_and_align_of ( coroutine_type_and_layout) ,
283294 NO_SCOPE_METADATA ,
284295 DIFlags :: FlagZero ,
@@ -326,14 +337,20 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
326337 let tag_base_type_di_node = type_di_node ( cx, tag_base_type) ;
327338 let tag_base_type_align = cx. align_of ( tag_base_type) ;
328339
340+ let enum_adt_def_id = if cx. sess ( ) . opts . unstable_opts . more_source_locations_in_debuginfo {
341+ Some ( enum_adt_def. did ( ) )
342+ } else {
343+ None
344+ } ;
345+
329346 let variant_names_type_di_node = build_variant_names_type_di_node (
330347 cx,
331348 enum_type_di_node,
332349 std:: iter:: once ( (
333350 variant_index,
334351 Cow :: from ( enum_adt_def. variant ( variant_index) . name . as_str ( ) ) ,
335352 ) ) ,
336- enum_adt_def . did ( ) ,
353+ enum_adt_def_id ,
337354 ) ;
338355
339356 let variant_struct_type_wrapper_di_node = build_variant_struct_wrapper_type_di_node (
@@ -391,14 +408,20 @@ fn build_union_fields_for_enum<'ll, 'tcx>(
391408) -> SmallVec < & ' ll DIType > {
392409 let tag_base_type = tag_base_type ( cx. tcx , enum_type_and_layout) ;
393410
411+ let enum_adt_def_id = if cx. sess ( ) . opts . unstable_opts . more_source_locations_in_debuginfo {
412+ Some ( enum_adt_def. did ( ) )
413+ } else {
414+ None
415+ } ;
416+
394417 let variant_names_type_di_node = build_variant_names_type_di_node (
395418 cx,
396419 enum_type_di_node,
397420 variant_indices. clone ( ) . map ( |variant_index| {
398421 let variant_name = Cow :: from ( enum_adt_def. variant ( variant_index) . name . as_str ( ) ) ;
399422 ( variant_index, variant_name)
400423 } ) ,
401- enum_adt_def . did ( ) ,
424+ enum_adt_def_id ,
402425 ) ;
403426 let visibility_flags = visibility_di_flags ( cx, enum_adt_def. did ( ) , enum_adt_def. did ( ) ) ;
404427
@@ -456,7 +479,7 @@ fn build_variant_names_type_di_node<'ll, 'tcx>(
456479 cx : & CodegenCx < ' ll , ' tcx > ,
457480 containing_scope : & ' ll DIType ,
458481 variants : impl Iterator < Item = ( VariantIdx , Cow < ' tcx , str > ) > ,
459- enum_def_id : rustc_span:: def_id:: DefId ,
482+ enum_def_id : Option < rustc_span:: def_id:: DefId > ,
460483) -> & ' ll DIType {
461484 // Create an enumerator for each variant.
462485 super :: build_enumeration_type_di_node (
@@ -698,7 +721,11 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>(
698721 variant_range
699722 . clone ( )
700723 . map ( |variant_index| ( variant_index, CoroutineArgs :: variant_name ( variant_index) ) ) ,
701- coroutine_def_id,
724+ if cx. sess ( ) . opts . unstable_opts . more_source_locations_in_debuginfo {
725+ Some ( coroutine_def_id)
726+ } else {
727+ None
728+ } ,
702729 ) ;
703730
704731 let discriminants: IndexVec < VariantIdx , DiscrResult > = {
@@ -791,7 +818,11 @@ fn build_union_fields_for_direct_tag_enum_or_coroutine<'ll, 'tcx>(
791818 tag_base_type_di_node,
792819 tag_base_type,
793820 variant_member_info. discr ,
794- variant_member_info. source_info ,
821+ if cx. sess ( ) . opts . unstable_opts . more_source_locations_in_debuginfo {
822+ variant_member_info. source_info
823+ } else {
824+ None
825+ } ,
795826 ) ;
796827
797828 // We use LLVMRustDIBuilderCreateMemberType() member type directly because
0 commit comments