Skip to content

Lint group refining_impl_trait: Enabling return_type_notation negatively affects the suggested fix #151663

@fmease

Description

@fmease

Given the following snippet

trait Trait { fn f() -> impl Sized; }

impl Trait for () { fn f() {} }

the compiler emits a correct suggestion:

warning: impl trait in impl method signature does not match trait method signature
 --> src/lib.rs:3:21
  |
1 | trait Trait { fn f() -> impl Sized; }
  |                         ---------- return type from trait method defined here
2 |
3 | impl Trait for () { fn f() {} }
  |                     ^^^^^^
  |
  = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
  = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
  = note: `#[warn(refining_impl_trait_internal)]` (part of `#[warn(refining_impl_trait)]`) on by default
help: replace the return type so that it matches the trait
  |
3 | impl Trait for () { fn f()-> impl Sized  {} }
  |                           +++++++++++++

However, if you enable the feature return_type_notation the suggestion will be different and invalid:

#![feature(return_type_notation)]

trait Trait { fn f() -> impl Sized; }

impl Trait for () { fn f() {} }
warning: impl trait in impl method signature does not match trait method signature
 --> src/lib.rs:5:21
  |
3 | trait Trait { fn f() -> impl Sized; }
  |                         ---------- return type from trait method defined here
4 |
5 | impl Trait for () { fn f() {} }
  |                     ^^^^^^
  |
  = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
  = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
  = note: `#[warn(refining_impl_trait_internal)]` (part of `#[warn(refining_impl_trait)]`) on by default
help: replace the return type so that it matches the trait
  |
5 | impl Trait for () { fn f()-> impl Sized { <Self as Trait>::f(..) }  {} }
  |                           ++++++++++++++++++++++++++++++++++++++++

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.F-return_type_notation`#[feature(return_type_notation)]`L-refining_impl_traitLint group: refining_impl_traitT-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