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
Rustfmt removes ::
from use statements on Rust 2018 code
#3241
Comments
You need to add a rustfmt.toml with Closing this issue probably needs some docs adding to README.md |
@nrc yes, adding a noticeable explanation about this in the README is a good idea IMO. Thanks for the help! |
This doesn't seem to be working regardless of the edition specified, at least on stable ( cargo new rustfmt-3241
cd rustfmt-3241
echo 'edition = "2018"' > rustfmt.toml
# Using libc instead of the actual ignore crate to speed up compilation
echo 'ignore = { package = "libc", version = "0.2.45" }' >> Cargo.toml
sed -i '1iuse ::ignore;' src/main.rs
cat src/main.rs
# use ::ignore;
# fn main() {
# println!("Hello, world!");
# }
cargo check So far, so good. Now, let's use rustfmt --edition 2018 src/main.rs
cat src/main.rs
# use ignore;
# fn main() {
# println!("Hello, world!");
# }
cargo check
# error[E0658]: imports can only refer to extern crate names passed with `--extern` on stable channel (see issue #53130)
Combined with #3273 and an editor that auto-formats on save, this is somewhat frustrating. |
@Deewiant is the edition set to 2018 in your Cargo.toml too? |
@nrc Yes, as per the default from |
This is quite annoying. It will leave something like |
i'll try to fix this if nobody's on that. |
When transitioning to Rust 2018 edition, it becomes necessary to use
::
in use statements (e.g.use ::actix::prelude::*
) in order to compile one's code. Unfortunatelyrustfmt
removes these when formatting the code.Although
cargo fmt
does work in these cases, many tools actually userustfmt
since it's easier to integrate into editors (e.g.rust-mode
in Emacs). This makes it impossible to write 2018 code in those editors without tweaking.The text was updated successfully, but these errors were encountered: