Skip to content

private_interfaces not linting RPITIT #143531

Closed

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

Activity

  1. added
    A-diagnostics
    T-compiler
    on Jul 6, 2025
  2. added
    A-lints
    A-impl-trait
    L-private_interfaces
    L-false-negative
    A-visibility
    C-bug
    and removed
    A-diagnostics
    on Jul 6, 2025
  3. mladedav commented on Jul 16, 2025

    @mladedav
    ContributorAuthor

    After merging #143357 the original code now outputs the following error:

    warning: trait `Bar` is more private than the item `Foo::foo::{anon_assoc#0}`
     --> src/main.rs:4:17
      |
    4 |     fn foo() -> impl Bar;
      |                 ^^^^^^^^ opaque type `Foo::foo::{anon_assoc#0}` is reachable at visibility `pub`
      |
    note: but trait `Bar` is only usable at visibility `pub(crate)`
     --> src/main.rs:1:1
      |
    1 | trait Bar {}
      | ^^^^^^^^^
      = note: `#[warn(private_bounds)]` on by default
    

    So now the lint could just have an improved message but it's no longer a false negative as of nightly-2025-07-15.

  4. added a commit that references this issue on Jul 19, 2025
  5. added a commit that references this issue on Jul 19, 2025
  6. added a commit that references this issue on Jul 21, 2025
  7. petrochenkov commented on Feb 12, 2026

    @petrochenkov
    Contributor

    Fixed in #151168, tests were added earlier in #144098.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitA-lintsA-visibilityC-bugL-false-negativeL-private_interfacesT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions