Skip to content

2024 impl_trait_overcaptures ambiguous + #132853

Closed
@ehuss

Description

@ehuss

I tried this code:

#![warn(impl_trait_overcaptures)]

pub fn f(x: &i32) -> &impl Clone {
    x
}

I expected to see this happen: Provides a valid suggestion that is -> &(impl Clone + use<>) with parentheses to avoid ambiguity.

Instead, this happened: Provides a suggestion that includes &impl Clone + use<> which fails to parse with:

error: ambiguous `+` in a type
 --> src/main.rs:3:23
  |
3 | pub fn f(x: &i32) -> &impl Clone + use<> {
  |                       ^^^^^^^^^^^^^^^^^^
  |
help: try adding parentheses
  |
3 | pub fn f(x: &i32) -> &(impl Clone + use<>) {
  |                       +                  +

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (b91a3a056 2024-11-07)
binary: rustc
commit-hash: b91a3a05609a46f73d23e0995ae7ebb4a4f429a5
commit-date: 2024-11-07
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.3

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-edition-2024Area: The 2024 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-editionDiagnostics: An error or lint that should account for edition differences.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-impl_trait_overcapturesLint: impl_trait_overcapturesT-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