Skip to content

private_interfaces not linting RPITIT #143531

Open
@mladedav

Description

@mladedav

Code

trait Bar {}

pub trait Foo {
    fn foo() -> impl Bar;
}

fn main() {}

Current output

Empty output with no warnings.

Desired output

warning: trait `Bar` is more private than the item `Foo::foo`
 --> foo.rs:4:1
  |
4 |     fn foo() -> impl Bar;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `Foo::foo` is reachable at visibility `pub`
  |
note: but trait `Bar` is only usable at visibility `pub(crate)`
 --> foo.rs:1:1
  |
1 | trait Bar {}
  | ^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

warning: 1 warning emitted

Rationale and extra context

No response

Other cases

Both using a concrete type or using RPIT in a method outside traits produce correct lints:

struct X;

pub trait Foo {
    fn foo() -> X;
}

produces

warning: type `X` is more private than the item `Foo::foo`
trait Bar {}
impl Bar for () {}

fn foo() -> impl Bar {}

Produces

warning: trait `Bar` is more private than the item `foo`

Rust Version

rustc 1.90.0-nightly (5adb489a8 2025-07-05)
binary: rustc
commit-hash: 5adb489a8034f7b56b29f3b28af0813c866f679c
commit-date: 2025-07-05
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.L-false-negativeLint: False negative (should have fired but didn't).L-private_interfacesLint: private_interfacesT-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