Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate doc-comments for generated errors #25

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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
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() {}
7 changes: 6 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use proc_macro2::TokenStream as TokenStream2;
use quote::{format_ident, quote};
use std::vec::Vec;
use std::{format, vec::Vec};
use syn::{punctuated::Punctuated, DeriveInput, Generics, Ident, Token, TypeParamBound, Variant};

use crate::{
Expand Down Expand Up @@ -142,6 +142,10 @@ impl Enum {

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

let error_doc = format!(
"An error type used for converting from [`{parent_ident}`] to [`{child_ident}`]."
);

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

#(#inherited_derives)*

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

Expand Down