Replace old private-in-public diagnostic with type privacy lints

This commit is contained in:
Bryanskiy 2023-06-19 17:06:00 +03:00
parent 5cbfee5455
commit e26614e6a7
68 changed files with 862 additions and 1700 deletions

View File

@ -607,6 +607,7 @@ E0794: include_str!("./error_codes/E0794.md"),
// E0420, // merged into 532
// E0421, // merged into 531
// E0427, // merged into 530
// E0445, // merged into 446 and type privacy lints
// E0456, // plugin `..` is not available for triple `..`
// E0465, // removed: merged with E0464
// E0467, // removed

View File

@ -1,10 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.
A private trait was used on a public type parameter bound.
Erroneous code examples:
```compile_fail,E0445
#![deny(private_in_public)]
Previously erroneous code examples:
```
trait Foo {
fn dummy(&self) { }
}

View File

@ -1,16 +1,16 @@
A private type was used in a public type signature.
A private type or trait was used in a public associated type signature.
Erroneous code example:
```compile_fail,E0446
#![deny(private_in_public)]
struct Bar(u32);
struct Bar;
mod foo {
use crate::Bar;
pub fn bar() -> Bar { // error: private type in public interface
Bar(0)
}
pub trait PubTr {
type Alias;
}
impl PubTr for u8 {
type Alias = Bar; // error private type in public interface
}
fn main() {}
@ -22,13 +22,14 @@ This is done by using pub(crate) or pub(in crate::my_mod::etc)
Example:
```
struct Bar(u32);
struct Bar;
mod foo {
use crate::Bar;
pub(crate) fn bar() -> Bar { // only public to crate root
Bar(0)
}
pub(crate) trait PubTr { // only public to crate root
type Alias;
}
impl PubTr for u8 {
type Alias = Bar;
}
fn main() {}
@ -38,12 +39,15 @@ The other way to solve this error is to make the private type public.
Example:
```
pub struct Bar(u32); // we set the Bar type public
mod foo {
use crate::Bar;
pub fn bar() -> Bar { // ok!
Bar(0)
}
pub struct Bar; // we set the Bar trait public
pub trait PubTr {
type Alias;
}
impl PubTr for u8 {
type Alias = Bar;
}
fn main() {}

View File

@ -516,6 +516,11 @@ fn register_builtins(store: &mut LintStore) {
"converted into hard error, see issue #82523 \
<https://github.com/rust-lang/rust/issues/82523> for more information",
);
store.register_removed(
"private_in_public",
"replaced with another group of lints, see RFC \
<https://rust-lang.github.io/rfcs/2145-type-privacy.html> for more information",
);
}
fn register_internals(store: &mut LintStore) {

View File

@ -982,44 +982,6 @@ declare_lint! {
"detects trivial casts of numeric types which could be removed"
}
declare_lint! {
/// The `private_in_public` lint detects private items in public
/// interfaces not caught by the old implementation.
///
/// ### Example
///
/// ```rust
/// # #![allow(unused)]
/// struct SemiPriv;
///
/// mod m1 {
/// struct Priv;
/// impl super::SemiPriv {
/// pub fn f(_: Priv) {}
/// }
/// }
/// # fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The visibility rules are intended to prevent exposing private items in
/// public interfaces. This is a [future-incompatible] lint to transition
/// this to a hard error in the future. See [issue #34537] for more
/// details.
///
/// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PRIVATE_IN_PUBLIC,
Warn,
"detect private items in public interfaces not caught by the old implementation",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
};
}
declare_lint! {
/// The `invalid_alignment` lint detects dereferences of misaligned pointers during
/// constant evaluation.
@ -3374,7 +3336,6 @@ declare_lint_pass! {
PATTERNS_IN_FNS_WITHOUT_BODY,
POINTER_STRUCTURAL_MATCH,
PRIVATE_BOUNDS,
PRIVATE_IN_PUBLIC,
PRIVATE_INTERFACES,
PROC_MACRO_BACK_COMPAT,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
@ -4293,9 +4254,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(unused)]
/// # #![allow(private_in_public)]
/// #![deny(private_interfaces)]
/// struct SemiPriv;
///
@ -4316,9 +4275,8 @@ declare_lint! {
/// Having something private in primary interface guarantees that
/// the item will be unusable from outer modules due to type privacy.
pub PRIVATE_INTERFACES,
Allow,
Warn,
"private type in primary interface of an item",
@feature_gate = sym::type_privacy_lints;
}
declare_lint! {
@ -4329,8 +4287,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(type_privacy_lints)]
/// # #![allow(private_in_public)]
/// # #![allow(unused)]
/// #![deny(private_bounds)]
///
@ -4348,9 +4304,8 @@ declare_lint! {
/// Having private types or traits in item bounds makes it less clear what interface
/// the item actually provides.
pub PRIVATE_BOUNDS,
Allow,
Warn,
"private type in secondary interface of an item",
@feature_gate = sym::type_privacy_lints;
}
declare_lint! {

View File

@ -1222,7 +1222,6 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher);
// Hash visibility information since it does not appear in HIR.
resolutions.visibilities.hash_stable(&mut hcx, &mut stable_hasher);
resolutions.has_pub_restricted.hash_stable(&mut hcx, &mut stable_hasher);
stable_hasher.finish()
});

View File

@ -162,8 +162,6 @@ pub struct ResolverOutputs {
#[derive(Debug)]
pub struct ResolverGlobalCtxt {
pub visibilities: FxHashMap<LocalDefId, Visibility>,
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
pub has_pub_restricted: bool,
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
pub effective_visibilities: EffectiveVisibilities,

View File

@ -11,11 +11,6 @@ privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interfac
privacy_item_is_private = {$kind} `{$descr}` is private
.label = private {$kind}
privacy_private_in_public_lint =
{$vis_descr} {$kind} `{$descr}` in public interface (error {$kind ->
[trait] E0445
*[other] E0446
})
privacy_private_interface_or_bounds_lint = {$ty_kind} `{$ty_descr}` is more private than the item `{$item_descr}`
.item_label = {$item_kind} `{$item_descr}` is reachable at visibility `{$item_vis_descr}`

View File

@ -47,21 +47,6 @@ pub struct UnnamedItemIsPrivate {
pub kind: &'static str,
}
// Duplicate of `InPublicInterface` but with a different error code, shares the same slug.
#[derive(Diagnostic)]
#[diag(privacy_in_public_interface, code = "E0445")]
pub struct InPublicInterfaceTraits<'a> {
#[primary_span]
#[label]
pub span: Span,
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: DiagnosticArgFromDisplay<'a>,
#[label(privacy_visibility_label)]
pub vis_span: Span,
}
// Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug.
#[derive(Diagnostic)]
#[diag(privacy_in_public_interface, code = "E0446")]
pub struct InPublicInterface<'a> {
@ -91,14 +76,6 @@ pub struct FromPrivateDependencyInPublicInterface<'a> {
pub krate: Symbol,
}
#[derive(LintDiagnostic)]
#[diag(privacy_private_in_public_lint)]
pub struct PrivateInPublicLint<'a> {
pub vis_descr: &'static str,
pub kind: &'a str,
pub descr: DiagnosticArgFromDisplay<'a>,
}
#[derive(LintDiagnostic)]
#[diag(privacy_unnameable_types_lint)]
pub struct UnnameableTypesLint<'a> {

View File

