Skip to content

private_in_public lint triggered for pub associated type computed using non-pub trait #45713

@scottmcm

Description

@scottmcm

I was surprised to get a private_in_public deprecation warning for using a private trait to compute an associated type that's itself pub.

De-macro'd, shortened example of what I was doing:

#![feature(try_from)]

trait Bar {
    type Inner;
}

pub struct B16(u16);
pub struct B32(u32);

impl Bar for B16 {
    type Inner = u16;
}
impl Bar for B32 {
    type Inner = u32;
}

use std::convert::{TryFrom, TryInto};
impl TryFrom<B32> for B16 {
    type Error = <<B16 as Bar>::Inner as TryFrom<<B32 as Bar>::Inner>>::Error;
//  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//  warning: private type `<B16 as Bar>::Inner` in public interface (error E0446)
//  (Despite the fact that that actual type is core::num::TryFromIntError)
    fn try_from(x: B32) -> Result<Self, Self::Error> {
       Ok(B16(x.0.try_into()?))
    }
}

fn main() {}

Repro: https://play.rust-lang.org/?gist=1f84c630e07ddd54d2bf208aa85ed8bb&version=nightly

I don't understand how that type is part of the public interface, since I can't get to it using TryFrom.

(Do close if this is known and covered by things like rust-lang/rfcs#1671 (comment), but I couldn't find any issues talking about this part at least.)

Metadata

Metadata

Assignees

Labels

A-visibilityArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.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