From 74892700857cf51ba1a15c84814e6938dd43fc2e Mon Sep 17 00:00:00 2001 From: Lucien XU Date: Wed, 22 Feb 2023 10:25:59 +0100 Subject: [PATCH] Made sure (doc) attributs are propagated to trait This commit propagates attributes to the generated trait, so that doc (among other attributes) are correctly available in the generated trait. --- .github/workflows/ci.yml | 13 +++++++++++++ pretend-codegen/src/lib.rs | 2 ++ tests/doc-propagation/Cargo.toml | 10 ++++++++++ tests/doc-propagation/src/lib.rs | 13 +++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 tests/doc-propagation/Cargo.toml create mode 100644 tests/doc-propagation/src/lib.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 353573c..b9e6714 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,19 @@ jobs: - run: cd tests/default-features-build && cargo test + test-doc-propagation: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + default: true + + - run: cd tests/doc-propagation && cargo test + test-msrv-check: runs-on: ubuntu-latest steps: diff --git a/pretend-codegen/src/lib.rs b/pretend-codegen/src/lib.rs index 5366324..cae066c 100644 --- a/pretend-codegen/src/lib.rs +++ b/pretend-codegen/src/lib.rs @@ -29,6 +29,7 @@ fn implement_pretend(attr: PretendAttr, item: ItemTrait) -> Result let name = &item.ident; let vis = &item.vis; let items = &item.items; + let attrs = &item.attrs; let trait_items = items.iter().map(trait_item).collect::>(); let kind = parse_client_kind(name, attr, items)?; @@ -43,6 +44,7 @@ fn implement_pretend(attr: PretendAttr, item: ItemTrait) -> Result let send_sync = send_sync_traits_impl(&kind); let tokens = quote! { #attr + #(#attrs)* #vis trait #name { #(#trait_items)* } diff --git a/tests/doc-propagation/Cargo.toml b/tests/doc-propagation/Cargo.toml new file mode 100644 index 0000000..1c013b1 --- /dev/null +++ b/tests/doc-propagation/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "pretend-test-doc-propagation" +version = "0.0.0" +edition = "2018" + +[dependencies] +pretend = { path = "../../pretend" } +pretend-codegen = { path = "../../pretend-codegen" } + +[workspace] diff --git a/tests/doc-propagation/src/lib.rs b/tests/doc-propagation/src/lib.rs new file mode 100644 index 0000000..540f7ab --- /dev/null +++ b/tests/doc-propagation/src/lib.rs @@ -0,0 +1,13 @@ +//! Test crate + +#![forbid(missing_docs)] + +use pretend::{pretend, Result}; + +/// This REST endpoints tests documentation features +#[pretend] +trait TestTrait { + /// Documentation for a simple method + #[request(method = "GET", path = "/api/v1/test")] + async fn test(&self) -> Result; +}