@ -22,7 +22,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{AssocItemKind, ForeignItemKind, HirIdSet, ItemId, Node, PatKind};
use rustc_hir::{AssocItemKind, ForeignItemKind, ItemId, Node, PatKind};
use rustc_middle::bug;
use rustc_middle::hir::nested_filter;
use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility, Level};
@ -42,8 +42,8 @@ use std::{fmt, mem};
use errors::{
FieldIsPrivate, FieldIsPrivateLabel, FromPrivateDependencyInPublicInterface, InPublicInterface,
InPublicInterfaceTraits, ItemIsPrivate, PrivateInPublicLint, PrivateInterfacesOrBoundsLint,
ReportEffectiveVisibility, UnnameableTypesLint, UnnamedItemIsPrivate,
ItemIsPrivate, PrivateInterfacesOrBoundsLint, ReportEffectiveVisibility, UnnameableTypesLint,
UnnamedItemIsPrivate,
};
fluent_messages! { "../messages.ftl" }
@ -364,6 +364,7 @@ trait VisibilityLike: Sized {
find.min
}
}
impl VisibilityLike for ty::Visibility {
const MAX: Self = ty::Visibility::Public;
fn new_min<const SHALLOW: bool>(
@ -1373,345 +1374,6 @@ impl<'tcx> DefIdVisitor<'tcx> for TypePrivacyVisitor<'tcx> {
}
}
///////////////////////////////////////////////////////////////////////////////
/// Obsolete visitors for checking for private items in public interfaces.
/// These visitors are supposed to be kept in frozen state and produce an
/// "old error node set". For backward compatibility the new visitor reports
/// warnings instead of hard errors when the erroneous node is not in this old set.
///////////////////////////////////////////////////////////////////////////////
struct ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
effective_visibilities: &'a EffectiveVisibilities,
in_variant: bool,
// Set of errors produced by this obsolete visitor.
old_error_set: HirIdSet,
}
struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
inner: &'a ObsoleteVisiblePrivateTypesVisitor<'b, 'tcx>,
/// Whether the type refers to private types.
contains_private: bool,
/// Whether we've recurred at all (i.e., if we're pointing at the
/// first type on which `visit_ty` was called).
at_outer_type: bool,
/// Whether that first type is a public path.
outer_type_is_public_path: bool,
}
impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
fn path_is_private_type(&self, path: &hir::Path<'_>) -> bool {
let did = match path.res {
Res::PrimTy(..) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } | Res::Err => {
return false;
}
res => res.def_id(),
};
// A path can only be private if:
// it's in this crate...
if let Some(did) = did.as_local() {
// .. and it corresponds to a private type in the AST (this returns
// `None` for type parameters).
match self.tcx.hir().find(self.tcx.hir().local_def_id_to_hir_id(did)) {
Some(Node::Item(_)) => !self.tcx.visibility(did).is_public(),
Some(_) | None => false,
}
} else {
false
}
}
fn trait_is_public(&self, trait_id: LocalDefId) -> bool {
// FIXME: this would preferably be using `exported_items`, but all
// traits are exported currently (see `EmbargoVisitor.exported_trait`).
self.effective_visibilities.is_directly_public(trait_id)
}
fn check_generic_bound(&mut self, bound: &hir::GenericBound<'_>) {
if let hir::GenericBound::Trait(ref trait_ref, _) = *bound {
if self.path_is_private_type(trait_ref.trait_ref.path) {
self.old_error_set.insert(trait_ref.trait_ref.hir_ref_id);
}
}
}
fn item_is_public(&self, def_id: LocalDefId) -> bool {
self.effective_visibilities.is_reachable(def_id) || self.tcx.visibility(def_id).is_public()
}
}
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> {
fn visit_generic_arg(&mut self, generic_arg: &'v hir::GenericArg<'v>) {
match generic_arg {
hir::GenericArg::Type(t) => self.visit_ty(t),
hir::GenericArg::Infer(inf) => self.visit_ty(&inf.to_ty()),
hir::GenericArg::Lifetime(_) | hir::GenericArg::Const(_) => {}
}
}
fn visit_ty(&mut self, ty: &hir::Ty<'_>) {
if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind {
if self.inner.path_is_private_type(path) {
self.contains_private = true;
// Found what we're looking for, so let's stop working.
return;
}
}
if let hir::TyKind::Path(_) = ty.kind {
if self.at_outer_type {
self.outer_type_is_public_path = true;
}
}
self.at_outer_type = false;
intravisit::walk_ty(self, ty)
}
// Don't want to recurse into `[, .. expr]`.
fn visit_expr(&mut self, _: &hir::Expr<'_>) {}
}
impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
type NestedFilter = nested_filter::All;
/// We want to visit items in the context of their containing
/// module and so forth, so supply a crate for doing a deep walk.
fn nested_visit_map(&mut self) -> Self::Map {
self.tcx.hir()
}
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
match item.kind {
// Contents of a private mod can be re-exported, so we need
// to check internals.
hir::ItemKind::Mod(_) => {}
// An `extern {}` doesn't introduce a new privacy
// namespace (the contents have their own privacies).
hir::ItemKind::ForeignMod { .. } => {}
hir::ItemKind::Trait(.., bounds, _) => {
if !self.trait_is_public(item.owner_id.def_id) {
return;
}
for bound in bounds.iter() {
self.check_generic_bound(bound)
}
}
// Impls need some special handling to try to offer useful
// error messages without (too many) false positives
// (i.e., we could just return here to not check them at
// all, or some worse estimation of whether an impl is
// publicly visible).
hir::ItemKind::Impl(ref impl_) => {
// `impl [... for] Private` is never visible.
let self_contains_private;
// `impl [... for] Public<...>`, but not `impl [... for]
// Vec<Public>` or `(Public,)`, etc.
let self_is_public_path;
// Check the properties of the `Self` type:
{
let mut visitor = ObsoleteCheckTypeForPrivatenessVisitor {
inner: self,
contains_private: false,
at_outer_type: true,
outer_type_is_public_path: false,
};
visitor.visit_ty(impl_.self_ty);
self_contains_private = visitor.contains_private;
self_is_public_path = visitor.outer_type_is_public_path;
}
// Miscellaneous info about the impl:
// `true` iff this is `impl Private for ...`.
let not_private_trait = impl_.of_trait.as_ref().map_or(
true, // no trait counts as public trait
|tr| {
if let Some(def_id) = tr.path.res.def_id().as_local() {
self.trait_is_public(def_id)
} else {
true // external traits must be public
}
},
);
// `true` iff this is a trait impl or at least one method is public.
//
// `impl Public { $( fn ...() {} )* }` is not visible.
//
// This is required over just using the methods' privacy
// directly because we might have `impl<T: Foo<Private>> ...`,
// and we shouldn't warn about the generics if all the methods
// are private (because `T` won't be visible externally).
let trait_or_some_public_method = impl_.of_trait.is_some()
|| impl_.items.iter().any(|impl_item_ref| {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..) => self
.effective_visibilities
.is_reachable(impl_item_ref.id.owner_id.def_id),
hir::ImplItemKind::Type(_) => false,
}
});
if !self_contains_private && not_private_trait && trait_or_some_public_method {
intravisit::walk_generics(self, &impl_.generics);
match impl_.of_trait {
None => {
for impl_item_ref in impl_.items {
// This is where we choose whether to walk down
// further into the impl to check its items. We
// should only walk into public items so that we
// don't erroneously report errors for private
// types in private items.
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item.kind {
hir::ImplItemKind::Const(..) | hir::ImplItemKind::Fn(..)
if self.item_is_public(impl_item.owner_id.def_id) =>
{
intravisit::walk_impl_item(self, impl_item)
}
hir::ImplItemKind::Type(..) => {
intravisit::walk_impl_item(self, impl_item)
}
_ => {}
}
}
}
Some(ref tr) => {
// Any private types in a trait impl fall into three
// categories.
// 1. mentioned in the trait definition
// 2. mentioned in the type params/generics
// 3. mentioned in the associated types of the impl
//
// Those in 1. can only occur if the trait is in
// this crate and will have been warned about on the
// trait definition (there's no need to warn twice
// so we don't check the methods).
//
// Those in 2. are warned via walk_generics and this
// call here.
intravisit::walk_path(self, tr.path);
// Those in 3. are warned with this call.
for impl_item_ref in impl_.items {
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
if let hir::ImplItemKind::Type(ty) = impl_item.kind {
self.visit_ty(ty);
}
}
}
}
} else if impl_.of_trait.is_none() && self_is_public_path {
// `impl Public<Private> { ... }`. Any public static
// methods will be visible as `Public::foo`.
let mut found_pub_static = false;
for impl_item_ref in impl_.items {
if self
.effective_visibilities
.is_reachable(impl_item_ref.id.owner_id.def_id)
|| self.tcx.visibility(impl_item_ref.id.owner_id).is_public()
{
let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
match impl_item_ref.kind {
AssocItemKind::Const => {
found_pub_static = true;
intravisit::walk_impl_item(self, impl_item);
}
AssocItemKind::Fn { has_self: false } => {
found_pub_static = true;
intravisit::walk_impl_item(self, impl_item);
}
_ => {}
}
}
}
if found_pub_static {
intravisit::walk_generics(self, &impl_.generics)
}
}
return;
}
// `type ... = ...;` can contain private types, because
// we're introducing a new name.
hir::ItemKind::TyAlias(..) => return,
// Not at all public, so we don't care.
_ if !self.item_is_public(item.owner_id.def_id) => {
return;
}
_ => {}
}
// We've carefully constructed it so that if we're here, then
// any `visit_ty`'s will be called on things that are in
// public signatures, i.e., things that we're interested in for
// this visitor.
intravisit::walk_item(self, item);
}
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
for predicate in generics.predicates {
match predicate {
hir::WherePredicate::BoundPredicate(bound_pred) => {
for bound in bound_pred.bounds.iter() {
self.check_generic_bound(bound)
}
}
hir::WherePredicate::RegionPredicate(_) => {}
hir::WherePredicate::EqPredicate(eq_pred) => {
self.visit_ty(eq_pred.rhs_ty);
}
}
}
}
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem<'tcx>) {
if self.effective_visibilities.is_reachable(item.owner_id.def_id) {
intravisit::walk_foreign_item(self, item)
}
}
fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) {
if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = t.kind {
if self.path_is_private_type(path) {
self.old_error_set.insert(t.hir_id);
}
}
intravisit::walk_ty(self, t)
}
fn visit_variant(&mut self, v: &'tcx hir::Variant<'tcx>) {
if self.effective_visibilities.is_reachable(v.def_id) {
self.in_variant = true;
intravisit::walk_variant(self, v);
self.in_variant = false;
}
}
fn visit_field_def(&mut self, s: &'tcx hir::FieldDef<'tcx>) {
let vis = self.tcx.visibility(s.def_id);
if vis.is_public() || self.in_variant {
intravisit::walk_field_def(self, s);
}
}
// We don't need to introspect into these at all: an
// expression/block context can't possibly contain exported things.
// (Making them no-ops stops us from traversing the whole AST without
// having to be super careful about our `walk_...` calls above.)
fn visit_block(&mut self, _: &'tcx hir::Block<'tcx>) {}
fn visit_expr(&mut self, _: &'tcx hir::Expr<'tcx>) {}
}
///////////////////////////////////////////////////////////////////////////////
/// SearchInterfaceForPrivateItemsVisitor traverses an item's interface and
/// finds any private components in it.
@ -1725,7 +1387,6 @@ struct SearchInterfaceForPrivateItemsVisitor<'tcx> {
/// The visitor checks that each component type is at least this visible.
required_visibility: ty::Visibility,
required_effective_vis: Option<EffectiveVisibility>,
has_old_errors: bool,
in_assoc_ty: bool,
in_primary_interface: bool,
}
@ -1796,7 +1457,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id);
let span = self.tcx.def_span(self.item_def_id.to_def_id());
let vis_span = self.tcx.def_span(def_id);
if !vis.is_at_least(self.required_visibility, self.tcx) {
if self.in_assoc_ty && !vis.is_at_least(self.required_visibility, self.tcx) {
let vis_descr = match vis {
ty::Visibility::Public => "public",
ty::Visibility::Restricted(vis_def_id) => {
@ -1810,35 +1471,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
}
};
if self.has_old_errors
|| self.in_assoc_ty
|| self.tcx.resolutions(()).has_pub_restricted
{
if kind == "trait" {
self.tcx.sess.emit_err(InPublicInterfaceTraits {
span,
vis_descr,
kind,
descr: descr.into(),
vis_span,
});
} else {
self.tcx.sess.emit_err(InPublicInterface {
span,
vis_descr,
kind,
descr: descr.into(),
vis_span,
});
}
} else {
self.tcx.emit_spanned_lint(
lint::builtin::PRIVATE_IN_PUBLIC,
hir_id,
span,
PrivateInPublicLint { vis_descr, kind, descr: descr.into() },
);
}
self.tcx.sess.emit_err(InPublicInterface {
span,
vis_descr,
kind,
descr: descr.into(),
vis_span,
});
return false;
}
let Some(effective_vis) = self.required_effective_vis else {
@ -1909,7 +1549,6 @@ impl<'tcx> DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
struct PrivateItemsInPublicInterfacesChecker<'tcx, 'a> {
tcx: TyCtxt<'tcx>,
old_error_set_ancestry: HirIdSet,
effective_visibilities: &'a EffectiveVisibilities,
}
@ -1925,9 +1564,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> {
item_def_id: def_id,
required_visibility,
required_effective_vis,
has_old_errors: self
.old_error_set_ancestry
.contains(&self.tcx.hir().local_def_id_to_hir_id(def_id)),
in_assoc_ty: false,
in_primary_interface: true,
}
@ -2282,35 +1918,8 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
let effective_visibilities = tcx.effective_visibilities(());
let mut visitor = ObsoleteVisiblePrivateTypesVisitor {
tcx,
effective_visibilities,
in_variant: false,
old_error_set: Default::default(),
};
tcx.hir().walk_toplevel_module(&mut visitor);
let mut old_error_set_ancestry = HirIdSet::default();
for mut id in visitor.old_error_set.iter().copied() {
loop {
if !old_error_set_ancestry.insert(id) {
break;
}
let parent = tcx.hir().parent_id(id);
if parent == id {
break;
}
id = parent;
}
}
// Check for private types and traits in public interfaces.
let mut checker = PrivateItemsInPublicInterfacesChecker {
tcx,
old_error_set_ancestry,
effective_visibilities,
};
// Check for private types in public interfaces.
let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities };
for id in tcx.hir().items() {
checker.check_item(id);

View File

@ -247,8 +247,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
})
}
ast::VisibilityKind::Restricted { ref path, id, .. } => {
// Make `PRIVATE_IN_PUBLIC` lint a hard error.
self.r.has_pub_restricted = true;
// For visibilities we are not ready to provide correct implementation of "uniform
// paths" right now, so on 2018 edition we only allow module-relative paths for now.
// On 2015 edition visibilities are resolved as crate-relative by default,

View File

@ -980,7 +980,6 @@ pub struct Resolver<'a, 'tcx> {
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
/// Visibilities in "lowered" form, for all entities that have them.
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
has_pub_restricted: bool,
used_imports: FxHashSet<NodeId>,
maybe_unused_trait_imports: FxIndexSet<LocalDefId>,
@ -1319,7 +1318,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
glob_map: Default::default(),
visibilities,
has_pub_restricted: false,
used_imports: FxHashSet::default(),
maybe_unused_trait_imports: Default::default(),
@ -1435,7 +1433,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
let expn_that_defined = self.expn_that_defined;
let visibilities = self.visibilities;
let has_pub_restricted = self.has_pub_restricted;
let extern_crate_map = self.extern_crate_map;
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
let glob_map = self.glob_map;
@ -1453,7 +1450,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let global_ctxt = ResolverGlobalCtxt {
expn_that_defined,
visibilities,
has_pub_restricted,
effective_visibilities,
extern_crate_map,
module_children: self.module_children,

View File

@ -1,26 +1,15 @@
// check-pass
#![feature(inherent_associated_types)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]
#![crate_type = "lib"]
#![deny(private_in_public)]
#![warn(private_interfaces)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
pub type PubAlias0 = PubTy::PrivAssocTy;
//~^ ERROR private associated type `PubTy::PrivAssocTy` in public interface (error E0446)
//~| WARNING this was previously accepted
//~| WARNING associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0`
//~^ WARNING associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0`
pub type PubAlias1 = PrivTy::PubAssocTy;
//~^ ERROR private type `PrivTy` in public interface (error E0446)
//~| WARNING this was previously accepted
//~| WARNING type `PrivTy` is more private than the item `PubAlias1`
//~^ WARNING type `PrivTy` is more private than the item `PubAlias1`
pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
//~^ ERROR private type `PrivTy` in public interface (error E0446)
//~| WARNING this was previously accepted
//~| WARNING type `PrivTy` is more private than the item `PubAlias2`
//~^ WARNING type `PrivTy` is more private than the item `PubAlias2`
pub struct PubTy;
impl PubTy {

View File

@ -1,75 +1,39 @@
error: private associated type `PubTy::PrivAssocTy` in public interface (error E0446)
--> $DIR/private-in-public.rs:12:1
|
LL | pub type PubAlias0 = PubTy::PrivAssocTy;
| ^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: the lint level is defined here
--> $DIR/private-in-public.rs:5:9
|
LL | #![deny(private_in_public)]
| ^^^^^^^^^^^^^^^^^
warning: associated type `PubTy::PrivAssocTy` is more private than the item `PubAlias0`
--> $DIR/private-in-public.rs:12:1
--> $DIR/private-in-public.rs:7:1
|
LL | pub type PubAlias0 = PubTy::PrivAssocTy;
| ^^^^^^^^^^^^^^^^^^ type alias `PubAlias0` is reachable at visibility `pub`
|
note: but associated type `PubTy::PrivAssocTy` is only usable at visibility `pub(crate)`
--> $DIR/private-in-public.rs:27:5
--> $DIR/private-in-public.rs:16:5
|
LL | type PrivAssocTy = ();
| ^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/private-in-public.rs:6:9
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^
error: private type `PrivTy` in public interface (error E0446)
--> $DIR/private-in-public.rs:16:1
|
LL | pub type PubAlias1 = PrivTy::PubAssocTy;
| ^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
= note: `#[warn(private_interfaces)]` on by default
warning: type `PrivTy` is more private than the item `PubAlias1`
--> $DIR/private-in-public.rs:16:1
--> $DIR/private-in-public.rs:9:1
|
LL | pub type PubAlias1 = PrivTy::PubAssocTy;
| ^^^^^^^^^^^^^^^^^^ type alias `PubAlias1` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/private-in-public.rs:31:1
--> $DIR/private-in-public.rs:20:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
error: private type `PrivTy` in public interface (error E0446)
--> $DIR/private-in-public.rs:20:1
|
LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
| ^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
warning: type `PrivTy` is more private than the item `PubAlias2`
--> $DIR/private-in-public.rs:20:1
--> $DIR/private-in-public.rs:11:1
|
LL | pub type PubAlias2 = PubTy::PubAssocTy<PrivTy>;
| ^^^^^^^^^^^^^^^^^^ type alias `PubAlias2` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/private-in-public.rs:31:1
--> $DIR/private-in-public.rs:20:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
error: aborting due to 3 previous errors; 3 warnings emitted
warning: 3 warnings emitted

View File

@ -1,12 +1,6 @@
#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]
#![warn(private_interfaces)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
pub struct Const<const U: u8>;
@ -21,7 +15,6 @@ where
{
type AssocTy = Const<{ my_const_fn(U) }>;
//~^ ERROR private type
//~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
fn assoc_fn() -> Self::AssocTy {
Const
}

View File

@ -1,5 +1,5 @@
error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface
--> $DIR/eval-privacy.rs:22:5
--> $DIR/eval-privacy.rs:16:5
|
LL | type AssocTy = Const<{ my_const_fn(U) }>;
| ^^^^^^^^^^^^ can't leak private type
@ -7,23 +7,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>;
LL | const fn my_const_fn(val: u8) -> u8 {
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
--> $DIR/eval-privacy.rs:22:5
|
LL | type AssocTy = Const<{ my_const_fn(U) }>;
| ^^^^^^^^^^^^ associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub`
|
note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)`
--> $DIR/eval-privacy.rs:30:1
|
LL | const fn my_const_fn(val: u8) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/eval-privacy.rs:5:9
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted
error: aborting due to previous error
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,23 +0,0 @@
#![feature(type_privacy_lints)]
#[warn(private_bounds)]
#[warn(private_interfaces)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
trait Foo {
fn dummy(&self) { }
}
pub trait Bar : Foo {}
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| WARNING trait `Foo` is more private than the item `Bar`
pub struct Bar2<T: Foo>(pub T);
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| WARNING trait `Foo` is more private than the item `Bar2`
pub fn foo<T: Foo> (t: T) {}
//~^ ERROR private trait `Foo` in public interface [E0445]
//~| WARNING trait `Foo` is more private than the item `foo`
fn main() {}

View File

@ -1,71 +0,0 @@
error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:13:1
|
LL | trait Foo {
| --------- `Foo` declared as private
...
LL | pub trait Bar : Foo {}
| ^^^^^^^^^^^^^^^^^^^ can't leak private trait
warning: trait `Foo` is more private than the item `Bar`
--> $DIR/E0445.rs:13:1
|
LL | pub trait Bar : Foo {}
| ^^^^^^^^^^^^^^^^^^^ trait `Bar` is reachable at visibility `pub`
|
note: but trait `Foo` is only usable at visibility `pub(crate)`
--> $DIR/E0445.rs:9:1
|
LL | trait Foo {
| ^^^^^^^^^
note: the lint level is defined here
--> $DIR/E0445.rs:2:8
|
LL | #[warn(private_bounds)]
| ^^^^^^^^^^^^^^
error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:16:1
|
LL | trait Foo {
| --------- `Foo` declared as private
...
LL | pub struct Bar2<T: Foo>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
warning: trait `Foo` is more private than the item `Bar2`
--> $DIR/E0445.rs:16:1
|
LL | pub struct Bar2<T: Foo>(pub T);
| ^^^^^^^^^^^^^^^^^^^^^^^ struct `Bar2` is reachable at visibility `pub`
|
note: but trait `Foo` is only usable at visibility `pub(crate)`
--> $DIR/E0445.rs:9:1
|
LL | trait Foo {
| ^^^^^^^^^
error[E0445]: private trait `Foo` in public interface
--> $DIR/E0445.rs:19:1
|
LL | trait Foo {
| --------- `Foo` declared as private
...
LL | pub fn foo<T: Foo> (t: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
warning: trait `Foo` is more private than the item `foo`
--> $DIR/E0445.rs:19:1
|
LL | pub fn foo<T: Foo> (t: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub`
|
note: but trait `Foo` is only usable at visibility `pub(crate)`
--> $DIR/E0445.rs:9:1
|
LL | trait Foo {
| ^^^^^^^^^
error: aborting due to 3 previous errors; 3 warnings emitted
For more information about this error, try `rustc --explain E0445`.

View File

@ -1,9 +1,14 @@
mod foo {
struct Bar(u32);
struct Bar;
trait PrivTr {}
pub fn bar() -> Bar { //~ ERROR E0446
Bar(0)
}
pub trait PubTr {
type Alias1;
type Alias2;
}
impl PubTr for u8 {
type Alias1 = Bar; //~ ERROR E0446
type Alias2 = Box<dyn PrivTr>; //~ ERROR E0446
}
fn main() {}

View File

@ -1,12 +1,21 @@
error[E0446]: private type `Bar` in public interface
--> $DIR/E0446.rs:4:5
--> $DIR/E0446.rs:10:5
|
LL | struct Bar(u32);
| ---------- `Bar` declared as private
LL |
LL | pub fn bar() -> Bar {
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
LL | struct Bar;
| ---------- `Bar` declared as private
...
LL | type Alias1 = Bar;
| ^^^^^^^^^^^ can't leak private type
error: aborting due to previous error
error[E0446]: private trait `PrivTr` in public interface
--> $DIR/E0446.rs:11:5
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
...
LL | type Alias2 = Box<dyn PrivTr>;
| ^^^^^^^^^^^ can't leak private trait
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,11 +1,5 @@
// check-pass
#![warn(private_interfaces)] //~ WARN unknown lint
//~| WARN unknown lint
//~| WARN unknown lint
#![warn(private_bounds)] //~ WARN unknown lint
//~| WARN unknown lint
//~| WARN unknown lint
#![warn(unnameable_types)] //~ WARN unknown lint
//~| WARN unknown lint
//~| WARN unknown lint

View File

@ -1,57 +1,17 @@
warning: unknown lint: `private_interfaces`
warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_interfaces` lint is unstable
= note: the `unnameable_types` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
= note: `#[warn(unknown_lints)]` on by default
warning: unknown lint: `private_bounds`
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_bounds` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
|
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `unnameable_types` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `private_interfaces`
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_interfaces` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `private_bounds`
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_bounds` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
|
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
@ -59,29 +19,9 @@ LL | #![warn(unnameable_types)]
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `private_interfaces`
warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:3:1
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_interfaces` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `private_bounds`
--> $DIR/feature-gate-type_privacy_lints.rs:6:1
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `private_bounds` lint is unstable
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: unknown lint: `unnameable_types`
--> $DIR/feature-gate-type_privacy_lints.rs:9:1
|
LL | #![warn(unnameable_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
@ -89,5 +29,5 @@ LL | #![warn(unnameable_types)]
= note: see issue #48054 <https://github.com/rust-lang/rust/issues/48054> for more information
= help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable
warning: 9 warnings emitted
warning: 3 warnings emitted

View File

@ -1,9 +1,4 @@
#![feature(type_privacy_lints)]
#![warn(private_bounds)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
// check-pass
use std::any::Any;
use std::any::TypeId;
@ -12,8 +7,7 @@ trait Private<P, R> {
fn call(&self, p: P, r: R);
}
pub trait Public: Private<
//~^ ERROR private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
//~| WARNING trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
//~^ WARNING trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
<Self as Public>::P,
<Self as Public>::R
> {

View File

@ -1,39 +1,19 @@
error[E0445]: private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
--> $DIR/issue-18389.rs:14:1
|
LL | trait Private<P, R> {
| ------------------- `Private<<Self as Public>::P, <Self as Public>::R>` declared as private
...
LL | / pub trait Public: Private<
LL | |
LL | |
LL | | <Self as Public>::P,
LL | | <Self as Public>::R
LL | | > {
| |_^ can't leak private trait
warning: trait `Private<<Self as Public>::P, <Self as Public>::R>` is more private than the item `Public`
--> $DIR/issue-18389.rs:14:1
--> $DIR/issue-18389.rs:9:1
|
LL | / pub trait Public: Private<
LL | |
LL | |
LL | | <Self as Public>::P,
LL | | <Self as Public>::R
LL | | > {
| |_^ trait `Public` is reachable at visibility `pub`
|
note: but trait `Private<<Self as Public>::P, <Self as Public>::R>` is only usable at visibility `pub(crate)`
--> $DIR/issue-18389.rs:11:1
--> $DIR/issue-18389.rs:6:1
|
LL | trait Private<P, R> {
| ^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/issue-18389.rs:2:9
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^
= note: `#[warn(private_bounds)]` on by default
error: aborting due to previous error; 1 warning emitted
warning: 1 warning emitted
For more information about this error, try `rustc --explain E0445`.

View File

@ -2,7 +2,7 @@
//! opaque types.
#![feature(type_alias_impl_trait)]
#![allow(private_in_public)]
#![allow(private_interfaces)]
pub type Successors<'a> = impl Iterator<Item = &'a ()>;

View File

@ -1,6 +1,6 @@
#![feature(rustc_private)]
#![allow(private_in_public)]
#![allow(private_interfaces)]
#![deny(improper_ctypes_definitions)]
extern crate libc;

View File

@ -1,6 +1,6 @@
#![feature(rustc_private)]
#![allow(private_in_public)]
#![allow(private_interfaces)]
#![deny(improper_ctypes)]
extern crate libc;

View File

@ -1,5 +1,5 @@
#![feature(decl_macro, associated_type_defaults)]
#![allow(unused, private_in_public)]
#![allow(private_interfaces)]
mod priv_nominal {
pub struct Pub;

View File

@ -1,5 +1,5 @@
#![feature(decl_macro, associated_type_defaults)]
#![allow(unused, private_in_public)]
#![allow(private_interfaces, private_bounds)]
mod priv_trait {
trait PrivTr {

View File

@ -1,5 +1,5 @@
#![feature(decl_macro, associated_type_defaults)]
#![allow(unused, private_in_public)]
#![allow(private_interfaces, private_bounds)]
mod priv_trait {
trait PrivTr {

View File

@ -1,5 +1,5 @@
#![feature(rustc_attrs)]
#![allow(private_in_public)]
#![allow(private_interfaces)]
struct SemiPriv;

View File

@ -3,8 +3,7 @@ struct SemiPriv;
mod m1 {
struct Priv;
impl ::SemiPriv {
pub fn f(_: Priv) {} //~ WARN private type `m1::Priv` in public interface
//~^ WARNING hard error
pub fn f(_: Priv) {} //~ WARN type `m1::Priv` is more private than the item `m1::<impl SemiPriv>::f`
}
impl Priv {

View File

@ -1,15 +1,18 @@
warning: private type `m1::Priv` in public interface (error E0446)
warning: type `m1::Priv` is more private than the item `m1::<impl SemiPriv>::f`
--> $DIR/issue-30079.rs:6:9
|
LL | pub fn f(_: Priv) {}
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^ associated function `m1::<impl SemiPriv>::f` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
= note: `#[warn(private_in_public)]` on by default
note: but type `m1::Priv` is only usable at visibility `pub(self)`
--> $DIR/issue-30079.rs:4:5
|
LL | struct Priv;
| ^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error[E0446]: private type `m2::Priv` in public interface
--> $DIR/issue-30079.rs:18:9
--> $DIR/issue-30079.rs:17:9
|
LL | struct Priv;
| ----------- `m2::Priv` declared as private
@ -18,7 +21,7 @@ LL | type Target = Priv;
| ^^^^^^^^^^^ can't leak private type
error[E0446]: private type `m3::Priv` in public interface
--> $DIR/issue-30079.rs:35:9
--> $DIR/issue-30079.rs:34:9
|
LL | struct Priv;
| ----------- `m3::Priv` declared as private

View File

@ -22,14 +22,11 @@ mod m {
// applies only to the aliased types, not bounds.
pub trait PubTr {
type Alias1: PrivTr;
//~^ WARN private trait `PrivTr` in public interface
//~| WARN this was previously accepted
//~^ WARN trait `PrivTr` is more private than the item `PubTr::Alias1`
type Alias2: PubTrAux1<Priv> = u8;
//~^ WARN private type `Priv` in public interface
//~| WARN this was previously accepted
//~^ WARN type `Priv` is more private than the item `PubTr::Alias2`
type Alias3: PubTrAux2<A = Priv> = u8;
//~^ WARN private type `Priv` in public interface
//~| WARN this was previously accepted
//~^ WARN type `Priv` is more private than the item `PubTr::Alias3`
type Alias4 = Priv;
//~^ ERROR private type `Priv` in public interface

View File

@ -7,36 +7,45 @@ LL | struct Priv;
LL | type A = Priv;
| ^^^^^^ can't leak private type
warning: private trait `PrivTr` in public interface (error E0445)
warning: trait `PrivTr` is more private than the item `PubTr::Alias1`
--> $DIR/private-in-public-assoc-ty.rs:24:9
|
LL | type Alias1: PrivTr;
| ^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias1` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
= note: `#[warn(private_in_public)]` on by default
note: but trait `PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-assoc-ty.rs:9:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
= note: `#[warn(private_bounds)]` on by default
warning: private type `Priv` in public interface (error E0446)
--> $DIR/private-in-public-assoc-ty.rs:27:9
warning: type `Priv` is more private than the item `PubTr::Alias2`
--> $DIR/private-in-public-assoc-ty.rs:26:9
|
LL | type Alias2: PubTrAux1<Priv> = u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-assoc-ty.rs:8:5
|
LL | struct Priv;
| ^^^^^^^^^^^
warning: private type `Priv` in public interface (error E0446)
--> $DIR/private-in-public-assoc-ty.rs:30:9
warning: type `Priv` is more private than the item `PubTr::Alias3`
--> $DIR/private-in-public-assoc-ty.rs:28:9
|
LL | type Alias3: PubTrAux2<A = Priv> = u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias3` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-assoc-ty.rs:8:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:34:9
--> $DIR/private-in-public-assoc-ty.rs:31:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
@ -45,7 +54,7 @@ LL | type Alias4 = Priv;
| ^^^^^^^^^^^ can't leak private type
error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:41:9
--> $DIR/private-in-public-assoc-ty.rs:38:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
@ -53,8 +62,8 @@ LL | struct Priv;
LL | type Alias1 = Priv;
| ^^^^^^^^^^^ can't leak private type
error[E0445]: private trait `PrivTr` in public interface
--> $DIR/private-in-public-assoc-ty.rs:44:9
error[E0446]: private trait `PrivTr` in public interface
--> $DIR/private-in-public-assoc-ty.rs:41:9
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
@ -64,5 +73,4 @@ LL | type Exist = impl PrivTr;
error: aborting due to 4 previous errors; 3 warnings emitted
Some errors have detailed explanations: E0445, E0446.
For more information about an error, try `rustc --explain E0445`.
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,19 +0,0 @@
mod m1 {
pub struct Pub;
struct Priv;
impl Pub {
pub fn f() -> Priv {Priv} //~ ERROR private type `m1::Priv` in public interface
}
}
mod m2 {
pub struct Pub;
struct Priv;
impl Pub {
pub fn f() -> Priv {Priv} //~ ERROR private type `m2::Priv` in public interface
}
}
fn main() {}

View File

@ -1,21 +0,0 @@
error[E0446]: private type `m1::Priv` in public interface
--> $DIR/private-in-public-lint.rs:6:9
|
LL | struct Priv;
| ----------- `m1::Priv` declared as private
...
LL | pub fn f() -> Priv {Priv}
| ^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `m2::Priv` in public interface
--> $DIR/private-in-public-lint.rs:15:9
|
LL | struct Priv;
| ----------- `m2::Priv` declared as private
...
LL | pub fn f() -> Priv {Priv}
| ^^^^^^^^^^^^^^^^^^ can't leak private type
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,7 +1,7 @@
#![feature(auto_traits)]
#![feature(negative_impls)]
#[allow(private_in_public)]
#[allow(private_interfaces)]
mod m {
pub trait PubPrincipal {}
auto trait PrivNonPrincipal {}

View File

@ -1,19 +1,11 @@
#![feature(auto_traits)]
#![feature(negative_impls)]
#![feature(type_privacy_lints)]
#![deny(private_interfaces)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
pub trait PubPrincipal {}
auto trait PrivNonPrincipal {}
pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} }
//~^ WARN private trait `PrivNonPrincipal` in public interface
//~| WARN this was previously accepted
//~| ERROR trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal`
//~^ WARN trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal`
#[deny(missing_docs)]
fn container() {

View File

@ -1,41 +1,27 @@
warning: private trait `PrivNonPrincipal` in public interface (error E0445)
--> $DIR/private-in-public-non-principal.rs:13:1
|
LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
= note: `#[warn(private_in_public)]` on by default
error: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal`
--> $DIR/private-in-public-non-principal.rs:13:1
warning: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal`
--> $DIR/private-in-public-non-principal.rs:7:1
|
LL | pub fn leak_dyn_nonprincipal() -> Box<dyn PubPrincipal + PrivNonPrincipal> { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `leak_dyn_nonprincipal` is reachable at visibility `pub`
|
note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)`
--> $DIR/private-in-public-non-principal.rs:11:1
--> $DIR/private-in-public-non-principal.rs:5:1
|
LL | auto trait PrivNonPrincipal {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/private-in-public-non-principal.rs:4:9
|
LL | #![deny(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error: missing documentation for an associated function
--> $DIR/private-in-public-non-principal.rs:21:9
--> $DIR/private-in-public-non-principal.rs:13:9
|
LL | pub fn check_doc_lint() {}
| ^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/private-in-public-non-principal.rs:18:8
--> $DIR/private-in-public-non-principal.rs:10:8
|
LL | #[deny(missing_docs)]
| ^^^^^^^^^^^^
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to previous error; 1 warning emitted

View File

@ -1,7 +1,7 @@
// build-pass (FIXME(62277): could be check-pass?)
#![feature(impl_trait_in_assoc_type)]
#![feature(type_alias_impl_trait)]
#![deny(private_in_public)]
#![deny(private_interfaces, private_bounds)]
pub type Pub = impl Default;

View File

@ -2,7 +2,7 @@
// This test also ensures that the checks are performed even inside private modules.
#![feature(associated_type_defaults)]
#![deny(private_in_public)]
#![deny(private_interfaces, private_bounds)]
#![allow(improper_ctypes)]
mod types {
@ -12,30 +12,21 @@ mod types {
type Alias;
}
pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub type Alias = Priv; //~ ERROR type `types::Priv` is more private than the item `types::Alias`
pub enum E {
V1(Priv), //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
V1(Priv), //~ ERROR type `types::Priv` is more private than the item `E::V1::0`
V2 { field: Priv }, //~ ERROR type `types::Priv` is more private than the item `E::V2::field`
}
pub trait Tr {
const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
const C: Priv = Priv; //~ ERROR type `types::Priv` is more private than the item `Tr::C`
type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
fn f1(arg: Priv) {} //~ ERROR type `types::Priv` is more private than the item `Tr::f1`
fn f2() -> Priv { panic!() } //~ ERROR type `types::Priv` is more private than the item `Tr::f2`
}
extern "C" {
pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface
//~^ WARNING hard error
pub static ES: Priv; //~ ERROR type `types::Priv` is more private than the item `types::ES`
pub fn ef1(arg: Priv); //~ ERROR type `types::Priv` is more private than the item `types::ef1`
pub fn ef2() -> Priv; //~ ERROR type `types::Priv` is more private than the item `types::ef2`
}
impl PubTr for Pub {
type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
@ -47,22 +38,16 @@ mod traits {
pub struct Pub<T>(T);
pub trait PubTr {}
pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
//~| WARNING hard error
//~| WARNING bounds on generic parameters are not enforced in type aliases
pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
pub type Alias<T: PrivTr> = T; //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Alias`
//~^ WARNING bounds on generic parameters are not enforced in type aliases
pub trait Tr1: PrivTr {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr1`
pub trait Tr2<T: PrivTr> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr2`
pub trait Tr3 {
type Alias: PrivTr;
//~^ ERROR private trait `traits::PrivTr` in public interface
//~| WARNING hard error
fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias`
fn f<T: PrivTr>(arg: T) {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
}
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
//~^ WARNING hard error
impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
}
@ -72,20 +57,16 @@ mod traits_where {
pub trait PubTr {}
pub type Alias<T> where T: PrivTr = T;
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
//~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Alias`
//~| WARNING where clauses are not enforced in type aliases
pub trait Tr2<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
//~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2`
pub trait Tr3 {
fn f<T>(arg: T) where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
//~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f`
}
impl<T> Pub<T> where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~| WARNING hard error
//~^ ERROR trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
impl<T> PubTr for Pub<T> where T: PrivTr {} // OK, trait impl predicates
}
@ -96,14 +77,10 @@ mod generics {
pub trait PubTr<T> {}
pub trait Tr1: PrivTr<Pub> {}
//~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
//~| WARNING hard error
pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
//~^ WARNING hard error
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
//~^ WARNING hard error
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
//~^ WARNING hard error
//~^ ERROR trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
pub trait Tr2: PubTr<Priv> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr2`
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr3`
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR type `generics::Priv` is more private than the item `Tr4`
}
mod impls {
@ -200,8 +177,7 @@ mod aliases_pub {
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
impl PrivAlias {
pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
//~^ WARNING hard error
pub fn f(arg: Priv) {} //~ ERROR type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f`
}
impl PrivUseAliasTr for PrivUseAlias {
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
@ -244,13 +220,10 @@ mod aliases_priv {
}
pub trait Tr1: PrivUseAliasTr {}
//~^ ERROR private trait `PrivTr1` in public interface
//~| WARNING hard error
//~^ ERROR trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
//~^ ERROR private trait `PrivTr1<Priv2>` in public interface
//~| WARNING hard error
//~| ERROR private type `Priv2` in public interface
//~| WARNING hard error
//~^ ERROR trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2`
//~| ERROR type `Priv2` is more private than the item `aliases_priv::Tr2`
impl PrivUseAlias {
pub fn f(arg: Priv) {} // OK

View File

@ -1,46 +1,58 @@
error: private type `types::Priv` in public interface (error E0446)
error: type `types::Priv` is more private than the item `types::Alias`
--> $DIR/private-in-public-warn.rs:15:5
|
LL | pub type Alias = Priv;
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^ type alias `types::Alias` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/private-in-public-warn.rs:5:9
|
LL | #![deny(private_in_public)]
| ^^^^^^^^^^^^^^^^^
LL | #![deny(private_interfaces, private_bounds)]
| ^^^^^^^^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:18:12
error: type `types::Priv` is more private than the item `E::V1::0`
--> $DIR/private-in-public-warn.rs:17:12
|
LL | V1(Priv),
| ^^^^
| ^^^^ field `E::V1::0` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:20:14
error: type `types::Priv` is more private than the item `E::V2::field`
--> $DIR/private-in-public-warn.rs:18:14
|
LL | V2 { field: Priv },
| ^^^^^^^^^^^
| ^^^^^^^^^^^ field `E::V2::field` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:24:9
error: type `types::Priv` is more private than the item `Tr::C`
--> $DIR/private-in-public-warn.rs:21:9
|
LL | const C: Priv = Priv;
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^^^ associated constant `Tr::C` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public-warn.rs:26:9
--> $DIR/private-in-public-warn.rs:22:9
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
@ -48,53 +60,68 @@ LL | struct Priv;
LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:27:9
error: type `types::Priv` is more private than the item `Tr::f1`
--> $DIR/private-in-public-warn.rs:23:9
|
LL | fn f1(arg: Priv) {}
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^ associated function `Tr::f1` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:29:9
error: type `types::Priv` is more private than the item `Tr::f2`
--> $DIR/private-in-public-warn.rs:24:9
|
LL | fn f2() -> Priv { panic!() }
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^ associated function `Tr::f2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:33:9
error: type `types::Priv` is more private than the item `types::ES`
--> $DIR/private-in-public-warn.rs:27:9
|
LL | pub static ES: Priv;
| ^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:35:9
error: type `types::Priv` is more private than the item `types::ef1`
--> $DIR/private-in-public-warn.rs:28:9
|
LL | pub fn ef1(arg: Priv);
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: private type `types::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:37:9
error: type `types::Priv` is more private than the item `types::ef2`
--> $DIR/private-in-public-warn.rs:29:9
|
LL | pub fn ef2() -> Priv;
| ^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public-warn.rs:41:9
--> $DIR/private-in-public-warn.rs:32:9
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
@ -102,134 +129,181 @@ LL | struct Priv;
LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type
error: private trait `traits::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:50:5
error: trait `traits::PrivTr` is more private than the item `traits::Alias`
--> $DIR/private-in-public-warn.rs:41:5
|
LL | pub type Alias<T: PrivTr> = T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `traits::Alias` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:37:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/private-in-public-warn.rs:5:29
|
LL | #![deny(private_interfaces, private_bounds)]
| ^^^^^^^^^^^^^^
error: private trait `traits::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:53:5
error: trait `traits::PrivTr` is more private than the item `traits::Tr1`
--> $DIR/private-in-public-warn.rs:43:5
|
LL | pub trait Tr1: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr1` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:37:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:55:5
error: trait `traits::PrivTr` is more private than the item `traits::Tr2`
--> $DIR/private-in-public-warn.rs:44:5
|
LL | pub trait Tr2<T: PrivTr> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:37:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:58:9
error: trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias`
--> $DIR/private-in-public-warn.rs:46:9
|
LL | type Alias: PrivTr;
| ^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^ associated type `traits::Tr3::Alias` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:37:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:61:9
error: trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
--> $DIR/private-in-public-warn.rs:48:9
|
LL | fn f<T: PrivTr>(arg: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Tr3::f` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:37:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:64:5
error: trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
--> $DIR/private-in-public-warn.rs:50:5
|
LL | impl<T: PrivTr> Pub<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:37:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits_where::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:74:5
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias`
--> $DIR/private-in-public-warn.rs:59:5
|
LL | pub type Alias<T> where T: PrivTr = T;
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits_where::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:78:5
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2`
--> $DIR/private-in-public-warn.rs:62:5
|
LL | pub trait Tr2<T> where T: PrivTr {}
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits_where::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:82:9
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f`
--> $DIR/private-in-public-warn.rs:65:9
|
LL | fn f<T>(arg: T) where T: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Tr3::f` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `traits_where::PrivTr` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:86:5
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
--> $DIR/private-in-public-warn.rs:68:5
|
LL | impl<T> Pub<T> where T: PrivTr {}
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: private trait `generics::PrivTr<generics::Pub>` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:98:5
error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
--> $DIR/private-in-public-warn.rs:79:5
|
LL | pub trait Tr1: PrivTr<Pub> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:76:5
|
LL | trait PrivTr<T> {}
| ^^^^^^^^^^^^^^^
error: private type `generics::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:101:5
error: type `generics::Priv` is more private than the item `generics::Tr2`
--> $DIR/private-in-public-warn.rs:81:5
|
LL | pub trait Tr2: PubTr<Priv> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:74:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^
error: private type `generics::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:103:5
error: type `generics::Priv` is more private than the item `generics::Tr3`
--> $DIR/private-in-public-warn.rs:82:5
|
LL | pub trait Tr3: PubTr<[Priv; 1]> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr3` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:74:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^
error: private type `generics::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:105:5
error: type `generics::Priv` is more private than the item `Tr4`
--> $DIR/private-in-public-warn.rs:83:5
|
LL | pub trait Tr4: PubTr<Pub<Priv>> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:74:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^
error[E0446]: private type `impls::Priv` in public interface
--> $DIR/private-in-public-warn.rs:132:9
--> $DIR/private-in-public-warn.rs:109:9
|
LL | struct Priv;
| ----------- `impls::Priv` declared as private
@ -237,17 +311,20 @@ LL | struct Priv;
LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type
error: private type `aliases_pub::Priv` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:203:9
error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f`
--> $DIR/private-in-public-warn.rs:180:9
|
LL | pub fn f(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::<impl Pub2>::f` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:153:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:207:9
--> $DIR/private-in-public-warn.rs:183:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
@ -256,7 +333,7 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:210:9
--> $DIR/private-in-public-warn.rs:186:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
@ -265,7 +342,7 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:213:9
--> $DIR/private-in-public-warn.rs:189:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
@ -274,7 +351,7 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:216:9
--> $DIR/private-in-public-warn.rs:192:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
@ -282,35 +359,44 @@ LL | struct Priv;
LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
error: private trait `PrivTr1` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:246:5
error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
--> $DIR/private-in-public-warn.rs:222:5
|
LL | pub trait Tr1: PrivUseAliasTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `PrivTr1` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:208:5
|
LL | trait PrivTr1<T = u8> {
| ^^^^^^^^^^^^^^^^^^^^^
error: private trait `PrivTr1<Priv2>` in public interface (error E0445)
--> $DIR/private-in-public-warn.rs:249:5
error: trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2`
--> $DIR/private-in-public-warn.rs:224:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but trait `PrivTr1<Priv2>` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:208:5
|
LL | trait PrivTr1<T = u8> {
| ^^^^^^^^^^^^^^^^^^^^^
error: private type `Priv2` in public interface (error E0446)
--> $DIR/private-in-public-warn.rs:249:5
error: type `Priv2` is more private than the item `aliases_priv::Tr2`
--> $DIR/private-in-public-warn.rs:224:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
note: but type `Priv2` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:206:5
|
LL | struct Priv2;
| ^^^^^^^^^^^^
warning: bounds on generic parameters are not enforced in type aliases
--> $DIR/private-in-public-warn.rs:50:23
--> $DIR/private-in-public-warn.rs:41:23
|
LL | pub type Alias<T: PrivTr> = T;
| ^^^^^^
@ -323,7 +409,7 @@ LL + pub type Alias<T> = T;
|
warning: where clauses are not enforced in type aliases
--> $DIR/private-in-public-warn.rs:74:29
--> $DIR/private-in-public-warn.rs:59:29
|
LL | pub type Alias<T> where T: PrivTr = T;
| ^^^^^^^^^

View File

@ -1,3 +1,5 @@
// check-pass
// Private types and traits are not allowed in public interfaces.
// This test also ensures that the checks are performed even inside private modules.
@ -10,16 +12,16 @@ mod types {
type Alias;
}
pub const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
pub static S: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
pub fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
pub struct S1(pub Priv); //~ ERROR private type `types::Priv` in public interface
pub struct S2 { pub field: Priv } //~ ERROR private type `types::Priv` in public interface
pub const C: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `C`
pub static S: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `S`
pub fn f1(arg: Priv) {} //~ WARNING `types::Priv` is more private than the item `types::f1`
pub fn f2() -> Priv { panic!() } //~ WARNING type `types::Priv` is more private than the item `types::f2`
pub struct S1(pub Priv); //~ WARNING type `types::Priv` is more private than the item `types::S1::0`
pub struct S2 { pub field: Priv } //~ WARNING `types::Priv` is more private than the item `S2::field`
impl Pub {
pub const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
pub fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
pub fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
pub const C: Priv = Priv; //~ WARNING type `types::Priv` is more private than the item `types::Pub::C`
pub fn f1(arg: Priv) {} //~ WARNING type `types::Priv` is more private than the item `types::Pub::f1`
pub fn f2() -> Priv { panic!() } //~ WARNING type `types::Priv` is more private than the item `types::Pub::f2`
}
}
@ -28,11 +30,11 @@ mod traits {
pub struct Pub<T>(T);
pub trait PubTr {}
pub enum E<T: PrivTr> { V(T) } //~ ERROR private trait `traits::PrivTr` in public interface
pub fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
pub struct S1<T: PrivTr>(T); //~ ERROR private trait `traits::PrivTr` in public interface
impl<T: PrivTr> Pub<T> { //~ ERROR private trait `traits::PrivTr` in public interface
pub fn f<U: PrivTr>(arg: U) {} //~ ERROR private trait `traits::PrivTr` in public interface
pub enum E<T: PrivTr> { V(T) } //~ WARNING trait `traits::PrivTr` is more private than the item `traits::E`
pub fn f<T: PrivTr>(arg: T) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::f`
pub struct S1<T: PrivTr>(T); //~ WARNING trait `traits::PrivTr` is more private than the item `traits::S1`
impl<T: PrivTr> Pub<T> { //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
pub fn f<U: PrivTr>(arg: U) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub::<T>::f`
}
}
@ -42,15 +44,15 @@ mod traits_where {
pub trait PubTr {}
pub enum E<T> where T: PrivTr { V(T) }
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::E`
pub fn f<T>(arg: T) where T: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::f`
pub struct S1<T>(T) where T: PrivTr;
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::S1`
impl<T> Pub<T> where T: PrivTr {
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
pub fn f<U>(arg: U) where U: PrivTr {}
//~^ ERROR private trait `traits_where::PrivTr` in public interface
//~^ WARNING trait `traits_where::PrivTr` is more private than the item `traits_where::Pub::<T>::f`
}
}
@ -60,10 +62,10 @@ mod generics {
trait PrivTr<T> {}
pub trait PubTr<T> {}
pub fn f1(arg: [Priv; 1]) {} //~ ERROR private type `generics::Priv` in public interface
pub fn f2(arg: Pub<Priv>) {} //~ ERROR private type `generics::Priv` in public interface
pub fn f1(arg: [Priv; 1]) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f1`
pub fn f2(arg: Pub<Priv>) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f2`
pub fn f3(arg: Priv<Pub>) {}
//~^ ERROR private type `generics::Priv<generics::Pub>` in public interface
//~^ WARNING type `generics::Priv<generics::Pub>` is more private than the item `generics::f3`
}
mod impls {
@ -77,7 +79,7 @@ mod impls {
}
impl Pub {
pub fn f(arg: Priv) {} //~ ERROR private type `impls::Priv` in public interface
pub fn f(arg: Priv) {} //~ WARNING type `impls::Priv` is more private than the item `impls::Pub::f`
}
}
@ -102,11 +104,11 @@ mod aliases_pub {
// This should be OK, but associated type aliases are not substituted yet
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
//~^ ERROR private trait `aliases_pub::PrivTr` in public interface
//~| ERROR private type `aliases_pub::Priv` in public interface
//~^ WARNING trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3`
//~| WARNING type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
impl PrivUseAlias {
pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
pub fn f(arg: Priv) {}
}
}
@ -128,11 +130,11 @@ mod aliases_priv {
}
impl PrivTr for Priv {}
pub fn f1(arg: PrivUseAlias) {} //~ ERROR private type `Priv1` in public interface
pub fn f2(arg: PrivAlias) {} //~ ERROR private type `Priv2` in public interface
pub fn f1(arg: PrivUseAlias) {} //~ WARNING type `Priv1` is more private than the item `aliases_priv::f1`
pub fn f2(arg: PrivAlias) {} //~ WARNING type `Priv2` is more private than the item `aliases_priv::f2`
pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
//~^ ERROR private trait `aliases_priv::PrivTr` in public interface
//~| ERROR private type `aliases_priv::Priv` in public interface
//~^ WARNING trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3`
//~| WARNING type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
}
mod aliases_params {
@ -141,8 +143,8 @@ mod aliases_params {
type Result<T> = ::std::result::Result<T, Priv>;
pub fn f2(arg: PrivAliasGeneric) {}
//~^ ERROR private type `aliases_params::Priv` in public interface
pub fn f3(arg: Result<u8>) {} //~ ERROR private type `aliases_params::Priv` in public interface
//~^ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f2`
pub fn f3(arg: Result<u8>) {} //~ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f3`
}
fn main() {}

View File

@ -1,292 +1,376 @@
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public.rs:13:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
LL | pub const C: Priv = Priv;
| ^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public.rs:14:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
LL | pub static S: Priv = Priv;
| ^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `types::Priv` in public interface
warning: type `types::Priv` is more private than the item `C`
--> $DIR/private-in-public.rs:15:5
|
LL | pub const C: Priv = Priv;
| ^^^^^^^^^^^^^^^^^ constant `C` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
LL | pub fn f1(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error[E0446]: private type `types::Priv` in public interface
warning: type `types::Priv` is more private than the item `S`
--> $DIR/private-in-public.rs:16:5
|
LL | pub static S: Priv = Priv;
| ^^^^^^^^^^^^^^^^^^ static `S` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
| ^^^^^^^^^^^
warning: type `types::Priv` is more private than the item `types::f1`
--> $DIR/private-in-public.rs:17:5
|
LL | pub fn f1(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^^ function `types::f1` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
warning: type `types::Priv` is more private than the item `types::f2`
--> $DIR/private-in-public.rs:18:5
|
LL | pub fn f2() -> Priv { panic!() }
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public.rs:17:19
| ^^^^^^^^^^^^^^^^^^^ function `types::f2` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
| ^^^^^^^^^^^
warning: type `types::Priv` is more private than the item `types::S1::0`
--> $DIR/private-in-public.rs:19:19
|
LL | pub struct S1(pub Priv);
| ^^^^^^^^ can't leak private type
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public.rs:18:21
| ^^^^^^^^ field `types::S1::0` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
| ^^^^^^^^^^^
warning: type `types::Priv` is more private than the item `S2::field`
--> $DIR/private-in-public.rs:20:21
|
LL | pub struct S2 { pub field: Priv }
| ^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public.rs:20:9
| ^^^^^^^^^^^^^^^ field `S2::field` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
LL | pub const C: Priv = Priv;
| ^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^
error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public.rs:21:9
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
LL | pub fn f1(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `types::Priv` in public interface
warning: type `types::Priv` is more private than the item `types::Pub::C`
--> $DIR/private-in-public.rs:22:9
|
LL | pub const C: Priv = Priv;
| ^^^^^^^^^^^^^^^^^ associated constant `types::Pub::C` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
...
| ^^^^^^^^^^^
warning: type `types::Priv` is more private than the item `types::Pub::f1`
--> $DIR/private-in-public.rs:23:9
|
LL | pub fn f1(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::f1` is reachable at visibility `pub(crate)`
|
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | struct Priv;
| ^^^^^^^^^^^
warning: type `types::Priv` is more private than the item `types::Pub::f2`
--> $DIR/private-in-public.rs:24:9
|
LL | pub fn f2() -> Priv { panic!() }
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:31:5
| ^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::f2` is reachable at visibility `pub(crate)`
|
LL | trait PrivTr {}
| ------------ `traits::PrivTr` declared as private
...
LL | pub enum E<T: PrivTr> { V(T) }
| ^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:32:5
note: but type `types::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:9:5
|
LL | trait PrivTr {}
| ------------ `traits::PrivTr` declared as private
...
LL | pub fn f<T: PrivTr>(arg: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
LL | struct Priv;
| ^^^^^^^^^^^
error[E0445]: private trait `traits::PrivTr` in public interface
warning: trait `traits::PrivTr` is more private than the item `traits::E`
--> $DIR/private-in-public.rs:33:5
|
LL | pub enum E<T: PrivTr> { V(T) }
| ^^^^^^^^^^^^^^^^^^^^^ enum `traits::E` is reachable at visibility `pub(crate)`
|
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:29:5
|
LL | trait PrivTr {}
| ------------ `traits::PrivTr` declared as private
...
LL | pub struct S1<T: PrivTr>(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
| ^^^^^^^^^^^^
= note: `#[warn(private_bounds)]` on by default
error[E0445]: private trait `traits::PrivTr` in public interface
warning: trait `traits::PrivTr` is more private than the item `traits::f`
--> $DIR/private-in-public.rs:34:5
|
LL | pub fn f<T: PrivTr>(arg: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `traits::f` is reachable at visibility `pub(crate)`
|
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:29:5
|
LL | trait PrivTr {}
| ------------ `traits::PrivTr` declared as private
...
| ^^^^^^^^^^^^
warning: trait `traits::PrivTr` is more private than the item `traits::S1`
--> $DIR/private-in-public.rs:35:5
|
LL | pub struct S1<T: PrivTr>(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^ struct `traits::S1` is reachable at visibility `pub(crate)`
|
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:29:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
warning: trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
--> $DIR/private-in-public.rs:36:5
|
LL | impl<T: PrivTr> Pub<T> {
| ^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
error[E0445]: private trait `traits::PrivTr` in public interface
--> $DIR/private-in-public.rs:35:9
| ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)`
|
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:29:5
|
LL | trait PrivTr {}
| ------------ `traits::PrivTr` declared as private
...
| ^^^^^^^^^^^^
warning: trait `traits::PrivTr` is more private than the item `traits::Pub::<T>::f`
--> $DIR/private-in-public.rs:37:9
|
LL | pub fn f<U: PrivTr>(arg: U) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:44:5
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Pub::<T>::f` is reachable at visibility `pub(crate)`
|
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:29:5
|
LL | trait PrivTr {}
| ------------ `traits_where::PrivTr` declared as private
...
LL | pub enum E<T> where T: PrivTr { V(T) }
| ^^^^^^^^^^^^^ can't leak private trait
| ^^^^^^^^^^^^
error[E0445]: private trait `traits_where::PrivTr` in public interface
warning: trait `traits_where::PrivTr` is more private than the item `traits_where::E`
--> $DIR/private-in-public.rs:46:5
|
LL | pub enum E<T> where T: PrivTr { V(T) }
| ^^^^^^^^^^^^^ enum `traits_where::E` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:42:5
|
LL | trait PrivTr {}
| ------------ `traits_where::PrivTr` declared as private
...
LL | pub fn f<T>(arg: T) where T: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
| ^^^^^^^^^^^^
error[E0445]: private trait `traits_where::PrivTr` in public interface
warning: trait `traits_where::PrivTr` is more private than the item `traits_where::f`
--> $DIR/private-in-public.rs:48:5
|
LL | pub fn f<T>(arg: T) where T: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `traits_where::f` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:42:5
|
LL | trait PrivTr {}
| ------------ `traits_where::PrivTr` declared as private
...
LL | pub struct S1<T>(T) where T: PrivTr;
| ^^^^^^^^^^^^^^^^ can't leak private trait
| ^^^^^^^^^^^^
error[E0445]: private trait `traits_where::PrivTr` in public interface
warning: trait `traits_where::PrivTr` is more private than the item `traits_where::S1`
--> $DIR/private-in-public.rs:50:5
|
LL | pub struct S1<T>(T) where T: PrivTr;
| ^^^^^^^^^^^^^^^^ struct `traits_where::S1` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:42:5
|
LL | trait PrivTr {}
| ------------ `traits_where::PrivTr` declared as private
...
| ^^^^^^^^^^^^
warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
--> $DIR/private-in-public.rs:52:5
|
LL | impl<T> Pub<T> where T: PrivTr {
| ^^^^^^^^^^^^^^ can't leak private trait
error[E0445]: private trait `traits_where::PrivTr` in public interface
--> $DIR/private-in-public.rs:52:9
| ^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:42:5
|
LL | trait PrivTr {}
| ------------ `traits_where::PrivTr` declared as private
...
| ^^^^^^^^^^^^
warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub::<T>::f`
--> $DIR/private-in-public.rs:54:9
|
LL | pub fn f<U>(arg: U) where U: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
error[E0446]: private type `generics::Priv` in public interface
--> $DIR/private-in-public.rs:63:5
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Pub::<T>::f` is reachable at visibility `pub(crate)`
|
LL | struct Priv<T = u8>(T);
| ------------------- `generics::Priv` declared as private
...
LL | pub fn f1(arg: [Priv; 1]) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `generics::Priv` in public interface
--> $DIR/private-in-public.rs:64:5
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:42:5
|
LL | struct Priv<T = u8>(T);
| ------------------- `generics::Priv` declared as private
...
LL | pub fn f2(arg: Pub<Priv>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error[E0446]: private type `generics::Priv<generics::Pub>` in public interface
warning: type `generics::Priv` is more private than the item `generics::f1`
--> $DIR/private-in-public.rs:65:5
|
LL | pub fn f1(arg: [Priv; 1]) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f1` is reachable at visibility `pub(crate)`
|
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:60:5
|
LL | struct Priv<T = u8>(T);
| ------------------- `generics::Priv<generics::Pub>` declared as private
...
LL | pub fn f3(arg: Priv<Pub>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^^^^^^^^
error[E0446]: private type `impls::Priv` in public interface
--> $DIR/private-in-public.rs:80:9
warning: type `generics::Priv` is more private than the item `generics::f2`
--> $DIR/private-in-public.rs:66:5
|
LL | pub fn f2(arg: Pub<Priv>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f2` is reachable at visibility `pub(crate)`
|
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:60:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^
warning: type `generics::Priv<generics::Pub>` is more private than the item `generics::f3`
--> $DIR/private-in-public.rs:67:5
|
LL | pub fn f3(arg: Priv<Pub>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f3` is reachable at visibility `pub(crate)`
|
note: but type `generics::Priv<generics::Pub>` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:60:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^
warning: type `impls::Priv` is more private than the item `impls::Pub::f`
--> $DIR/private-in-public.rs:82:9
|
LL | pub fn f(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^ associated function `impls::Pub::f` is reachable at visibility `pub(crate)`
|
note: but type `impls::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:72:5
|
LL | struct Priv;
| ----------- `impls::Priv` declared as private
...
LL | pub fn f(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^
error[E0445]: private trait `aliases_pub::PrivTr` in public interface
--> $DIR/private-in-public.rs:104:5
warning: trait `aliases_pub::PrivTr` is more private than the item `aliases_pub::f3`
--> $DIR/private-in-public.rs:106:5
|
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)`
|
note: but trait `aliases_pub::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:100:5
|
LL | trait PrivTr {
| ------------ `aliases_pub::PrivTr` declared as private
...
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
| ^^^^^^^^^^^^
error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public.rs:104:5
warning: type `aliases_pub::Priv` is more private than the item `aliases_pub::f3`
--> $DIR/private-in-public.rs:106:5
|
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_pub::f3` is reachable at visibility `pub(crate)`
|
note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:87:5
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
...
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^
error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public.rs:109:9
warning: type `Priv1` is more private than the item `aliases_priv::f1`
--> $DIR/private-in-public.rs:133:5
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
...
LL | pub fn f(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `Priv1` in public interface
--> $DIR/private-in-public.rs:131:5
LL | pub fn f1(arg: PrivUseAlias) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f1` is reachable at visibility `pub(crate)`
|
note: but type `Priv1` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:118:5
|
LL | struct Priv1;
| ------------ `Priv1` declared as private
...
LL | pub fn f1(arg: PrivUseAlias) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^
error[E0446]: private type `Priv2` in public interface
--> $DIR/private-in-public.rs:132:5
warning: type `Priv2` is more private than the item `aliases_priv::f2`
--> $DIR/private-in-public.rs:134:5
|
LL | pub fn f2(arg: PrivAlias) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f2` is reachable at visibility `pub(crate)`
|
note: but type `Priv2` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:119:5
|
LL | struct Priv2;
| ------------ `Priv2` declared as private
...
LL | pub fn f2(arg: PrivAlias) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^
error[E0445]: private trait `aliases_priv::PrivTr` in public interface
--> $DIR/private-in-public.rs:133:5
warning: trait `aliases_priv::PrivTr` is more private than the item `aliases_priv::f3`
--> $DIR/private-in-public.rs:135:5
|
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)`
|
note: but trait `aliases_priv::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:128:5
|
LL | trait PrivTr {
| ------------ `aliases_priv::PrivTr` declared as private
...
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
| ^^^^^^^^^^^^
error[E0446]: private type `aliases_priv::Priv` in public interface
--> $DIR/private-in-public.rs:133:5
warning: type `aliases_priv::Priv` is more private than the item `aliases_priv::f3`
--> $DIR/private-in-public.rs:135:5
|
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_priv::f3` is reachable at visibility `pub(crate)`
|
note: but type `aliases_priv::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:116:5
|
LL | struct Priv;
| ----------- `aliases_priv::Priv` declared as private
...
LL | pub fn f3(arg: <Priv as PrivTr>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^
error[E0446]: private type `aliases_params::Priv` in public interface
--> $DIR/private-in-public.rs:143:5
|
LL | struct Priv;
| ----------- `aliases_params::Priv` declared as private
...
LL | pub fn f2(arg: PrivAliasGeneric) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `aliases_params::Priv` in public interface
warning: type `aliases_params::Priv` is more private than the item `aliases_params::f2`
--> $DIR/private-in-public.rs:145:5
|
LL | pub fn f2(arg: PrivAliasGeneric) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_params::f2` is reachable at visibility `pub(crate)`
|
note: but type `aliases_params::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:141:5
|
LL | struct Priv;
| ----------- `aliases_params::Priv` declared as private
...
| ^^^^^^^^^^^
warning: type `aliases_params::Priv` is more private than the item `aliases_params::f3`
--> $DIR/private-in-public.rs:147:5
|
LL | pub fn f3(arg: Result<u8>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ function `aliases_params::f3` is reachable at visibility `pub(crate)`
|
note: but type `aliases_params::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public.rs:141:5
|
LL | struct Priv;
| ^^^^^^^^^^^
error: aborting due to 32 previous errors
warning: 31 warnings emitted
Some errors have detailed explanations: E0445, E0446.
For more information about an error, try `rustc --explain E0445`.

View File

@ -1,4 +1,5 @@
// aux-build:private-inferred-type.rs
#![allow(private_interfaces)]
extern crate private_inferred_type as ext;

View File

@ -1,17 +1,17 @@
error: type `Priv` is private
--> $DIR/private-inferred-type-2.rs:16:5
--> $DIR/private-inferred-type-2.rs:17:5
|
LL | m::Pub::get_priv;
| ^^^^^^^^^^^^^^^^ private type
error: type `Priv` is private
--> $DIR/private-inferred-type-2.rs:17:5
--> $DIR/private-inferred-type-2.rs:18:5
|
LL | m::Pub::static_method;
| ^^^^^^^^^^^^^^^^^^^^^ private type
error: type `ext::Priv` is private
--> $DIR/private-inferred-type-2.rs:18:5
--> $DIR/private-inferred-type-2.rs:19:5
|
LL | ext::Pub::static_method;
| ^^^^^^^^^^^^^^^^^^^^^^^ private type

View File

@ -1,5 +1,5 @@
#![feature(decl_macro)]
#![allow(private_in_public)]
#![allow(private_interfaces)]
mod m {
fn priv_fn() {}

View File

@ -1,6 +1,7 @@
// aux-build:private-inferred-type.rs
#![allow(warnings)]
#![allow(private_interfaces)]
extern crate private_inferred_type as ext;

View File

@ -1,53 +1,53 @@
error: type `Priv` is private
--> $DIR/private-type-in-interface.rs:15:9
--> $DIR/private-type-in-interface.rs:16:9
|
LL | fn f(_: m::Alias) {}
| ^^^^^^^^ private type
error: type `Priv` is private
--> $DIR/private-type-in-interface.rs:15:6
--> $DIR/private-type-in-interface.rs:16:6
|
LL | fn f(_: m::Alias) {}
| ^ private type
error: type `ext::Priv` is private
--> $DIR/private-type-in-interface.rs:17:13
--> $DIR/private-type-in-interface.rs:18:13
|
LL | fn f_ext(_: ext::Alias) {}
| ^^^^^^^^^^ private type
error: type `ext::Priv` is private
--> $DIR/private-type-in-interface.rs:17:10
--> $DIR/private-type-in-interface.rs:18:10
|
LL | fn f_ext(_: ext::Alias) {}
| ^ private type
error: type `Priv` is private
--> $DIR/private-type-in-interface.rs:21:6
--> $DIR/private-type-in-interface.rs:22:6
|
LL | impl m::Alias {}
| ^^^^^^^^ private type
error: type `ext::Priv` is private
--> $DIR/private-type-in-interface.rs:22:14
--> $DIR/private-type-in-interface.rs:23:14
|
LL | impl Tr1 for ext::Alias {}
| ^^^^^^^^^^ private type
error: type `Priv` is private
--> $DIR/private-type-in-interface.rs:23:10
--> $DIR/private-type-in-interface.rs:24:10
|
LL | type A = <m::Alias as m::Trait>::X;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ private type
error: type `Priv` is private
--> $DIR/private-type-in-interface.rs:27:11
--> $DIR/private-type-in-interface.rs:28:11
|
LL | fn g() -> impl Tr2<m::Alias> { 0 }
| ^^^^^^^^^^^^^^^^^^ private type
error: type `ext::Priv` is private
--> $DIR/private-type-in-interface.rs:28:15
--> $DIR/private-type-in-interface.rs:29:15
|
LL | fn g_ext() -> impl Tr2<ext::Alias> { 0 }
| ^^^^^^^^^^^^^^^^^^^^ private type

View File

@ -1,10 +1,11 @@
// check-pass
mod foo {
struct Priv;
mod bar {
use foo::Priv;
pub(super) fn f(_: Priv) {}
pub(crate) fn g(_: Priv) {} //~ ERROR E0446
pub(crate) fn h(_: Priv) {} //~ ERROR E0446
pub(crate) fn g(_: Priv) {}
pub(crate) fn h(_: Priv) {}
}
}

View File

@ -1,21 +0,0 @@
error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public.rs:6:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
...
LL | pub(crate) fn g(_: Priv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public.rs:7:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
...
LL | pub(crate) fn h(_: Priv) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,5 +1,4 @@
#![feature(type_privacy_lints)]
#![allow(private_in_public)]
#![deny(unnameable_types)]
mod m {

View File

@ -1,23 +1,23 @@
error: struct `PubStruct` is reachable but cannot be named
--> $DIR/unnameable_types.rs:6:5
--> $DIR/unnameable_types.rs:5:5
|
LL | pub struct PubStruct(pub i32);
| ^^^^^^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
|
note: the lint level is defined here
--> $DIR/unnameable_types.rs:3:9
--> $DIR/unnameable_types.rs:2:9
|
LL | #![deny(unnameable_types)]
| ^^^^^^^^^^^^^^^^
error: enum `PubE` is reachable but cannot be named
--> $DIR/unnameable_types.rs:8:5
--> $DIR/unnameable_types.rs:7:5
|
LL | pub enum PubE {
| ^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`
error: trait `PubTr` is reachable but cannot be named
--> $DIR/unnameable_types.rs:12:5
--> $DIR/unnameable_types.rs:11:5
|
LL | pub trait PubTr {
| ^^^^^^^^^^^^^^^ reachable at visibility `pub`, but can only be named at visibility `pub(crate)`

View File

@ -3,14 +3,7 @@
#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]
#![warn(private_bounds)]
#![warn(private_interfaces)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
struct PrivTy;
trait PrivTr {}
@ -23,42 +16,33 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; }
pub struct S
//~^ WARNING private type `PrivTy` in public interface
//~| WARNING hard error
//~| WARNING type `PrivTy` is more private than the item `S`
//~^ WARNING type `PrivTy` is more private than the item `S`
where
PrivTy:
{}
pub enum E
//~^ WARNING private type `PrivTy` in public interface
//~| WARNING hard error
//~| WARNING type `PrivTy` is more private than the item `E`
//~^ WARNING type `PrivTy` is more private than the item `E`
where
PrivTy:
{}
pub fn f()
//~^ WARNING private type `PrivTy` in public interface
//~| WARNING hard error
//~| WARNING type `PrivTy` is more private than the item `f`
//~^ WARNING type `PrivTy` is more private than the item `f`
where
PrivTy:
{}
impl S
//~^ ERROR private type `PrivTy` in public interface
//~| WARNING type `PrivTy` is more private than the item `S`
//~^ WARNING type `PrivTy` is more private than the item `S`
where
PrivTy:
{
pub fn f()
//~^ WARNING private type `PrivTy` in public interface
//~| WARNING hard error
//~| WARNING type `PrivTy` is more private than the item `S::f`
//~^ WARNING type `PrivTy` is more private than the item `S::f`
where
PrivTy:
{}
@ -90,7 +74,6 @@ where
{
type AssocTy = Const<{ my_const_fn(U) }>;
//~^ ERROR private type
//~| WARNING type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
fn assoc_fn() -> Self::AssocTy {
Const
}

View File

@ -1,136 +1,72 @@
warning: private type `PrivTy` in public interface (error E0446)
--> $DIR/where-priv-type.rs:25:1
|
LL | pub struct S
| ^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
= note: `#[warn(private_in_public)]` on by default
warning: type `PrivTy` is more private than the item `S`
--> $DIR/where-priv-type.rs:25:1
--> $DIR/where-priv-type.rs:18:1
|
LL | pub struct S
| ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/where-priv-type.rs:15:1
--> $DIR/where-priv-type.rs:8:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/where-priv-type.rs:8:9
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^
warning: private type `PrivTy` in public interface (error E0446)
--> $DIR/where-priv-type.rs:34:1
|
LL | pub enum E
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
= note: `#[warn(private_bounds)]` on by default
warning: type `PrivTy` is more private than the item `E`
--> $DIR/where-priv-type.rs:34:1
--> $DIR/where-priv-type.rs:25:1
|
LL | pub enum E
| ^^^^^^^^^^ enum `E` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/where-priv-type.rs:15:1
--> $DIR/where-priv-type.rs:8:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
warning: private type `PrivTy` in public interface (error E0446)
--> $DIR/where-priv-type.rs:43:1
|
LL | / pub fn f()
LL | |
LL | |
LL | |
LL | | where
LL | | PrivTy:
| |___________^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
warning: type `PrivTy` is more private than the item `f`
--> $DIR/where-priv-type.rs:43:1
--> $DIR/where-priv-type.rs:32:1
|
LL | / pub fn f()
LL | |
LL | |
LL | |
LL | | where
LL | | PrivTy:
| |___________^ function `f` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/where-priv-type.rs:15:1
--> $DIR/where-priv-type.rs:8:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
error[E0446]: private type `PrivTy` in public interface
--> $DIR/where-priv-type.rs:52:1
|
LL | struct PrivTy;
| ------------- `PrivTy` declared as private
...
LL | impl S
| ^^^^^^ can't leak private type
warning: type `PrivTy` is more private than the item `S`
--> $DIR/where-priv-type.rs:52:1
--> $DIR/where-priv-type.rs:39:1
|
LL | impl S
| ^^^^^^ implementation `S` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/where-priv-type.rs:15:1
--> $DIR/where-priv-type.rs:8:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
warning: private type `PrivTy` in public interface (error E0446)
--> $DIR/where-priv-type.rs:58:5
|
LL | / pub fn f()
LL | |
LL | |
LL | |
LL | | where
LL | | PrivTy:
| |_______________^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
warning: type `PrivTy` is more private than the item `S::f`
--> $DIR/where-priv-type.rs:58:5
--> $DIR/where-priv-type.rs:44:5
|
LL | / pub fn f()
LL | |
LL | |
LL | |
LL | | where
LL | | PrivTy:
| |_______________^ associated function `S::f` is reachable at visibility `pub`
|
note: but type `PrivTy` is only usable at visibility `pub(crate)`
--> $DIR/where-priv-type.rs:15:1
--> $DIR/where-priv-type.rs:8:1
|
LL | struct PrivTy;
| ^^^^^^^^^^^^^
error[E0446]: private type `fn(u8) -> u8 {my_const_fn}` in public interface
--> $DIR/where-priv-type.rs:91:5
--> $DIR/where-priv-type.rs:75:5
|
LL | type AssocTy = Const<{ my_const_fn(U) }>;
| ^^^^^^^^^^^^ can't leak private type
@ -138,23 +74,6 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>;
LL | const fn my_const_fn(val: u8) -> u8 {
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
--> $DIR/where-priv-type.rs:91:5
|
LL | type AssocTy = Const<{ my_const_fn(U) }>;
| ^^^^^^^^^^^^ associated type `<Const<U> as Trait>::AssocTy` is reachable at visibility `pub`
|
note: but type `fn(u8) -> u8 {my_const_fn}` is only usable at visibility `pub(crate)`
--> $DIR/where-priv-type.rs:99:1
|
LL | const fn my_const_fn(val: u8) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/where-priv-type.rs:9:9
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors; 10 warnings emitted
error: aborting due to previous error; 5 warnings emitted
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,14 +1,10 @@
// check-pass
// priv-in-pub lint tests where the private trait bounds a public type
#![crate_type = "lib"]
#![feature(generic_const_exprs)]
#![feature(type_privacy_lints)]
#![allow(incomplete_features)]
#![warn(private_bounds)]
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
struct PrivTy;
trait PrivTr {}
@ -22,38 +18,33 @@ impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; }
pub struct S
//~^ ERROR private trait `PrivTr` in public interface
//~| WARNING trait `PrivTr` is more private than the item `S`
//~^ WARNING trait `PrivTr` is more private than the item `S`
where
PubTy: PrivTr
{}
pub enum E
//~^ ERROR private trait `PrivTr` in public interface
//~| WARNING trait `PrivTr` is more private than the item `E`
//~^ WARNING trait `PrivTr` is more private than the item `E`
where
PubTy: PrivTr
{}
pub fn f()
//~^ ERROR private trait `PrivTr` in public interface
//~| WARNING trait `PrivTr` is more private than the item `f`
//~^ WARNING trait `PrivTr` is more private than the item `f`
where
PubTy: PrivTr
{}
impl S
//~^ ERROR private trait `PrivTr` in public interface
//~| WARNING trait `PrivTr` is more private than the item `S`
//~^ WARNING trait `PrivTr` is more private than the item `S`
where
PubTy: PrivTr
{
pub fn f()
//~^ ERROR private trait `PrivTr` in public interface
//~| WARNING trait `PrivTr` is more private than the item `S::f`
//~^ WARNING trait `PrivTr` is more private than the item `S::f`
where
PubTy: PrivTr
{}

View File

@ -1,129 +1,69 @@
error[E0445]: private trait `PrivTr` in public interface
--> $DIR/where-pub-type-impls-priv-trait.rs:24:1
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
...
LL | pub struct S
| ^^^^^^^^^^^^ can't leak private trait
warning: trait `PrivTr` is more private than the item `S`
--> $DIR/where-pub-type-impls-priv-trait.rs:24:1
--> $DIR/where-pub-type-impls-priv-trait.rs:20:1
|
LL | pub struct S
| ^^^^^^^^^^^^ struct `S` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:14:1
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/where-pub-type-impls-priv-trait.rs:7:9
|
LL | #![warn(private_bounds)]
| ^^^^^^^^^^^^^^
error[E0445]: private trait `PrivTr` in public interface
--> $DIR/where-pub-type-impls-priv-trait.rs:32:1
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
...
LL | pub enum E
| ^^^^^^^^^^ can't leak private trait
= note: `#[warn(private_bounds)]` on by default
warning: trait `PrivTr` is more private than the item `E`
--> $DIR/where-pub-type-impls-priv-trait.rs:32:1
--> $DIR/where-pub-type-impls-priv-trait.rs:27:1
|
LL | pub enum E
| ^^^^^^^^^^ enum `E` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:14:1
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error[E0445]: private trait `PrivTr` in public interface
--> $DIR/where-pub-type-impls-priv-trait.rs:40:1
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
...
LL | / pub fn f()
LL | |
LL | |
LL | | where
LL | | PubTy: PrivTr
| |_________________^ can't leak private trait
warning: trait `PrivTr` is more private than the item `f`
--> $DIR/where-pub-type-impls-priv-trait.rs:40:1
--> $DIR/where-pub-type-impls-priv-trait.rs:34:1
|
LL | / pub fn f()
LL | |
LL | |
LL | | where
LL | | PubTy: PrivTr
| |_________________^ function `f` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:14:1
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error[E0445]: private trait `PrivTr` in public interface
--> $DIR/where-pub-type-impls-priv-trait.rs:48:1
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
...
LL | impl S
| ^^^^^^ can't leak private trait
warning: trait `PrivTr` is more private than the item `S`
--> $DIR/where-pub-type-impls-priv-trait.rs:48:1
--> $DIR/where-pub-type-impls-priv-trait.rs:41:1
|
LL | impl S
| ^^^^^^ implementation `S` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:14:1
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error[E0445]: private trait `PrivTr` in public interface
--> $DIR/where-pub-type-impls-priv-trait.rs:54:5
|
LL | trait PrivTr {}
| ------------ `PrivTr` declared as private
...
LL | / pub fn f()
LL | |
LL | |
LL | | where
LL | | PubTy: PrivTr
| |_____________________^ can't leak private trait
warning: trait `PrivTr` is more private than the item `S::f`
--> $DIR/where-pub-type-impls-priv-trait.rs:54:5
--> $DIR/where-pub-type-impls-priv-trait.rs:46:5
|
LL | / pub fn f()
LL | |
LL | |
LL | | where
LL | | PubTy: PrivTr
| |_____________________^ associated function `S::f` is reachable at visibility `pub`
|
note: but trait `PrivTr` is only usable at visibility `pub(crate)`
--> $DIR/where-pub-type-impls-priv-trait.rs:14:1
--> $DIR/where-pub-type-impls-priv-trait.rs:10:1
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^
error: aborting due to 5 previous errors; 5 warnings emitted
warning: 5 warnings emitted
For more information about this error, try `rustc --explain E0445`.

View File

@ -3,7 +3,7 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![allow(private_in_public)]
#![allow(private_interfaces)]
extern crate proc_macro;
use proc_macro::TokenStream;

View File

@ -1,44 +1,24 @@
#![feature(type_privacy_lints)]
#![allow(non_camel_case_types)] // genus is always capitalized
#![warn(private_interfaces)]
//~^ NOTE the lint level is defined here
// check-pass
// In this test both old and new private-in-public diagnostic were emitted.
// Old diagnostic will be deleted soon.
// See https://rust-lang.github.io/rfcs/2145-type-privacy.html.
#![allow(non_camel_case_types)] // genus is always capitalized
pub(crate) struct Snail;
//~^ NOTE `Snail` declared as private
//~| NOTE but type `Snail` is only usable at visibility `pub(crate)`
mod sea {
pub(super) struct Turtle;
//~^ NOTE `Turtle` declared as crate-private
//~| NOTE but type `Turtle` is only usable at visibility `pub(crate)`
}
struct Tortoise;
//~^ NOTE `Tortoise` declared as private
//~| NOTE but type `Tortoise` is only usable at visibility `pub(crate)`
pub struct Shell<T> {
pub(crate) creature: T,
}
pub type Helix_pomatia = Shell<Snail>;
//~^ ERROR private type `Snail` in public interface
//~| WARNING type `Snail` is more private than the item `Helix_pomatia`
//~| NOTE can't leak private type
//~| NOTE type alias `Helix_pomatia` is reachable at visibility `pub`
//~^ WARNING type `Snail` is more private than the item `Helix_pomatia`
pub type Dermochelys_coriacea = Shell<sea::Turtle>;
//~^ ERROR crate-private type `Turtle` in public interface
//~| WARNING type `Turtle` is more private than the item `Dermochelys_coriacea`
//~| NOTE can't leak crate-private type
//~| NOTE type alias `Dermochelys_coriacea` is reachable at visibility `pub`
//~^ WARNING type `Turtle` is more private than the item `Dermochelys_coriacea`
pub type Testudo_graeca = Shell<Tortoise>;
//~^ ERROR private type `Tortoise` in public interface
//~| WARNING type `Tortoise` is more private than the item `Testudo_graeca`
//~| NOTE can't leak private type
//~| NOTE type alias `Testudo_graeca` is reachable at visibility `pub`
//~^ WARNING type `Tortoise` is more private than the item `Testudo_graeca`
fn main() {}

View File

@ -1,71 +1,39 @@
error[E0446]: private type `Snail` in public interface
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1
|
LL | pub(crate) struct Snail;
| ----------------------- `Snail` declared as private
...
LL | pub type Helix_pomatia = Shell<Snail>;
| ^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
warning: type `Snail` is more private than the item `Helix_pomatia`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:28:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:17:1
|
LL | pub type Helix_pomatia = Shell<Snail>;
| ^^^^^^^^^^^^^^^^^^^^^^ type alias `Helix_pomatia` is reachable at visibility `pub`
|
note: but type `Snail` is only usable at visibility `pub(crate)`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:10:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:5:1
|
LL | pub(crate) struct Snail;
| ^^^^^^^^^^^^^^^^^^^^^^^
note: the lint level is defined here
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:3:9
|
LL | #![warn(private_interfaces)]
| ^^^^^^^^^^^^^^^^^^
error[E0446]: crate-private type `Turtle` in public interface
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:33:1
|
LL | pub(super) struct Turtle;
| ------------------------ `Turtle` declared as crate-private
...
LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak crate-private type
= note: `#[warn(private_interfaces)]` on by default
warning: type `Turtle` is more private than the item `Dermochelys_coriacea`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:33:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:19:1
|
LL | pub type Dermochelys_coriacea = Shell<sea::Turtle>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `Dermochelys_coriacea` is reachable at visibility `pub`
|
note: but type `Turtle` is only usable at visibility `pub(crate)`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:15:5
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:8:5
|
LL | pub(super) struct Turtle;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0446]: private type `Tortoise` in public interface
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:38:1
|
LL | struct Tortoise;
| --------------- `Tortoise` declared as private
...
LL | pub type Testudo_graeca = Shell<Tortoise>;
| ^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
warning: type `Tortoise` is more private than the item `Testudo_graeca`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:38:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:21:1
|
LL | pub type Testudo_graeca = Shell<Tortoise>;
| ^^^^^^^^^^^^^^^^^^^^^^^ type alias `Testudo_graeca` is reachable at visibility `pub`
|
note: but type `Tortoise` is only usable at visibility `pub(crate)`
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:20:1
--> $DIR/issue-33174-restricted-type-in-public-interface.rs:11:1
|
LL | struct Tortoise;
| ^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors; 3 warnings emitted
warning: 3 warnings emitted
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,6 +1,6 @@
// run-pass
// compile-flags:--test
#![deny(private_in_public)]
#![deny(private_interfaces)]
#[test] fn foo() {}
mod foo {}

View File

@ -1,3 +1,5 @@
// check-pass
//! If visibility is assumed, a transmutation should be accepted even if the
//! destination type contains an unreachable field (e.g., a public field with a
//! private type). (This rule is distinct from type privacy, which still may
@ -29,7 +31,7 @@ mod dst {
#[repr(C)] pub(self) struct Zst; // <- unreachable type
#[repr(C)] pub(in super) struct Dst {
pub(in super) field: Zst, //~ ERROR private type
pub(in super) field: Zst, //~ WARNING type `dst::Zst` is more private than the item `Dst::field`
}
}

View File

@ -1,12 +1,15 @@
error[E0446]: private type `dst::Zst` in public interface
--> $DIR/should_accept_if_dst_has_unreachable_field.rs:32:9
warning: type `dst::Zst` is more private than the item `Dst::field`
--> $DIR/should_accept_if_dst_has_unreachable_field.rs:34:9
|
LL | pub(in super) field: Zst,
| ^^^^^^^^^^^^^^^^^^^^^^^^ field `Dst::field` is reachable at visibility `pub(crate)`
|
note: but type `dst::Zst` is only usable at visibility `pub(self)`
--> $DIR/should_accept_if_dst_has_unreachable_field.rs:31:16
|
LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type
| -------------------- `dst::Zst` declared as private
...
LL | pub(in super) field: Zst,
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error: aborting due to previous error
warning: 1 warning emitted
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,3 +1,5 @@
// check-pass
//! The presence of an unreachable field in the source type (e.g., a public
//! field with a private type does not affect transmutability. (This rule is
//! distinct from type privacy, which still may forbid naming such types.)
@ -19,7 +21,7 @@ mod src {
#[repr(C)] pub(self) struct Zst; // <- unreachable type
#[repr(C)] pub(in super) struct Src {
pub(in super) field: Zst, //~ ERROR private type
pub(in super) field: Zst, //~ WARNING type `src::Zst` is more private than the item `Src::field`
}
}

View File

@ -1,12 +1,15 @@
error[E0446]: private type `src::Zst` in public interface
--> $DIR/should_accept_if_src_has_unreachable_field.rs:22:9
warning: type `src::Zst` is more private than the item `Src::field`
--> $DIR/should_accept_if_src_has_unreachable_field.rs:24:9
|
LL | pub(in super) field: Zst,
| ^^^^^^^^^^^^^^^^^^^^^^^^ field `Src::field` is reachable at visibility `pub(crate)`
|
note: but type `src::Zst` is only usable at visibility `pub(self)`
--> $DIR/should_accept_if_src_has_unreachable_field.rs:21:16
|
LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type
| -------------------- `src::Zst` declared as private
...
LL | pub(in super) field: Zst,
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
| ^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error: aborting due to previous error
warning: 1 warning emitted
For more information about this error, try `rustc --explain E0446`.

View File

@ -1,8 +1,10 @@
// check-pass
#![feature(type_alias_impl_trait)]
type Foo = (impl Sized, u8);
pub fn foo() -> Foo {
//~^ ERROR private type alias `Foo` in public interface
//~^ WARNING type alias `Foo` is more private than the item `foo`
(42, 42)
}
fn main() {}

View File

@ -1,11 +1,15 @@
error[E0446]: private type alias `Foo` in public interface
--> $DIR/privacy.rs:4:1
warning: type alias `Foo` is more private than the item `foo`
--> $DIR/privacy.rs:6:1
|
LL | pub fn foo() -> Foo {
| ^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub`
|
note: but type alias `Foo` is only usable at visibility `pub(crate)`
--> $DIR/privacy.rs:5:1
|
LL | type Foo = (impl Sized, u8);
| -------- `Foo` declared as private
LL | pub fn foo() -> Foo {
| ^^^^^^^^^^^^^^^^^^^ can't leak private type alias
| ^^^^^^^^
= note: `#[warn(private_interfaces)]` on by default
error: aborting due to previous error
warning: 1 warning emitted
For more information about this error, try `rustc --explain E0446`.