-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.F-return_type_notation`#[feature(return_type_notation)]``#[feature(return_type_notation)]`L-refining_impl_traitLint group: refining_impl_traitLint group: refining_impl_traitT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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 lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.F-return_type_notation`#[feature(return_type_notation)]``#[feature(return_type_notation)]`L-refining_impl_traitLint group: refining_impl_traitLint group: refining_impl_traitT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.