Skip to content

Proc-macro derivative::Derivative unresolved #7459

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

Closed
edwin0cheng opened this issue Jan 27, 2021 · 18 comments
Closed

Proc-macro derivative::Derivative unresolved #7459

edwin0cheng opened this issue Jan 27, 2021 · 18 comments
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@edwin0cheng
Copy link
Member

image
Not working for me unfortunately.

image

Settings are on true

➜ rustc --version
rustc 1.51.0-nightly (da305a2b0 2021-01-05)

Originally posted by @aaomidi in #6053 (comment)

@edwin0cheng
Copy link
Member Author

[Copy from original issue]

@aaomidi Confirm your bug in rustc-stable,

maybe related to cfg_attr(not(test)...) ?

https://github.com/mcarton/rust-derivative/blob/770c67484a872470ca782202e13fc70a35e2695b/src/lib.rs#L76-L80

#[cfg_attr(not(test), proc_macro_derive(Derivative, attributes(derivative)))]
pub fn derivative(input: TokenStream) -> TokenStream {
    let mut errors = proc_macro2::TokenStream::new();

    let mut output = match syn::parse::<syn::DeriveInput>(input) {
        Ok(parsed) => {
            ast::Input::from_ast(&parsed, &mut errors)
                .map(|mut input| derive_impls(&mut input, &mut errors))
                .unwrap_or_default()
        },
        Err(error) => {
            errors.extend(error.to_compile_error());
            Default::default()
        }
    };

    output.extend(errors);
    output.into()
}

@jonas-schievink
Copy link
Contributor

maybe related to cfg_attr(not(test)...) ?

Yeah that's it. We always set cfg(test).

@flodiebold
Copy link
Member

So, this is kind of related to #6117, #2414 and #7225.

@lnicola lnicola added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Jan 27, 2021
@aaomidi
Copy link

aaomidi commented Jan 28, 2021

Confirmed the bug is in stable too. Although I'm not 100% sure how to make sure rust-analyzer is running with the stable toolchain. I just used rustup to change the default and hoped for the best.

@Rua
Copy link

Rua commented Apr 22, 2021

I'm running into this as well with Derivative, using rustc 1.52.0-beta.3, rust-analyzer version: 2021-04-12-92-g7570212a5.

@edwin0cheng
Copy link
Member Author

edwin0cheng commented Apr 22, 2021

It will be fixed by the last item of #8486 :

  • correctly handle "duplicated" crates in the crate graph. I.e, when cfg(test) crate depends on itself without cfg(test).

@sbrocket
Copy link

sbrocket commented Jul 8, 2021

8b77e26 appears to have fixed this with some manual intervention; you can now add derivative to rust-analyzer.cargo.unsetTest (and then reload the window or restart the RA server).

@cheako
Copy link

cheako commented Aug 29, 2021

I used use derivative::*; and it's better.

@sunilkr
Copy link

sunilkr commented Feb 13, 2022

I still have this issue with use derivative::Derivative;. use derivative::*; just removes the unresolved error, but docs on hover or any such feature of VSCode doesn't work. It compiles just fine though. Is there a plan to fix this? I am using default RA settings.

RA: 
Released on    2/10/2020, 14:54:28
Last updated   2/9/2022, 06:16:38
Identifier     matklad.rust-analyzer
$ rustc -V
rustc 1.56.1 (59eed8a2a 2021-11-01)

@flodiebold
Copy link
Member

@sunilkr Right now, you will need to use the rust-analyzer.cargo.unsetTest setting.

LiptonB added a commit to LiptonB/building-git that referenced this issue Feb 20, 2022
@zeenix
Copy link

zeenix commented May 4, 2022

It's been more than 1.4 years of this issue, any update on it getting resolved soon?

@lnicola
Copy link
Member

lnicola commented May 4, 2022

There is a workaround in the comment above.

@zeenix
Copy link

zeenix commented May 4, 2022

There is a workaround in the comment above.

Thanks but the workaround needs to be applied by each dev on their own. I got people looking at my crate's source (possibly contributing) and getting annoyed by my use of derivative.

@bjorn3
Copy link
Member

bjorn3 commented May 4, 2022

You can set it in the .vscode/settings.json file in your repository. Then it will apply to everyone opening your project.

@zeenix
Copy link

zeenix commented May 4, 2022

You can set it in the .vscode/settings.json file in your repository. Then it will apply to everyone opening your project.

Thanks, that's much better indeed. Still that means every project having to do this.

@cyqsimon
Copy link

cyqsimon commented May 28, 2022

Is this issue fixed now? I had a project that used the use derivative::*; workaround, but today when I checked, use derivative::Derivative; no longer seems to error on my Linux box (rust v1.61.0). Can someone please help confirm/refute this finding?

cyqsimon added a commit to cyqsimon/rng-rename that referenced this issue May 28, 2022
@zeenix
Copy link

zeenix commented May 29, 2022

@cyqsimon Yeah, I am unable to reproduce either.

@flodiebold
Copy link
Member

This is fixed now, unless you're using derivative as a path dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests