|
30 | 30 | use clang;
|
31 | 31 | use parse::ClangItemParser;
|
32 | 32 | use super::context::{BindgenContext, ItemId};
|
33 |
| -use super::derive::CanDeriveCopy; |
| 33 | +use super::derive::{CanDeriveCopy, CanDeriveDebug}; |
| 34 | +use super::layout::Layout; |
34 | 35 | use super::item::Item;
|
35 | 36 | use super::traversal::{EdgeKind, Trace, Tracer};
|
36 | 37 |
|
@@ -148,6 +149,33 @@ impl<'a> CanDeriveCopy<'a> for TemplateInstantiation {
|
148 | 149 | }
|
149 | 150 | }
|
150 | 151 |
|
| 152 | +impl CanDeriveDebug for TemplateInstantiation { |
| 153 | + type Extra = Option<Layout>; |
| 154 | + |
| 155 | + fn can_derive_debug(&self, |
| 156 | + ctx: &BindgenContext, |
| 157 | + layout: Option<Layout>) |
| 158 | + -> bool { |
| 159 | + self.args.iter().all(|arg| arg.can_derive_debug(ctx, ())) && |
| 160 | + ctx.resolve_type(self.definition) |
| 161 | + .as_comp() |
| 162 | + .and_then(|c| { |
| 163 | + // For non-type template parameters, we generate an opaque |
| 164 | + // blob, and in this case the instantiation has a better |
| 165 | + // idea of the layout than the definition does. |
| 166 | + if c.has_non_type_template_params() { |
| 167 | + let opaque = layout.unwrap_or(Layout::zero()).opaque(); |
| 168 | + Some(opaque.can_derive_debug(ctx, ())) |
| 169 | + } else { |
| 170 | + None |
| 171 | + } |
| 172 | + }) |
| 173 | + .unwrap_or_else(|| { |
| 174 | + self.definition.can_derive_debug(ctx, ()) |
| 175 | + }) |
| 176 | + } |
| 177 | +} |
| 178 | + |
151 | 179 | impl Trace for TemplateInstantiation {
|
152 | 180 | type Extra = ();
|
153 | 181 |
|
|
0 commit comments