Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refining_impl_trait suggestion in invalid code #129404

Closed
cyrgani opened this issue Aug 22, 2024 · 0 comments · Fixed by #129417
Closed

refining_impl_trait suggestion in invalid code #129404

cyrgani opened this issue Aug 22, 2024 · 0 comments · Fixed by #129417
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Aug 22, 2024

Code

trait FromRow {
    fn prepare(self) -> impl Fn() -> T;
}

impl<T> FromRow for T {
    fn prepare(self) -> impl Fn() -> T {
        || loop {}
    }
}

Current output

error[E0412]: cannot find type `T` in this scope
 --> src/lib.rs:2:38
  |
2 |     fn prepare(self) -> impl Fn() -> T;
  |                                      ^ not found in this scope

warning: impl trait in impl method signature does not match trait method signature
 --> src/lib.rs:6:38
  |
2 |     fn prepare(self) -> impl Fn() -> T;
  |                         -------------- return type from trait method defined here
...
6 |     fn prepare(self) -> impl Fn() -> T {
  |                                      ^ this bound is stronger than that defined on the trait
  |
  = 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)]` on by default
help: replace the return type so that it matches the trait
  |
6 |     fn prepare(self) -> impl Fn() -> {type error} {
  |                         ~~~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0412`.

Desired output

error[E0412]: cannot find type `T` in this scope
 --> src/lib.rs:2:38
  |
2 |     fn prepare(self) -> impl Fn() -> T;
  |                                      ^ not found in this scope

Rationale and extra context

Not sure if this is worth fixing, but the warning message is not helpful here at all and the suggestion fn prepare(self) -> impl Fn() -> {type error} is not usable.

Other cases

No response

Rust Version

rustc 1.80.1

Anything else?

No response

@cyrgani cyrgani added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 22, 2024
@cyrgani cyrgani changed the title refining_impl_trait refining_impl_trait suggestion in invalid code Aug 22, 2024
@compiler-errors compiler-errors self-assigned this Aug 22, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 22, 2024
Don't trigger refinement lint if predicates reference errors

Fixes rust-lang#129404
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 22, 2024
Don't trigger refinement lint if predicates reference errors

Fixes rust-lang#129404
@bors bors closed this as completed in 32821b9 Aug 23, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 23, 2024
Rollup merge of rust-lang#129417 - compiler-errors:refine-err, r=lqd

Don't trigger refinement lint if predicates reference errors

Fixes rust-lang#129404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants