Skip to content

poor diagnostic for missing extern crate in 2015 edition #112809

Open
@Deaths-Door

Description

@Deaths-Door

Description:

I have recently published a crate named kmmp-structure on crates.io and added it as a dependency to my kmmp-generator crate. In the Cargo.toml file of kmmp-generator, I have added the following dependency:

[dependencies]
kmmp-structure = "0.1.2"

I expect to be able to use the structs and code defined in the kmmp-structure crate without using the extern crate syntax, as I have successfully done with other crates like serde_json and clap in the past.

However, when I try to use the kmmp-structure crate in my code by adding the following line in kmmp-generator's lib.rs file:

pub use kmmp_structure::*;

Or

use kmmp_structure::{
    project::{
        Project,
        Module,
    },
    gradle::{
        gradle_file::{
            ModuleContent,
            ModuleGradle,
            SettingsGradle
        },
        metadata::GradleProperties
    }
};

Cargo shows an error indicating a missing crate:

--> src\lib\mod.rs:6:9
   |
6  | pub use kmmp_structure::*;
   |         ^^^^^^^^^^^^^^ maybe a missing crate `kmmp_structure`?
   |

But then adding extern crate resolves the issue

extern crate kmmp_structure;
pub use kmmp_structure::*;

Strangely, if I specify the precise path to the struct, the code compiles without any issues and i have tested this point with different structs in different paths

impl Generate for kmmp_structure::....::ModuleGradle<'_>

Meta

rustc --version --verbose:

rustc 1.70.0 (90c541806 2023-05-31)
binary: rustc
commit-hash: 90c541806f23a127002de5b4038be731ba1458ca
commit-date: 2023-05-31
host: x86_64-pc-windows-msvc
release: 1.70.0
LLVM version: 16.0.2

cargo --version --verbose

cargo 1.70.0 (ec8a8a0ca 2023-04-25)
release: 1.70.0
commit-hash: ec8a8a0cabb0e0cadef58902470f6c7ee7868bdc
commit-date: 2023-04-25
host: x86_64-pc-windows-msvc
libgit2: 1.6.3 (sys:0.17.0 vendored)
libcurl: 8.0.1-DEV (sys:0.4.61+curl-8.0.1 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Home) [64-bit]

I am using the stable version of the Rust compiler.

Please note that both crates (kmmp-structure and kmmp-generator) are written by me and are using the same tool versions. I have successfully used other crates without the need for extern crate in the past or with other crates like serde_json

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-editionDiagnostics: An error or lint that should account for edition differences.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions