JelteF / derive_more

Some more derive(Trait) options
MIT License
1.68k stars 117 forks source link

Docs for `AsMut` shows `AsRef` docs instead #398

Open CGMossa opened 1 month ago

CGMossa commented 1 month ago

The issue is seen in https://docs.rs/derive_more/latest/derive_more/derive.AsMut.html#

Here's a screenshot:

image

Suggestion?

It might be this place:

diff --git a/impl/src/lib.rs b/impl/src/lib.rs
index eeccdb0..8fc3c7c 100644
--- a/impl/src/lib.rs
+++ b/impl/src/lib.rs
@@ -134,7 +134,7 @@ create_derive!(
     bit_xor_assign_derive,
 );

-create_derive!("as_ref", r#as::r#mut, AsMut, as_mut_derive, as_mut);
+create_derive!("as_mut", r#as::r#mut, AsMut, as_mut_derive, as_mut);
 create_derive!("as_ref", r#as::r#ref, AsRef, as_ref_derive, as_ref);

 create_derive!("constructor", constructor, Constructor, constructor_derive);

I'm getting a compile error:


   Compiling derive_more v1.0.0 (/Users/elea/Documents/GitHub/derive_more)
error[E0432]: unresolved import `derive_more_impl::AsMut`
   --> src/lib.rs:240:32
    |
240 |     pub use derive_more_impl::{AsMut, AsRef};
    |                                ^^^^^ no `AsMut` in the root
    |
    = help: consider importing one of these items instead:
            core::convert::AsMut
            crate::AsMut
            std::convert::AsMut

For more information about this error, try `rustc --explain E0432`.
error: could not compile `derive_more` (lib) due to 1 previous error

Sorry, I'm either dense or something is slightly wrong.

CGMossa commented 1 month ago

Okay, I did indeed find the right place for this. The change would have to be here in some fashion. Here's an attempt:

diff --git a/impl/src/lib.rs b/impl/src/lib.rs
index eeccdb0..0eebc3b 100644
--- a/impl/src/lib.rs
+++ b/impl/src/lib.rs
@@ -97,9 +97,12 @@ impl Output for Result<proc_macro2::TokenStream, ParseError> {

 macro_rules! create_derive(
     ($feature:literal, $mod_:ident $(:: $mod_rest:ident)*, $trait_:ident, $fn_name: ident $(,$attribute:ident)* $(,)?) => {
+        create_derive!($feature, $feature, $mod_ $(:: $mod_rest)*, $trait_, $fn_name $(,$attribute)*);
+    };
+    ($feature:literal, $documentation:literal, $mod_:ident $(:: $mod_rest:ident)*, $trait_:ident, $fn_name: ident $(,$attribute:ident)* $(,)?) => {
         #[cfg(feature = $feature)]
         #[proc_macro_derive($trait_, attributes($($attribute),*))]
-        #[doc = include_str!(concat!("../doc/", $feature, ".md"))]
+        #[doc = include_str!(concat!("../doc/", $documentation, ".md"))]
         pub fn $fn_name(input: TokenStream) -> TokenStream {
             let ast = syn::parse(input).unwrap();
             Output::process($mod_$(:: $mod_rest)*::expand(&ast, stringify!($trait_)))
@@ -134,7 +137,7 @@ create_derive!(
     bit_xor_assign_derive,
 );

-create_derive!("as_ref", r#as::r#mut, AsMut, as_mut_derive, as_mut);
+create_derive!("as_ref", "as_mut", r#as::r#mut, AsMut, as_mut_derive, as_mut);
 create_derive!("as_ref", r#as::r#ref, AsRef, as_ref_derive, as_ref);

 create_derive!("constructor", constructor, Constructor, constructor_derive);
CGMossa commented 1 week ago

Hello @JelteF. Sorry for the ping, I just want to say, that there is this issue too, and it has a suggested solution, although it is not too elegant. What do you think?

JelteF commented 1 week ago

Afaict this is another instance of https://github.com/JelteF/derive_more/issues/348, it's a bit special because previously AsMut and AsRef had different implementations and thus different documentation. But my preference would be to remove the copy pasted as_mut.md file from the repo and mention at the top that the derive for AsMut its very similar to AsRef.