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

Nested maps don't compile #183

Open
piegamesde opened this issue Oct 25, 2019 · 3 comments · May be fixed by #242
Open

Nested maps don't compile #183

piegamesde opened this issue Oct 25, 2019 · 3 comments · May be fixed by #242
Labels

Comments

@piegamesde
Copy link

let map = phf_map!{
	"foo" => phf_map!{"k"=>"v"}
};

Compile error:

error[E0659]: `proc_macro_call` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
  --> src/main.rs:57:12
   |
57 |       let map = phf_map!{
   |  _______________^
58 | |         "foo" => phf_map!{"k"=>"v"}
59 | |     };
   | |_____^ ambiguous name
   |
note: `proc_macro_call` could refer to the macro defined here
  --> src/main.rs:57:12
   |
57 |       let map = phf_map!{
   |  _______________^
58 | |         "foo" => phf_map!{"k"=>"v"}
59 | |     };
   | |_____^
note: `proc_macro_call` could also refer to the macro defined here
  --> src/main.rs:57:12
   |
57 |       let map = phf_map!{
   |  _______________^
58 | |         "foo" => phf_map!{"k"=>"v"}
59 | |     };
   | |_____^
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
@x10an14
Copy link

x10an14 commented Mar 29, 2020

This is a desired feature for me too, until Rustlang decides whether to implement BTree or HashMap map! macro...

@stephanemagnenat
Copy link

I stumbled upon this limitation as well. This should at least be documented, so that a potential user of this crate does not invest a lot of time (e.g. to write a code generator for recursive phf data structures) before realising this is not supported.

@Darksonn
Copy link

For anyone who runs in to this, note that this compiles just fine:

use phf::phf_map;

type InnerMap = phf::Map<&'static str, Option<&'static str>>;

static INNER1: InnerMap = phf_map! {
    "foo" => None,
    "bar" => Some("abc"),
};
static INNER2: InnerMap = phf_map! {
    "baz" => None,
    "bar" => Some("abc"),
};

static MY_MAP: phf::Map<&'static str, &'static InnerMap> = phf_map! {
    "hello" => &INNER1,
    "world" => &INNER2,
};

@vbe0201 vbe0201 linked a pull request Oct 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants