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

Better error for extern crate accidental-hyphen #48437

Closed
gibfahn opened this issue Feb 22, 2018 · 1 comment
Closed

Better error for extern crate accidental-hyphen #48437

gibfahn opened this issue Feb 22, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@gibfahn
Copy link
Contributor

gibfahn commented Feb 22, 2018

AIUI currently the standard is for crate names to be hyphenated, but the module name (not sure on the correct terminology) must be underscored.

For example you add bit-vec to the Cargo.toml, but extern crate bit_vec; to src/lib.rs.

image

cargo new rust-foo && cd rust-foo
cargo add bit_vec
sed -i '1s/^/extern crate bit-vec;\n/' src/lib.rs
cat src/lib.rs
cargo build
sed -i 's/bit-vec/bit_vec/' src/lib.rs
cargo build

So instead of this error, it would be great if the compiler could suggest extern crate bit_vec;.

cargo build                                                                                                                                                                       ~/tmp/rust-foo (!✦)
   Compiling foo v0.1.0 (file:///Users/gib/tmp/rust-foo)
error: expected one of `;` or `as`, found `-`
 --> src/lib.rs:1:17
  |
1 | extern crate bit-vec;
  |                 ^ expected one of `;` or `as` here

error: aborting due to previous error

error: Could not compile `foo`.

To learn more, run the command again with --verbose.

Came from a discussion with @nrc on twitter: https://twitter.com/gibfahn/status/966755092383739904

I couldn't find an existing issue for this, sorry if it's a duplicate.

@sfackler sfackler added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 22, 2018
@estebank estebank added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Feb 22, 2018
@steveklabnik
Copy link
Member

Related, this will also be more important post-edition, when the extern crate line goes away, but an incorrect use with the crate name is in it.

kennytm added a commit to kennytm/rust that referenced this issue Jul 28, 2018
Suggest underscore when using dashes in crate namet push fork

Fix rust-lang#48437.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants