Skip to content

Crate not found when using extern macro in another macro and invoked from another crate #44817

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

Open
tikue opened this issue Sep 24, 2017 · 1 comment
Assignees
Labels
A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tikue
Copy link
Contributor

tikue commented Sep 24, 2017

// -----------------------------------------------
// serde-test/src/lib.rs

//! This crate provides a macro that creates serializable structs.

#![feature(use_extern_macros)]

#[doc(hidden)]
pub extern crate serde_derive;

#[macro_export]
macro_rules! serde_test {
    () => {
        #[derive($crate::serde_derive::Deserialize, $crate::serde_derive::Serialize)]
        pub struct Serializable {
        }
    }
}

// -----------------------------------------------
// serde-test-test/Cargo.toml

[package]
name = "serde-test-test"
version = "0.1.0"
authors = ["Tim Kuehn <[email protected]>"]

[dependencies]
serde-test = { path = "../serde-test" }

// -----------------------------------------------
// serde-test-test/src/lib.rs

#![feature(use_extern_macros)]

#[macro_use]
extern crate serde_test;

serde_test! {}

In serde-test-test directory:

error[E0463]: can't find crate for `_serde`
 --> src/lib.rs:6:1
  |
6 | serde_test! {}
  | ^^^^^^^^^^^^^^ can't find crate
  |
  = note: this error originates in a macro outside of the current crate

error: aborting due to previous error

error: Could not compile `serde-test-test`.

To learn more, run the command again with --verbose.

This error goes away if you add serde = "*" to serde-test-test/Cargo.toml.

@TimNN TimNN added A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. labels Sep 26, 2017
@jseyfried jseyfried self-assigned this Dec 7, 2017
@jseyfried
Copy link
Contributor

jseyfried commented Dec 7, 2017

The issue here (IIUC) is that the macro serde_derive::Deserialize is unhygienic (macros 1.1) and expands extern crate serde as _serde; to use items from serde. I don't think we'll be able to fix this except with macros 2.0.

@Enselic Enselic added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-decl-macros-2-0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants