Skip to content

poor diagnostic for missing extern crate in 2015 edition #112809

Closed

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

Activity

  1. albertlarsan68 commented on Jun 19, 2023

    @albertlarsan68
    Member

    What is the full content of the Cargo.toml file?

  2. ehuss commented on Jun 19, 2023

    @ehuss
    Contributor

    The Cargo.toml of kmmp-generator does not specify an edition, which defaults to 2015.

  3. Deaths-Door commented on Jun 21, 2023

    @Deaths-Door
    Author

    Yes that's the issue , after specifically setting the edition it works , however shouldnt the complier give a warning that it is using rust 2015 with cargo and rustc 2023 in 2023

  4. albertlarsan68 commented on Jun 21, 2023

    @albertlarsan68
    Member

    It is documented in most places that the default edition is 2015, as before 2018 there was no concept of editions and Rust wants to be backwards compatible.
    The cargo new command will default to the newest stable edition however.
    Also FYI, there is no such thing as 2023 Edition. The closest ones are 2021 and (in the future, if everything goes as planned) 2024.

  5. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    D-editionDiagnostics: An error or lint that should account for edition differences.
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    and removed
    C-bugCategory: This is a bug.
    on Jun 30, 2023
  6. changed the title [-]Unable to Import Dependency Without extern crate in Rust 2023 edition[/-] [+]poor diagnostic for missing extern crate in 2015 edition[/+] on Jun 30, 2023
  7. added a commit that references this issue on Aug 26, 2026
    0591d9a
  8. added a commit that references this issue on Aug 27, 2026
    74ddead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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