Skip to content

cargo fix --edition failed: error: expected item after attributes #139567

Open
@eval-exec

Description

@eval-exec

I tried this code: https://github.com/eval-exec/cargo-migration-2024-bug.git

Execute cargo fix --edition

I expected to see this happen: migration success

Instead, this happened:

    Checking cargo-migration-2024-bug v0.1.0 (/home/exec/Projects/github.com/eval-exec/cargo-migration-2024-bug)
   Migrating src/main.rs from 2021 edition to 2024
warning: failed to automatically apply fixes suggested by rustc to crate `cargo_migration_2024_bug`

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

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: expected item after attributes
 --> src/main.rs:4:1
  |
4 | #[rpc] + use<>
  | ^^^^^^

error: aborting due to 1 previous error

Original diagnostics will follow.

warning: `impl std::future::Future<Output = Result<bool, RpcError>>` will capture more lifetimes than possibly intended in edition 2024
 --> src/main.rs:4:1
  |
4 | #[rpc]
  | ^^^^^^
  |
  = warning: this changes meaning in Rust 2024
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html>
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
 --> src/main.rs:4:1
  |
4 | #[rpc]
  | ^
  = note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024
  = note: `--force-warn impl-trait-overcaptures` implied by `--force-warn rust-2024-compatibility`
  = note: this warning originates in the attribute macro `rpc` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use the precise capturing `use<...>` syntax to make the captures explicit
  |
4 | #[rpc] + use<>
  |        +++++++

warning: `cargo-migration-2024-bug` (bin "cargo-migration-2024-bug") generated 1 warning (run `cargo fix --bin "cargo-migration-2024-bug"` to apply 1 suggestion)
warning: failed to automatically apply fixes suggested by rustc to crate `cargo_migration_2024_bug`

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

  * src/main.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error: expected item after attributes
 --> src/main.rs:4:1
  |
4 | #[rpc] + use<>
  | ^^^^^^

error: aborting due to 1 previous error

Original diagnostics will follow.

warning: `cargo-migration-2024-bug` (bin "cargo-migration-2024-bug" test) generated 1 warning (1 duplicate)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.04s

Meta

rustc --version --verbose:

❯ rustc --version --verbose
rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2024Area: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.F-precise_capturing`#![feature(precise_capturing)]`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