Skip to content

Commit

Permalink
Generate doc-comments for generated errors
Browse files Browse the repository at this point in the history
  • Loading branch information
paholg committed Sep 19, 2023
1 parent 063d56b commit a28925c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This project follows semantic versioning.

### Unreleased
- [fixed] Support for `#![deny(missing_docs)]`.

### 1.1.0 (2023-09-18)
- [added] Default feature `std` and support for no-std.
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ keywords = ["enum", "sub-enum", "no-std"]
proc-macro = true
name = "subenum"

[[example]]
name = "require_docs"

[dev-dependencies]
derive_more = "0.99.17"
strum = { version = "0.24.1", features = ["derive"], default-features = false }
Expand Down
19 changes: 19 additions & 0 deletions examples/require_docs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![deny(missing_docs)]
//! An example of using subenum with `#![deny(missing_docs)]`.
//!
//! This is an example because the aforementioned attribute doesn't work in
//! tests.

use subenum::subenum;

/// An enum.
#[subenum(Bar)]
pub enum Foo {
/// Variant A
#[subenum(Bar)]
A,
/// Variant B
B,
}

fn main() {}
8 changes: 8 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ impl Enum {

let (parent_impl, parent_ty, parent_where) = parent.generics.split_for_impl();

#[cfg(feature = "std")]
let error_doc = format!(
"A generated error type for converting from [`{parent_ident}`] to [`{child_ident}`]."
);
#[cfg(not(feature = "std"))]
let error_doc = "A generated error type from converting from a child enum to its parent.";

quote!(
#(#[ #attributes ])*
#(#child_attrs)*
Expand All @@ -151,6 +158,7 @@ impl Enum {

#(#inherited_derives)*

#[doc = #error_doc]
#[derive(Copy, Clone, Debug)]
#vis struct #error;

Expand Down

0 comments on commit a28925c

Please sign in to comment.