Repository navigation
poor diagnostic for missing extern crate in 2015 edition #112809
Description
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
albertlarsan68 commentedon Jun 19, 2023
What is the full content of the
Cargo.tomlfile?ehuss commentedon Jun 19, 2023
The
Cargo.tomlofkmmp-generatordoes not specify an edition, which defaults to 2015.Deaths-Door commentedon Jun 21, 2023
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
albertlarsan68 commentedon Jun 21, 2023
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 newcommand 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.
[-]Unable to Import Dependency Without extern crate in Rust 2023 edition[/-][+]poor diagnostic for missing extern crate in 2015 edition[/+]Rollup merge of rust-lang#161210 - chenyukang:yukang-fix-160026-exter…
Unrolled build for #161210 in rollup 161840