Skip to content

2015 edition: unresolved import due to missing extern crate should be smarter and suggest upgrading edition #160026

Description

@camelid

Code

playground

(assuming serde_json is passed via --extern or in Cargo.toml, and edition is 2015)

pub use serde_json::to_string;

Current output

error[E0432]: unresolved import `serde_json`
 --> src/lib.rs:1:5
  |
1 | use serde_json::to_string;
  |     ^^^^^^^^^^ use of unresolved module or unlinked crate `serde_json`
  |
help: if you wanted to use a crate named `serde_json`, use `cargo add serde_json` to add it to your `Cargo.toml` and import it in your code
  |
1 + extern crate serde_json;
  |

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

error[E0432]: unresolved import `serde_json`
 --> src/lib.rs:1:5
  |
1 | use serde_json::to_string;
  |     ^^^^^^^^^^ use of unresolved module or unlinked crate `serde_json`
  |
help: `extern crate` is required on Rust 2015
  |
1 + extern crate serde_json;
  |
help: consider upgrading to a newer edition (latest is 2024) to avoid needing `extern crate`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` (lib) due to 1 previous error

Rationale and extra context

No response

Other cases

Rust Version

1.97.1

Anything else?

Suggested by @workingjubilee: #t-compiler/major changes > Emit `note` when calling `rustc` without… compiler-team#1019 @ 💬
cc rust-lang/compiler-team#1019

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-editionDiagnostics: An error or lint that should account for edition differences.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions