Skip to content

cargo fix inserts invalid trait bound + use<>, compiles silently without error #141586

Closed as not planned
@alfredjstanley

Description

@alfredjstanley

Summary

During an edition migration (20212024), running cargo fix --edition inserted the following return type:

fn get_id_hash_sets(id_sets: &[&[(IdType, &str)]]) -> impl Iterator<Item = IdHashSet> + use<> {

Despite use being a reserved keyword and not a valid trait, the compiler accepts this code without any errors or warnings. This behavior occurs both in test modules and in regular code, potentially leading to undetected bugs.


Reproduction Steps

  1. Create a new Rust project.

  2. Add the following code to main.rs:

    fn get_stuff() -> impl Iterator<Item = u32> + use<> {
        vec![1, 2, 3].into_iter()
    }
    
    fn main() {
        for i in get_stuff() {
            println!("{}", i);
        }
    }
  3. Run cargo check or cargo build.


Expected Behavior

The compiler should produce an error indicating that use is a reserved keyword and cannot be used as a trait bound.


Actual Behavior

The code compiles successfully without any errors or warnings.


Version Information

$ rustc --version
rustc 1.87.0 (17067e9ac 2025-05-09)

$ cargo --version
cargo 1.87.0

Additional Notes

  • This issue was discovered after running cargo fix --edition, which inserted the invalid trait bound.

  • The problem persists in both test modules and regular code.

  • The compiler's silent acceptance of invalid syntax could lead to subtle bugs and undermines Rust's safety guarantees.


Labels

  • C-bug

  • T-compiler

  • T-cargo

  • A-impl-trait

  • A-suggestion-diagnostics

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions