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

oid! macro assumes der_parser is in the current namespace #46

Closed
lilyball opened this issue Jun 21, 2021 · 4 comments
Closed

oid! macro assumes der_parser is in the current namespace #46

lilyball opened this issue Jun 21, 2021 · 4 comments
Milestone

Comments

@lilyball
Copy link

The oid! macro evaluates to a reference to der_parser::…. This doesn't work if I don't have the crate in my namespace, e.g. if I'm using the macro via use x509_parser::der_parser::oid;. If this was a macro_rules! macro I'd say it needs to be using $crate, I hope proc macros have an equivalent (heck, can they just use $crate directly too?).

@chifflier chifflier added this to the 6.0 milestone Jul 2, 2021
@chifflier
Copy link
Member

As far as I understand, this is not possible now (see discussion and links in rust-lang/rust#54363)
There seems to be a workaround in rust-lang/rust#54647 but I haven't tested it.

@lilyball
Copy link
Author

lilyball commented Jul 2, 2021

Hack idea: make oid!() a macro-by-example in der_parser that just invoked something like _oid!($crate, $($args)*) and have the proc macro be _oid!(). Hopefully this will pass the crate path in correctly so the proc macro can then use it in the generated code.

@yuguorui
Copy link
Contributor

yuguorui commented Jul 8, 2021

Maybe this hack could be the solution...

        format!(
             "{{ 
                  use der_parser::oid;
                  use der_parser::oid::Oid;
                  // this will be the ret value
                  der_parser::oid::Oid::new(alloc::borrow::Cow::Borrowed(&{}))}}",
             s
         )

@chifflier
Copy link
Member

I'm working on this, and will try to find a solution for 6.0.

Workaround: import the re-exported der-parser:

use x509_parser::der_parser;
let oid = der_parser::oid!{ 1.2.3.4 };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants