Skip to content

RPITIT refinement lint false positive when HRTB is involved #116135

Closed
@kawadakk

Description

@kawadakk

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

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]`T-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