Skip to content

Commit 8288b37

Browse files
authored
fix(macros): docs for generated code (#202)
1 parent 9af337a commit 8288b37

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/lintspec-macros/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ workspace = true
1717
proc-macro = true
1818

1919
[dependencies]
20-
unsynn = { version = "0.2.0", default-features = false, features = ["docgen"] }
20+
unsynn = { version = "0.3.0", default-features = false, features = [
21+
"docgen",
22+
"proc_macro2",
23+
] }

crates/lintspec-macros/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#![allow(clippy::doc_markdown)]
22
#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
33
use unsynn::{
4-
BraceGroupContaining, BracketGroupContaining, CommaDelimitedVec, Cons, Either, Error, Except,
5-
Gt, Ident, LiteralString, Lt, Many, Optional, ParenthesisGroupContaining, Parse as _, PathSep,
6-
PathSepDelimited, Pound, ToTokens as _, TokenIter, TokenStream, TokenTree, Transaction,
7-
format_ident, quote, unsynn,
4+
BraceGroupContaining, BracketGroupContaining, CommaDelimitedVec, Cons, Either, Except, Gt,
5+
Ident, LiteralString, Lt, Many, Optional, ParenthesisGroupContaining, Parse as _, PathSep,
6+
PathSepDelimited, Pound, ToTokens as _, TokenStream, TokenTree, format_ident, quote, unsynn,
87
};
98

109
/// Represents a module path, consisting of an optional path separator followed by
@@ -122,12 +121,15 @@ pub fn derive_as_to_variant(input: proc_macro::TokenStream) -> proc_macro::Token
122121
let to_method = format_ident!("to_{variant_name_snake}");
123122
let as_method = format_ident!("as_{variant_name_snake}");
124123
let inner_type = variant.value.body.content.into_token_stream();
125-
// #[doc = #msg] feature is not supported yet
126-
// let _doc_to = format!("Convert to the inner {variant_name_snake} definition.");
127-
// let _doc_as = format!("Reference to the inner {variant_name_snake} definition.");
124+
let doc_to = LiteralString::from_str(format!(
125+
"Convert to the inner {variant_name_snake} definition."
126+
));
127+
let doc_as = LiteralString::from_str(format!(
128+
"Reference to the inner {variant_name_snake} definition."
129+
));
128130

129131
quote! {
130-
/// Convert to the inner definition.
132+
#[doc = #doc_to]
131133
#[must_use]
132134
pub fn #to_method(self) -> Option<#inner_type> {
133135
match self {
@@ -136,7 +138,7 @@ pub fn derive_as_to_variant(input: proc_macro::TokenStream) -> proc_macro::Token
136138
}
137139
}
138140

139-
/// Reference to the inner definition.
141+
#[doc = #doc_as]
140142
#[must_use]
141143
pub fn #as_method(&self) -> Option<&#inner_type> {
142144
match self {

0 commit comments

Comments
 (0)