Description
Summary
During an edition migration (2021
→ 2024
), 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
-
Create a new Rust project.
-
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); } }
-
Run
cargo check
orcargo 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