@@ -31,7 +31,7 @@ use std::{mem, ptr};
31
31
type Res = def:: Res < NodeId > ;
32
32
33
33
/// Contains data for specific kinds of imports.
34
- #[ derive( Clone , Debug ) ]
34
+ #[ derive( Clone ) ]
35
35
pub enum ImportKind < ' a > {
36
36
Single {
37
37
/// `source` in `use prefix::source as target`.
@@ -62,6 +62,44 @@ pub enum ImportKind<'a> {
62
62
MacroUse ,
63
63
}
64
64
65
+ /// Manually implement `Debug` for `ImportKind` because the `source/target_bindings`
66
+ /// contain `Cell`s which can introduce infinite loops while printing.
67
+ impl < ' a > std:: fmt:: Debug for ImportKind < ' a > {
68
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
69
+ use ImportKind :: * ;
70
+ match self {
71
+ Single {
72
+ ref source,
73
+ ref target,
74
+ ref type_ns_only,
75
+ ref nested,
76
+ ref additional_ids,
77
+ // Ignore the following to avoid an infinite loop while printing.
78
+ source_bindings : _,
79
+ target_bindings : _,
80
+ } => f
81
+ . debug_struct ( "Single" )
82
+ . field ( "source" , source)
83
+ . field ( "target" , target)
84
+ . field ( "type_ns_only" , type_ns_only)
85
+ . field ( "nested" , nested)
86
+ . field ( "additional_ids" , additional_ids)
87
+ . finish ( ) ,
88
+ Glob { ref is_prelude, ref max_vis } => f
89
+ . debug_struct ( "Glob" )
90
+ . field ( "is_prelude" , is_prelude)
91
+ . field ( "max_vis" , max_vis)
92
+ . finish ( ) ,
93
+ ExternCrate { ref source, ref target } => f
94
+ . debug_struct ( "ExternCrate" )
95
+ . field ( "source" , source)
96
+ . field ( "target" , target)
97
+ . finish ( ) ,
98
+ MacroUse => f. debug_struct ( "MacroUse" ) . finish ( ) ,
99
+ }
100
+ }
101
+ }
102
+
65
103
/// One import.
66
104
#[ derive( Debug , Clone ) ]
67
105
pub ( crate ) struct Import < ' a > {
0 commit comments