@@ -60,7 +60,7 @@ use middle::trans::adt;
60
60
use middle:: trans;
61
61
use middle:: ty;
62
62
use middle:: pat_util;
63
- use util:: ppaux:: ty_to_str ;
63
+ use util:: ppaux;
64
64
65
65
use std:: c_str:: ToCStr ;
66
66
use std:: hashmap:: HashMap ;
@@ -742,7 +742,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
742
742
codemap:: dummy_sp ( ) ) ;
743
743
744
744
// Add self type name to <...> clause of function name
745
- let actual_self_type_name = ty_to_str ( cx. tcx , actual_self_type) ;
745
+ let actual_self_type_name = ppaux :: ty_to_str ( cx. tcx , actual_self_type) ;
746
746
name_to_append_suffix_to. push_str ( actual_self_type_name) ;
747
747
if generics. is_type_parameterized ( ) {
748
748
name_to_append_suffix_to. push_str ( "," ) ;
@@ -779,7 +779,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
779
779
let actual_type_metadata = type_metadata ( cx, actual_type, codemap:: dummy_sp ( ) ) ;
780
780
781
781
// Add actual type name to <...> clause of function name
782
- let actual_type_name = ty_to_str ( cx. tcx , actual_type) ;
782
+ let actual_type_name = ppaux :: ty_to_str ( cx. tcx , actual_type) ;
783
783
name_to_append_suffix_to. push_str ( actual_type_name) ;
784
784
785
785
if index != generics. ty_params . len ( ) - 1 {
@@ -1039,7 +1039,7 @@ fn pointer_type_metadata(cx: &mut CrateContext,
1039
1039
-> DIType {
1040
1040
let pointer_llvm_type = type_of:: type_of ( cx, pointer_type) ;
1041
1041
let ( pointer_size, pointer_align) = size_and_align_of ( cx, pointer_llvm_type) ;
1042
- let name = ty_to_str ( cx. tcx , pointer_type) ;
1042
+ let name = ppaux :: ty_to_str ( cx. tcx , pointer_type) ;
1043
1043
let ptr_metadata = do name. with_c_str |name| {
1044
1044
unsafe {
1045
1045
llvm:: LLVMDIBuilderCreatePointerType (
@@ -1059,7 +1059,7 @@ fn struct_metadata(cx: &mut CrateContext,
1059
1059
substs : & ty:: substs ,
1060
1060
span : Span )
1061
1061
-> DICompositeType {
1062
- let struct_name = ty_to_str ( cx. tcx , struct_type) ;
1062
+ let struct_name = ppaux :: ty_to_str ( cx. tcx , struct_type) ;
1063
1063
debug ! ( "struct_metadata: %s" , struct_name) ;
1064
1064
1065
1065
let struct_llvm_type = type_of:: type_of ( cx, struct_type) ;
@@ -1098,7 +1098,7 @@ fn tuple_metadata(cx: &mut CrateContext,
1098
1098
component_types : & [ ty:: t ] ,
1099
1099
span : Span )
1100
1100
-> DICompositeType {
1101
- let tuple_name = ty_to_str ( cx. tcx , tuple_type) ;
1101
+ let tuple_name = ppaux :: ty_to_str ( cx. tcx , tuple_type) ;
1102
1102
let tuple_llvm_type = type_of:: type_of ( cx, tuple_type) ;
1103
1103
1104
1104
let component_descriptions = do component_types. map |& component_type| {
@@ -1127,7 +1127,7 @@ fn enum_metadata(cx: &mut CrateContext,
1127
1127
enum_def_id : ast:: DefId ,
1128
1128
span : Span )
1129
1129
-> DIType {
1130
- let enum_name = ty_to_str ( cx. tcx , enum_type) ;
1130
+ let enum_name = ppaux :: ty_to_str ( cx. tcx , enum_type) ;
1131
1131
1132
1132
let ( containing_scope, definition_span) = get_namespace_and_span_for_item ( cx,
1133
1133
enum_def_id,
@@ -1502,7 +1502,7 @@ fn vec_metadata(cx: &mut CrateContext,
1502
1502
let ( element_size, element_align) = size_and_align_of ( cx, element_llvm_type) ;
1503
1503
1504
1504
let vec_llvm_type = Type :: vec ( cx. sess . targ_cfg . arch , & element_llvm_type) ;
1505
- let vec_type_name: & str = fmt ! ( "[%s]" , ty_to_str( cx. tcx, element_type) ) ;
1505
+ let vec_type_name: & str = fmt ! ( "[%s]" , ppaux :: ty_to_str( cx. tcx, element_type) ) ;
1506
1506
1507
1507
let member_llvm_types = vec_llvm_type. field_types ( ) ;
1508
1508
@@ -1556,7 +1556,7 @@ fn boxed_vec_metadata(cx: &mut CrateContext,
1556
1556
1557
1557
let element_llvm_type = type_of:: type_of ( cx, element_type) ;
1558
1558
let vec_llvm_type = Type :: vec ( cx. sess . targ_cfg . arch , & element_llvm_type) ;
1559
- let vec_type_name: & str = fmt ! ( "[%s]" , ty_to_str( cx. tcx, element_type) ) ;
1559
+ let vec_type_name: & str = fmt ! ( "[%s]" , ppaux :: ty_to_str( cx. tcx, element_type) ) ;
1560
1560
let vec_metadata = vec_metadata ( cx, element_type, span) ;
1561
1561
1562
1562
return boxed_type_metadata (
@@ -1576,7 +1576,7 @@ fn vec_slice_metadata(cx: &mut CrateContext,
1576
1576
debug ! ( "vec_slice_metadata: %?" , ty:: get( vec_type) ) ;
1577
1577
1578
1578
let slice_llvm_type = type_of:: type_of ( cx, vec_type) ;
1579
- let slice_type_name = ty_to_str ( cx. tcx , vec_type) ;
1579
+ let slice_type_name = ppaux :: ty_to_str ( cx. tcx , vec_type) ;
1580
1580
1581
1581
let member_llvm_types = slice_llvm_type. field_types ( ) ;
1582
1582
assert ! ( slice_layout_is_correct( cx, member_llvm_types, element_type) ) ;
@@ -1648,10 +1648,47 @@ fn subroutine_type_metadata(cx: &mut CrateContext,
1648
1648
} ;
1649
1649
}
1650
1650
1651
+ fn trait_metadata ( cx : & mut CrateContext ,
1652
+ def_id : ast:: DefId ,
1653
+ trait_type : ty:: t ,
1654
+ substs : & ty:: substs ,
1655
+ trait_store : ty:: TraitStore ,
1656
+ mutability : ast:: Mutability ,
1657
+ builtinBounds : & ty:: BuiltinBounds ,
1658
+ usage_site_span : Span )
1659
+ -> DIType {
1660
+ // The implementation provided here is a stub. It makes sure that the trait type is
1661
+ // assigned the correct name, size, namespace, and source location. But it does not describe
1662
+ // the trait's methods.
1663
+ let path = ty:: item_path ( cx. tcx , def_id) ;
1664
+ let ident = path. last ( ) . ident ( ) ;
1665
+ let name = ppaux:: trait_store_to_str ( cx. tcx , trait_store)
1666
+ + ppaux:: mutability_to_str ( mutability)
1667
+ + token:: ident_to_str ( & ident) ;
1668
+ // Add type and region parameters
1669
+ let name = ppaux:: parameterized ( cx. tcx , name, & substs. regions , substs. tps ) ;
1670
+
1671
+ let ( containing_scope,
1672
+ definition_span) = get_namespace_and_span_for_item ( cx, def_id, usage_site_span) ;
1673
+
1674
+ let file_name = span_start ( cx, definition_span) . file . name ;
1675
+ let file_metadata = file_metadata ( cx, file_name) ;
1676
+
1677
+ let trait_llvm_type = type_of:: type_of ( cx, trait_type) ;
1678
+
1679
+ return composite_type_metadata ( cx,
1680
+ trait_llvm_type,
1681
+ name,
1682
+ [ ] ,
1683
+ containing_scope,
1684
+ file_metadata,
1685
+ definition_span) ;
1686
+ }
1687
+
1651
1688
fn unimplemented_type_metadata ( cx : & mut CrateContext , t : ty:: t ) -> DIType {
1652
1689
debug ! ( "unimplemented_type_metadata: %?" , ty:: get( t) ) ;
1653
1690
1654
- let name = ty_to_str ( cx. tcx , t) ;
1691
+ let name = ppaux :: ty_to_str ( cx. tcx , t) ;
1655
1692
let metadata = do fmt ! ( "NYI<%s>" , name) . with_c_str |name| {
1656
1693
unsafe {
1657
1694
llvm:: LLVMDIBuilderCreateBasicType (
@@ -1681,7 +1718,7 @@ fn type_metadata(cx: &mut CrateContext,
1681
1718
type_in_box : ty:: t )
1682
1719
-> DIType {
1683
1720
1684
- let content_type_name: & str = ty_to_str ( cx. tcx , type_in_box) ;
1721
+ let content_type_name: & str = ppaux :: ty_to_str ( cx. tcx , type_in_box) ;
1685
1722
let content_llvm_type = type_of:: type_of ( cx, type_in_box) ;
1686
1723
let content_type_metadata = type_metadata (
1687
1724
cx,
@@ -1773,9 +1810,8 @@ fn type_metadata(cx: &mut CrateContext,
1773
1810
ty:: ty_closure( ref closurety) => {
1774
1811
subroutine_type_metadata ( cx, & closurety. sig , usage_site_span)
1775
1812
} ,
1776
- ty:: ty_trait( _did, ref _substs, ref _vstore, _, _bounds) => {
1777
- cx. sess . span_note ( usage_site_span, "debuginfo for trait NYI" ) ;
1778
- unimplemented_type_metadata ( cx, t)
1813
+ ty:: ty_trait( def_id, ref substs, trait_store, mutability, ref bounds) => {
1814
+ trait_metadata ( cx, def_id, t, substs, trait_store, mutability, bounds, usage_site_span)
1779
1815
} ,
1780
1816
ty:: ty_struct( def_id, ref substs) => {
1781
1817
struct_metadata ( cx, t, def_id, substs, usage_site_span)
0 commit comments