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

Docs for AsMut shows AsRef docs instead #398

Open
CGMossa opened this issue Aug 12, 2024 · 3 comments
Open

Docs for AsMut shows AsRef docs instead #398

CGMossa opened this issue Aug 12, 2024 · 3 comments
Labels

Comments

@CGMossa
Copy link

CGMossa commented Aug 12, 2024

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
Copy link
Author

CGMossa commented Aug 12, 2024

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
Copy link
Author

CGMossa commented Sep 8, 2024

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
Copy link
Owner

JelteF commented Sep 8, 2024

Afaict this is another instance of #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.

@JelteF JelteF added the docs label Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants