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

cargo fix produces incorrect code when removing last unused dependency next to self as __ syntax #133750

Open
bragov4ik opened this issue Dec 2, 2024 · 1 comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-dead_code Lint: dead_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bragov4ik
Copy link

I encountered incorrect code being produced by cargo fix command.

Code

mod bakery_module {
    pub struct Cheesecake;

    #[derive(Debug)]
    pub struct Cupcake;
}

use bakery_module::{self as moms_spaghetti, Cheesecake};

fn main() {
    dbg!(moms_spaghetti::Cupcake);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=205e34f726214436ef250b91b4d025f2

Meta

stable rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1

nightly rustc --version --verbose:

rustc 1.85.0-nightly (5e1440ae5 2024-12-01)
binary: rustc
commit-hash: 5e1440ae514d98ddfcbf1607acb64d41e07ef616
commit-date: 2024-12-01
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.4

Error output

warning: `test-field` (bin "test-field") generated 2 warnings (run `cargo fix --bin "test-field"` to apply 1 suggestion)
warning: failed to automatically apply fixes suggested by rustc to crate `test_field`

after fixes were automatically applied the compiler reported errors within these files:

  * src/main.rs

<here I removed notice about making an issue into this repo>

The following errors were reported:
error[E0429]: `self` imports are only allowed within a { } list
 --> src/main.rs:8:18
  |
8 | use bakery_module::self as moms_spaghetti;
  |                  ^^^^^^
  |
help: consider importing the module directly
  |
8 - use bakery_module::self as moms_spaghetti;
8 + use bakery_module as moms_spaghetti;
  |
help: alternatively, use the multi-path `use` syntax to import `self`
  |
8 | use bakery_module::{self as moms_spaghetti};
  |                    +                      +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0429`.
Original diagnostics will follow.

warning: `test-field` (bin "test-field" test) generated 2 warnings (2 duplicates)
Backtrace

No backtrace

@bragov4ik bragov4ik added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 2, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 2, 2024
@bragov4ik
Copy link
Author

couldn't find more appropriate template, thus chose ICE

@fmease fmease added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-dead_code Lint: dead_code and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-dead_code Lint: dead_code T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants