Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,8 @@ impl FieldCodegen<'_> for FieldData {
};

let mut field = quote! {};
if ctx.options().generate_comments {
if let Some(raw_comment) = self.comment() {
let comment = ctx.options().process_comment(raw_comment);
field = attributes::doc(&comment);
}
if let Some(comment) = self.doc_comment(ctx) {
field = attributes::doc(&comment);
}

let field_name = self
Expand Down Expand Up @@ -3933,14 +3930,11 @@ impl CodeGenerator for Enum {
continue;
}

let mut variant_doc = quote! {};
if ctx.options().generate_comments {
if let Some(raw_comment) = variant.comment() {
let processed_comment =
ctx.options().process_comment(raw_comment);
variant_doc = attributes::doc(&processed_comment);
}
}
let variant_doc = if let Some(comment) = variant.doc_comment(ctx) {
attributes::doc(&comment)
} else {
quote! {}
};

match seen_values.entry(variant.val()) {
Entry::Occupied(ref entry) => {
Expand Down
15 changes: 15 additions & 0 deletions bindgen/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub(crate) trait FieldMethods {
fn ty(&self) -> TypeId;

/// Get the comment for this field.
#[allow(dead_code)] // Used by trait implementations in Field wrapper types
fn comment(&self) -> Option<&str>;

/// If this is a bitfield, how many bits does it need?
Expand Down Expand Up @@ -902,6 +903,20 @@ impl FieldMethods for FieldData {
}
}

impl FieldData {
/// Get this field's documentation comment, if it has any, already preprocessed
/// and with the right indentation. Returns `None` if comment generation is disabled.
pub(crate) fn doc_comment(&self, ctx: &BindgenContext) -> Option<String> {
if !ctx.options().generate_comments {
return None;
}

self.comment
.as_ref()
.map(|comment| ctx.options().process_comment(comment))
}
}

/// The kind of inheritance a base class is using.
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum BaseKind {
Expand Down
13 changes: 10 additions & 3 deletions bindgen/ir/enum_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,16 @@ impl EnumVariant {
self.val
}

/// Get this variant's documentation.
pub(crate) fn comment(&self) -> Option<&str> {
self.comment.as_deref()
/// Get this variant's documentation comment, if it has any, already preprocessed
/// and with the right indentation. Returns `None` if comment generation is disabled.
pub(crate) fn doc_comment(&self, ctx: &BindgenContext) -> Option<String> {
if !ctx.options().generate_comments {
return None;
}

self.comment
.as_ref()
.map(|comment| ctx.options().process_comment(comment))
}

/// Returns whether this variant should be enforced to be a constant by code
Expand Down