Skip to content

RPITIT refinement lint false positive when HRTB is involved #116135

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

Closed
kawadakk opened this issue Sep 25, 2023 · 0 comments · Fixed by #116149
Closed

RPITIT refinement lint false positive when HRTB is involved #116135

kawadakk opened this issue Sep 25, 2023 · 0 comments · Fixed by #116149
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kawadakk
Copy link
Contributor

kawadakk commented Sep 25, 2023

Code

#![feature(return_position_impl_trait_in_trait)]

pub trait Tr<T> {
    fn foo() -> impl for<'a> Tr<&'a Self>;
}

impl<T> Tr<T> for () {
    fn foo() -> impl for<'a> Tr<&'a Self> {}
}

(Playground)

Current output

warning: impl trait in impl method signature does not match trait method signature
 --> src/lib.rs:8:22
  |
4 |     fn foo() -> impl for<'a> Tr<&'a Self>;
  |                 ------------------------- return type from trait method defined here
...
8 |     fn foo() -> impl for<'a> Tr<&'a Self> {}
  |                      ^^^^^^^^^^^^^^^^^^^^ 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: `#[warn(refining_impl_trait)]` on by default
help: replace the return type so that it matches the trait
  |
8 |     fn foo() -> impl for<'a> Tr<&'a Self> {}
  |                 ~~~~~~~~~~~~~~~~~~~~~~~~~

Desired output

No warnings

Rationale and extra context

Can be reproduced in:

  • rustc 1.74.0-nightly (13e6f24b9 2023-09-23)
  • rustc 1.74.0-nightly (37390d656 2023-09-24)

Other cases

No response

Anything else?

No response

@kawadakk kawadakk 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 Sep 25, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 25, 2023
@saethlin saethlin added F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 25, 2023
@compiler-errors compiler-errors self-assigned this Sep 25, 2023
@bors bors closed this as completed in 50417a5 Sep 27, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 27, 2023
Rollup merge of rust-lang#116149 - compiler-errors:anonymize, r=lcnr

Anonymize binders for `refining_impl_trait` check

We're naively using the equality impl for `ty::Clause` in the refinement check, which is okay *except* for binders, which carry some information about where they come from in the AST. Those locations are not gonna be equal between traits and impls, so anonymize those clauses so that this doesn't matter.

Fixes rust-lang#116135
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 F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` 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.

4 participants