Skip to content
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

omitting edition produces unexpected errors #14023

Closed
sancho20021 opened this issue Jun 7, 2024 · 3 comments
Closed

omitting edition produces unexpected errors #14023

sancho20021 opened this issue Jun 7, 2024 · 3 comments
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@sancho20021
Copy link

Problem

If there is no edition = "2021" line in Cargo.toml, the project can't be build because of:

error[E0432]: unresolved import `rustfix`
 --> ghostcellify/src/main.rs:1:5
  |
1 | use rustfix::Suggestion;
  |     ^^^^^^^ maybe a missing crate `rustfix`?
  |
  = help: consider adding `extern crate rustfix` to use the `rustfix` crate

error[E0432]: unresolved import `itertools`
 --> ghostcellify/src/main.rs:2:5
  |
2 | use itertools::Itertools;
  |     ^^^^^^^^^ maybe a missing crate `itertools`?
  |
  = help: consider adding `extern crate itertools` to use the `itertools` crate

For more information about this error, try `rustc --explain E0432`.
error: could not compile `ghostcelltf` (bin "ghostcelltf") due to 2 previous errors

This is unexpected. I would like to know why is this happening? What edition is used when edition is omitted?

Steps

  1. Project structure and contents:
.
├── Cargo.toml
└── src
    └── main.rs

Cargo.toml:

[package]
name = "ghostcelltf"
version = "0.1.0"
# edition = "2021"

[dependencies]
rustfix = "0.8.2"
itertools = "0.9.0"

src/main.rs:

use rustfix::Suggestion;
use itertools::Itertools;

fn main() {
}
  1. How to reproduce?
> cargo build
error[E0432]: unresolved import `itertools`
 --> ghostcellify/src/main.rs:2:5

Note that if explicitly set the edition to 2021, the project builds fine.

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.78.0 (54d8815d0 2024-03-26)
release: 1.78.0
commit-hash: 54d8815d04fa3816edc207bbc4dd36bf18014dbc
commit-date: 2024-03-26
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 20.04 (focal) [64-bit]
@sancho20021 sancho20021 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jun 7, 2024
@weihanglo
Copy link
Member

It defaults to 2015, and you need extern crate xxx to make them usable. See also https://doc.rust-lang.org/edition-guide/rust-2018/path-changes.html#no-more-extern-crate

@weihanglo weihanglo added S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. labels Jun 7, 2024
@sancho20021
Copy link
Author

Ooo I see, it is said in documentation about 2015 default: https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html#enabling-the-new-edition-to-use-new-features

Thank you, I will close the issue

@sancho20021
Copy link
Author

default is 2015 which corresponds to the described behavior. Documentation mentions this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

2 participants