Is the module name `meta` forbidden?


#1

I encountered something weird: I made a module named meta. But the compiler prints this error:

error[E0463]: can't find crate for `meta`
  --> src/macros/src/lib.rs:21:5
   |
21 | use meta::RustField;
   |     ^^^^ can't find crate

When I rename the module to something else, it works. The error only occurs when the module is named meta.

The error occurs in lib.rs, which is a proc-macro crate. Here are the first lines of the file:

extern crate proc_macro;
use std::collections::HashSet;
use proc_macro::TokenStream as OldStream;

use proc_macro2::{TokenStream, Ident};
use quote::{quote, ToTokens};
use syn::{
    parse_macro_input,
    spanned::Spanned,
    DeriveInput, Data, DataStruct, Field, Fields, Type, Attribute, FieldsNamed,
};

mod attributes;
mod errors;
mod types;
mod meta;

use attributes::{EntityAttribute, FieldAttribute, GetAttributes};
use errors::{MacroResult, err};
use types::get_type;
use meta::RustField;       // error!

I also tried it with nightly rust, but that didn’t make a difference. Is it a bug, or am I doing something wrong?


#2

Use crate::meta::RustField. That’s the new, intended syntax.

An unprefixed path to modules is supported for backwards compatibility, and apparently the fallback has a bug feature.


#3

Thanks, that fixed it.


#4

That’s not quite the issue; under normal circumstances you should never need to write crate::. The specific crate name meta was reserved as a top-level crate name in Rust 2018, to avoid an ever-proliferating set of “built-in” crate names like proc_macro. In the current plan, new built-in crates provided by rustc would go under meta.


#5

@petrochenkov Perhaps a change in diagnostics to say “meta is reserved” is in order?