-
Notifications
You must be signed in to change notification settings - Fork 46
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
Consider allowing to rename the crate by passing an attribute crate = ...
to the proc-macro
#221
Comments
crate = ...
to the proc-macro
Nice catch!!! This issue is just related to The bug is here: I assume that you have imported rstest/rstest_macros/src/render/inject.rs Line 103 in b32e182
I don't know how I can fix it but I can investigate is there is a way to identify the new crate name on compile time and use it in procedural macro. |
Seams https://docs.rs/proc-macro-crate/latest/proc_macro_crate does the job... but is not really clean and some edge-case are not covered. The base Idea is to parse the |
Having the attribute But for other people that don't, that would be nice if the new name of the crate could be inferred with |
I'm not sure if I understand your point correctly... in procedural macro I cannot use |
By
I mean something like: #[cfg(test)]
mod tests {
use super::*;
use renamed_rstest::rstest;
#[rstest(crate = "renamed_rstest")]
#[case("2", "2", "22")]
fn it_works(#[case] left: &str, #[case] right: &str, #[case] expected: &str) {
assert_eq!(join(left, right), expected);
}
} Where the proc-macro
use tokio as tokio1;
#[tokio1::test(crate = "tokio1")]
async fn my_test() {
println!("Hello world");
} |
Ok.... I got it. I don't love it but is pragmatic. The downside here is that you should write it in all tests 😢
The real issue here is.... I don't know when I'll can do it 😢 |
Take a look to substrate/primitives/api/proc-macro/src/utils.rs where thy solve the issue |
I'm not sure to understand what you mean. I can't find a file named |
Sorry.. it was just a note for me... in https://github.com/paritytech/polkadot-sdk/blob/master/substrate/primitives/api/proc-macro/src/utils.rs they handling the same problem and solve it without introducing the string name needs. |
Ok, I've implemented it. Now you can import and use it with any name:
and in your code use
I'll publish this version ASAP |
Oh, nice I'll try that this week :) |
Currently the crate
rstest
cannot be renamed.That would be nice if it could have something like the proc-macro
tokio::test
where you can rename the crate by providing the attributecrate
: https://docs.rs/tokio-macros/latest/tokio_macros/attr.test.html#rename-packageReproduction steps
I've create a simple rust project with
cargo new --lib rstest-renamed-bug
and edited the following files:src/lib.rs
with the following content:Cargo.toml
with the following content:How does that expand ?
If we look at the expanded code using
cargo-expand
:We have the following rust output:
The problem is caused by the
use rstest::magic_conversion::*;
linesThe text was updated successfully, but these errors were encountered: