From e26614e6a7f8003dfd2a756db070c6d04ca34c6f Mon Sep 17 00:00:00 2001 From: Bryanskiy Date: Mon, 19 Jun 2023 17:06:00 +0300 Subject: [PATCH] Replace old private-in-public diagnostic with type privacy lints --- compiler/rustc_error_codes/src/error_codes.rs | 1 + .../src/error_codes/E0445.md | 8 +- .../src/error_codes/E0446.md | 46 +- compiler/rustc_lint/src/lib.rs | 5 + compiler/rustc_lint_defs/src/builtin.rs | 49 +- compiler/rustc_middle/src/hir/map/mod.rs | 1 - compiler/rustc_middle/src/ty/mod.rs | 2 - compiler/rustc_privacy/messages.ftl | 5 - compiler/rustc_privacy/src/errors.rs | 23 - compiler/rustc_privacy/src/lib.rs | 421 +--------------- .../rustc_resolve/src/build_reduced_graph.rs | 2 - compiler/rustc_resolve/src/lib.rs | 4 - .../private-in-public.rs | 21 +- .../private-in-public.stderr | 52 +- .../generic_const_exprs/eval-privacy.rs | 7 - .../generic_const_exprs/eval-privacy.stderr | 21 +- tests/ui/error-codes/E0445.rs | 23 - tests/ui/error-codes/E0445.stderr | 71 --- tests/ui/error-codes/E0446.rs | 15 +- tests/ui/error-codes/E0446.stderr | 23 +- .../feature-gate-type_privacy_lints.rs | 6 - .../feature-gate-type_privacy_lints.stderr | 70 +-- tests/ui/issues/issue-18389.rs | 10 +- tests/ui/issues/issue-18389.stderr | 28 +- tests/ui/lint/issue-99387.rs | 2 +- tests/ui/lint/lint-ctypes-fn.rs | 2 +- tests/ui/lint/lint-ctypes.rs | 2 +- .../associated-item-privacy-inherent.rs | 2 +- .../privacy/associated-item-privacy-trait.rs | 2 +- .../associated-item-privacy-type-binding.rs | 2 +- .../effective_visibilities_full_priv.rs | 2 +- tests/ui/privacy/issue-30079.rs | 3 +- tests/ui/privacy/issue-30079.stderr | 17 +- .../ui/privacy/private-in-public-assoc-ty.rs | 9 +- .../privacy/private-in-public-assoc-ty.stderr | 50 +- tests/ui/privacy/private-in-public-lint.rs | 19 - .../ui/privacy/private-in-public-lint.stderr | 21 - .../private-in-public-non-principal-2.rs | 2 +- .../private-in-public-non-principal.rs | 10 +- .../private-in-public-non-principal.stderr | 28 +- ...private-in-public-type-alias-impl-trait.rs | 2 +- tests/ui/privacy/private-in-public-warn.rs | 85 ++-- .../ui/privacy/private-in-public-warn.stderr | 376 ++++++++------ tests/ui/privacy/private-in-public.rs | 66 +-- tests/ui/privacy/private-in-public.stderr | 468 +++++++++++------- tests/ui/privacy/private-inferred-type-2.rs | 1 + .../ui/privacy/private-inferred-type-2.stderr | 6 +- tests/ui/privacy/private-inferred-type.rs | 2 +- tests/ui/privacy/private-type-in-interface.rs | 1 + .../privacy/private-type-in-interface.stderr | 18 +- .../privacy/restricted/private-in-public.rs | 5 +- .../restricted/private-in-public.stderr | 21 - tests/ui/privacy/unnameable_types.rs | 1 - tests/ui/privacy/unnameable_types.stderr | 8 +- tests/ui/privacy/where-priv-type.rs | 27 +- tests/ui/privacy/where-priv-type.stderr | 107 +--- .../where-pub-type-impls-priv-trait.rs | 23 +- .../where-pub-type-impls-priv-trait.stderr | 84 +--- tests/ui/proc-macro/allowed-signatures.rs | 2 +- ...174-restricted-type-in-public-interface.rs | 30 +- ...restricted-type-in-public-interface.stderr | 48 +- tests/ui/test-attrs/issue-36768.rs | 2 +- ...uld_accept_if_dst_has_unreachable_field.rs | 4 +- ...accept_if_dst_has_unreachable_field.stderr | 19 +- ...uld_accept_if_src_has_unreachable_field.rs | 4 +- ...accept_if_src_has_unreachable_field.stderr | 19 +- tests/ui/type-alias-impl-trait/privacy.rs | 4 +- tests/ui/type-alias-impl-trait/privacy.stderr | 18 +- 68 files changed, 850 insertions(+), 1688 deletions(-) delete mode 100644 tests/ui/error-codes/E0445.rs delete mode 100644 tests/ui/error-codes/E0445.stderr delete mode 100644 tests/ui/privacy/private-in-public-lint.rs delete mode 100644 tests/ui/privacy/private-in-public-lint.stderr delete mode 100644 tests/ui/privacy/restricted/private-in-public.stderr diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index d104ff0891d34..755e5e26ac67a 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -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 diff --git a/compiler/rustc_error_codes/src/error_codes/E0445.md b/compiler/rustc_error_codes/src/error_codes/E0445.md index e6a28a9c2c460..d47393194c50f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0445.md +++ b/compiler/rustc_error_codes/src/error_codes/E0445.md @@ -1,10 +1,10 @@ -A private trait was used on a public type parameter bound. +#### Note: this error code is no longer emitted by the compiler. -Erroneous code examples: +A private trait was used on a public type parameter bound. -```compile_fail,E0445 -#![deny(private_in_public)] +Previously erroneous code examples: +``` trait Foo { fn dummy(&self) { } } diff --git a/compiler/rustc_error_codes/src/error_codes/E0446.md b/compiler/rustc_error_codes/src/error_codes/E0446.md index 6ec47c4962c06..ebbd83c683caa 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0446.md +++ b/compiler/rustc_error_codes/src/error_codes/E0446.md @@ -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); - -mod foo { - use crate::Bar; - pub fn bar() -> Bar { // error: private type in public interface - Bar(0) - } +struct Bar; + +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; + +pub(crate) trait PubTr { // only public to crate root + type Alias; +} -mod foo { - use crate::Bar; - pub(crate) fn bar() -> Bar { // only public to crate root - Bar(0) - } +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() {} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 53089294fe2e6..6f1cdff2fc265 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -516,6 +516,11 @@ fn register_builtins(store: &mut LintStore) { "converted into hard error, see issue #82523 \ for more information", ); + store.register_removed( + "private_in_public", + "replaced with another group of lints, see RFC \ + for more information", + ); } fn register_internals(store: &mut LintStore) { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 7e3b6e9e218cc..4d0d071d03fae 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -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 ", - }; -} - 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! { diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 0256e09e4b553..26a28fc64056a 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -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() }); diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 2b4c834f766b9..0d63c1f801e89 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -162,8 +162,6 @@ pub struct ResolverOutputs { #[derive(Debug)] pub struct ResolverGlobalCtxt { pub visibilities: FxHashMap, - /// 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, pub effective_visibilities: EffectiveVisibilities, diff --git a/compiler/rustc_privacy/messages.ftl b/compiler/rustc_privacy/messages.ftl index b91e0d18a804f..7785f1a7f81fb 100644 --- a/compiler/rustc_privacy/messages.ftl +++ b/compiler/rustc_privacy/messages.ftl @@ -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}` diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index da18f0c82682e..b1242f82f4fec 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -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> { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 5fa780a372b72..c1db182a31d13 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -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( @@ -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` 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> ...`, - // 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 { ... }`. 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, - 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); diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 2f4327990224d..83ab5d5e68db8 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -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, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index da5e92a075a41..d1dc8e3e71c07 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -980,7 +980,6 @@ pub struct Resolver<'a, 'tcx> { glob_map: FxHashMap>, /// Visibilities in "lowered" form, for all entities that have them. visibilities: FxHashMap, - has_pub_restricted: bool, used_imports: FxHashSet, maybe_unused_trait_imports: FxIndexSet, @@ -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, diff --git a/tests/ui/associated-inherent-types/private-in-public.rs b/tests/ui/associated-inherent-types/private-in-public.rs index e9e189f95c906..7797a2a16a58c 100644 --- a/tests/ui/associated-inherent-types/private-in-public.rs +++ b/tests/ui/associated-inherent-types/private-in-public.rs @@ -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; -//~^ 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 { diff --git a/tests/ui/associated-inherent-types/private-in-public.stderr b/tests/ui/associated-inherent-types/private-in-public.stderr index 65d187c1bcdfb..076bbd78ae910 100644 --- a/tests/ui/associated-inherent-types/private-in-public.stderr +++ b/tests/ui/associated-inherent-types/private-in-public.stderr @@ -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 -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 + = 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; - | ^^^^^^^^^^^^^^^^^^ - | - = 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 - 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; | ^^^^^^^^^^^^^^^^^^ 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 diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs index e5464a4253f0b..8023b998a4099 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.rs @@ -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; @@ -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 ` as Trait>::AssocTy` fn assoc_fn() -> Self::AssocTy { Const } diff --git a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr index 16fae6b5c637e..2d9de8805bb55 100644 --- a/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr +++ b/tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr @@ -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 ` as Trait>::AssocTy` - --> $DIR/eval-privacy.rs:22:5 - | -LL | type AssocTy = Const<{ my_const_fn(U) }>; - | ^^^^^^^^^^^^ associated type ` 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`. diff --git a/tests/ui/error-codes/E0445.rs b/tests/ui/error-codes/E0445.rs deleted file mode 100644 index 9f29c81673e5b..0000000000000 --- a/tests/ui/error-codes/E0445.rs +++ /dev/null @@ -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(pub T); -//~^ ERROR private trait `Foo` in public interface [E0445] -//~| WARNING trait `Foo` is more private than the item `Bar2` -pub fn foo (t: T) {} -//~^ ERROR private trait `Foo` in public interface [E0445] -//~| WARNING trait `Foo` is more private than the item `foo` - -fn main() {} diff --git a/tests/ui/error-codes/E0445.stderr b/tests/ui/error-codes/E0445.stderr deleted file mode 100644 index 4f940868ff905..0000000000000 --- a/tests/ui/error-codes/E0445.stderr +++ /dev/null @@ -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(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(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: 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: 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`. diff --git a/tests/ui/error-codes/E0446.rs b/tests/ui/error-codes/E0446.rs index f61c7e5461662..6d6c4f97c0657 100644 --- a/tests/ui/error-codes/E0446.rs +++ b/tests/ui/error-codes/E0446.rs @@ -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; //~ ERROR E0446 } fn main() {} diff --git a/tests/ui/error-codes/E0446.stderr b/tests/ui/error-codes/E0446.stderr index b6a195c40a93a..2951e69d1c263 100644 --- a/tests/ui/error-codes/E0446.stderr +++ b/tests/ui/error-codes/E0446.stderr @@ -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; + | ^^^^^^^^^^^ can't leak private trait + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0446`. diff --git a/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs b/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs index aad64c9d07326..8bb9736f1b474 100644 --- a/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs +++ b/tests/ui/feature-gates/feature-gate-type_privacy_lints.rs @@ -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 diff --git a/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr b/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr index 79cc974cca122..4349fea6f8960 100644 --- a/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr +++ b/tests/ui/feature-gates/feature-gate-type_privacy_lints.stderr @@ -1,26 +1,5 @@ -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 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 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 + --> $DIR/feature-gate-type_privacy_lints.rs:3:1 | LL | #![warn(unnameable_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -28,29 +7,10 @@ LL | #![warn(unnameable_types)] = note: the `unnameable_types` lint is unstable = note: see issue #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 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 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: `unnameable_types` - --> $DIR/feature-gate-type_privacy_lints.rs:9:1 + --> $DIR/feature-gate-type_privacy_lints.rs:3:1 | LL | #![warn(unnameable_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -59,28 +19,8 @@ LL | #![warn(unnameable_types)] = note: see issue #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 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 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 + --> $DIR/feature-gate-type_privacy_lints.rs:3:1 | LL | #![warn(unnameable_types)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -89,5 +29,5 @@ LL | #![warn(unnameable_types)] = note: see issue #48054 for more information = help: add `#![feature(type_privacy_lints)]` to the crate attributes to enable -warning: 9 warnings emitted +warning: 3 warnings emitted diff --git a/tests/ui/issues/issue-18389.rs b/tests/ui/issues/issue-18389.rs index 05a5decf4629c..26b607f4081f7 100644 --- a/tests/ui/issues/issue-18389.rs +++ b/tests/ui/issues/issue-18389.rs @@ -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 { fn call(&self, p: P, r: R); } pub trait Public: Private< -//~^ ERROR private trait `Private<::P, ::R>` in public interface -//~| WARNING trait `Private<::P, ::R>` is more private than the item `Public` +//~^ WARNING trait `Private<::P, ::R>` is more private than the item `Public` ::P, ::R > { diff --git a/tests/ui/issues/issue-18389.stderr b/tests/ui/issues/issue-18389.stderr index 18ffc4177d718..4706d1ba1779e 100644 --- a/tests/ui/issues/issue-18389.stderr +++ b/tests/ui/issues/issue-18389.stderr @@ -1,39 +1,19 @@ -error[E0445]: private trait `Private<::P, ::R>` in public interface - --> $DIR/issue-18389.rs:14:1 - | -LL | trait Private { - | ------------------- `Private<::P, ::R>` declared as private -... -LL | / pub trait Public: Private< -LL | | -LL | | -LL | | ::P, -LL | | ::R -LL | | > { - | |_^ can't leak private trait - warning: trait `Private<::P, ::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 | | ::P, LL | | ::R LL | | > { | |_^ trait `Public` is reachable at visibility `pub` | note: but trait `Private<::P, ::R>` is only usable at visibility `pub(crate)` - --> $DIR/issue-18389.rs:11:1 + --> $DIR/issue-18389.rs:6:1 | LL | trait Private { | ^^^^^^^^^^^^^^^^^^^ -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`. diff --git a/tests/ui/lint/issue-99387.rs b/tests/ui/lint/issue-99387.rs index ba5031167e33d..571d4194fe78f 100644 --- a/tests/ui/lint/issue-99387.rs +++ b/tests/ui/lint/issue-99387.rs @@ -2,7 +2,7 @@ //! opaque types. #![feature(type_alias_impl_trait)] -#![allow(private_in_public)] +#![allow(private_interfaces)] pub type Successors<'a> = impl Iterator; diff --git a/tests/ui/lint/lint-ctypes-fn.rs b/tests/ui/lint/lint-ctypes-fn.rs index d3b36a9d59c70..14831e247183a 100644 --- a/tests/ui/lint/lint-ctypes-fn.rs +++ b/tests/ui/lint/lint-ctypes-fn.rs @@ -1,6 +1,6 @@ #![feature(rustc_private)] -#![allow(private_in_public)] +#![allow(private_interfaces)] #![deny(improper_ctypes_definitions)] extern crate libc; diff --git a/tests/ui/lint/lint-ctypes.rs b/tests/ui/lint/lint-ctypes.rs index 9165e14b7ffe3..3dd731625f495 100644 --- a/tests/ui/lint/lint-ctypes.rs +++ b/tests/ui/lint/lint-ctypes.rs @@ -1,6 +1,6 @@ #![feature(rustc_private)] -#![allow(private_in_public)] +#![allow(private_interfaces)] #![deny(improper_ctypes)] extern crate libc; diff --git a/tests/ui/privacy/associated-item-privacy-inherent.rs b/tests/ui/privacy/associated-item-privacy-inherent.rs index 7b7c734a99a1c..81703ae106766 100644 --- a/tests/ui/privacy/associated-item-privacy-inherent.rs +++ b/tests/ui/privacy/associated-item-privacy-inherent.rs @@ -1,5 +1,5 @@ #![feature(decl_macro, associated_type_defaults)] -#![allow(unused, private_in_public)] +#![allow(private_interfaces)] mod priv_nominal { pub struct Pub; diff --git a/tests/ui/privacy/associated-item-privacy-trait.rs b/tests/ui/privacy/associated-item-privacy-trait.rs index c686a21772e0e..db77a6a72580b 100644 --- a/tests/ui/privacy/associated-item-privacy-trait.rs +++ b/tests/ui/privacy/associated-item-privacy-trait.rs @@ -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 { diff --git a/tests/ui/privacy/associated-item-privacy-type-binding.rs b/tests/ui/privacy/associated-item-privacy-type-binding.rs index 9826b83a35d50..95a4fbf639c65 100644 --- a/tests/ui/privacy/associated-item-privacy-type-binding.rs +++ b/tests/ui/privacy/associated-item-privacy-type-binding.rs @@ -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 { diff --git a/tests/ui/privacy/effective_visibilities_full_priv.rs b/tests/ui/privacy/effective_visibilities_full_priv.rs index a26ae3bd12264..b96eddcab671a 100644 --- a/tests/ui/privacy/effective_visibilities_full_priv.rs +++ b/tests/ui/privacy/effective_visibilities_full_priv.rs @@ -1,5 +1,5 @@ #![feature(rustc_attrs)] -#![allow(private_in_public)] +#![allow(private_interfaces)] struct SemiPriv; diff --git a/tests/ui/privacy/issue-30079.rs b/tests/ui/privacy/issue-30079.rs index a02a932d0570a..ddba629f52825 100644 --- a/tests/ui/privacy/issue-30079.rs +++ b/tests/ui/privacy/issue-30079.rs @@ -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::::f` } impl Priv { diff --git a/tests/ui/privacy/issue-30079.stderr b/tests/ui/privacy/issue-30079.stderr index 9179ff339bf6b..f1facba7cd230 100644 --- a/tests/ui/privacy/issue-30079.stderr +++ b/tests/ui/privacy/issue-30079.stderr @@ -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::::f` --> $DIR/issue-30079.rs:6:9 | LL | pub fn f(_: Priv) {} - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ associated function `m1::::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 - = 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 diff --git a/tests/ui/privacy/private-in-public-assoc-ty.rs b/tests/ui/privacy/private-in-public-assoc-ty.rs index d4d379bdb7327..5f7c4bcf2656a 100644 --- a/tests/ui/privacy/private-in-public-assoc-ty.rs +++ b/tests/ui/privacy/private-in-public-assoc-ty.rs @@ -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 = 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 = 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 diff --git a/tests/ui/privacy/private-in-public-assoc-ty.stderr b/tests/ui/privacy/private-in-public-assoc-ty.stderr index a59027d81d286..0931e6d9971ea 100644 --- a/tests/ui/privacy/private-in-public-assoc-ty.stderr +++ b/tests/ui/privacy/private-in-public-assoc-ty.stderr @@ -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 - = 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 = 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 +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 = 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 +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`. diff --git a/tests/ui/privacy/private-in-public-lint.rs b/tests/ui/privacy/private-in-public-lint.rs deleted file mode 100644 index 8b6e43601608d..0000000000000 --- a/tests/ui/privacy/private-in-public-lint.rs +++ /dev/null @@ -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() {} diff --git a/tests/ui/privacy/private-in-public-lint.stderr b/tests/ui/privacy/private-in-public-lint.stderr deleted file mode 100644 index 1e98e3bed147c..0000000000000 --- a/tests/ui/privacy/private-in-public-lint.stderr +++ /dev/null @@ -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`. diff --git a/tests/ui/privacy/private-in-public-non-principal-2.rs b/tests/ui/privacy/private-in-public-non-principal-2.rs index db451d33429b3..d7223c647c0a3 100644 --- a/tests/ui/privacy/private-in-public-non-principal-2.rs +++ b/tests/ui/privacy/private-in-public-non-principal-2.rs @@ -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 {} diff --git a/tests/ui/privacy/private-in-public-non-principal.rs b/tests/ui/privacy/private-in-public-non-principal.rs index a2284c9302742..e348a181651cf 100644 --- a/tests/ui/privacy/private-in-public-non-principal.rs +++ b/tests/ui/privacy/private-in-public-non-principal.rs @@ -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 { 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() { diff --git a/tests/ui/privacy/private-in-public-non-principal.stderr b/tests/ui/privacy/private-in-public-non-principal.stderr index 1387f59cbde12..63512f462f518 100644 --- a/tests/ui/privacy/private-in-public-non-principal.stderr +++ b/tests/ui/privacy/private-in-public-non-principal.stderr @@ -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 { 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 - = 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 { 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 diff --git a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs index fe6ed46734cd2..3fb543e962411 100644 --- a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs +++ b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs @@ -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; diff --git a/tests/ui/privacy/private-in-public-warn.rs b/tests/ui/privacy/private-in-public-warn.rs index 0fa1de975b040..99d318e36be3d 100644 --- a/tests/ui/privacy/private-in-public-warn.rs +++ b/tests/ui/privacy/private-in-public-warn.rs @@ -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); pub trait PubTr {} - pub type Alias = 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 {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + pub type Alias = 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 {} //~ 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(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(arg: T) {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f` } - impl Pub {} //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING hard error + impl Pub {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub` impl PubTr for Pub {} // OK, trait impl predicates } @@ -72,20 +57,16 @@ mod traits_where { pub trait PubTr {} pub type Alias 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 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(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 Pub 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` impl PubTr for Pub where T: PrivTr {} // OK, trait impl predicates } @@ -96,14 +77,10 @@ mod generics { pub trait PubTr {} pub trait Tr1: PrivTr {} - //~^ ERROR private trait `generics::PrivTr` in public interface - //~| WARNING hard error - pub trait Tr2: PubTr {} //~ 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> {} //~ ERROR private type `generics::Priv` in public interface - //~^ WARNING hard error + //~^ ERROR trait `generics::PrivTr` is more private than the item `generics::Tr1` + pub trait Tr2: PubTr {} //~ 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> {} //~ ERROR type `generics::Priv` is more private than the item `Tr4` } mod impls { @@ -200,8 +177,7 @@ mod aliases_pub { pub trait Tr2: PrivUseAliasTr {} // 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::::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 {} - //~^ ERROR private trait `PrivTr1` in public interface - //~| WARNING hard error - //~| ERROR private type `Priv2` in public interface - //~| WARNING hard error + //~^ ERROR trait `PrivTr1` 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 diff --git a/tests/ui/privacy/private-in-public-warn.stderr b/tests/ui/privacy/private-in-public-warn.stderr index 66f91ce6fd683..6497b7ff535cb 100644 --- a/tests/ui/privacy/private-in-public-warn.stderr +++ b/tests/ui/privacy/private-in-public-warn.stderr @@ -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 +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)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 +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)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 +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 +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)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 +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)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 +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 +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 +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)` + | +note: but type `types::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:9:5 | - = 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 +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; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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 +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)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = 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 +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 {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr2` is reachable at visibility `pub(crate)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = 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 +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)` + | +note: but trait `traits::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:37:5 | - = 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 +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(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 +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` + --> $DIR/private-in-public-warn.rs:50:5 | LL | impl Pub {} - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub` 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 +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 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 +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 where T: PrivTr {} - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 | - = 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 +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(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 +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` + --> $DIR/private-in-public-warn.rs:68:5 | LL | impl Pub where T: PrivTr {} - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ implementation `traits_where::Pub` is reachable at visibility `pub(crate)` + | +note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:55:5 | - = 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 +LL | trait PrivTr {} + | ^^^^^^^^^^^^ -error: private trait `generics::PrivTr` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:98:5 +error: trait `generics::PrivTr` is more private than the item `generics::Tr1` + --> $DIR/private-in-public-warn.rs:79:5 | LL | pub trait Tr1: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)` + | +note: but trait `generics::PrivTr` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:76:5 | - = 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 +LL | trait PrivTr {} + | ^^^^^^^^^^^^^^^ -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 {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 | - = 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 +LL | struct Priv(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 +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 + | +LL | struct Priv(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> {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)` + | +note: but type `generics::Priv` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:74:5 | - = 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 +LL | struct Priv(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::::f` + --> $DIR/private-in-public-warn.rs:180:9 | LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::::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 +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 +note: but trait `PrivTr1` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:208:5 + | +LL | trait PrivTr1 { + | ^^^^^^^^^^^^^^^^^^^^^ -error: private trait `PrivTr1` in public interface (error E0445) - --> $DIR/private-in-public-warn.rs:249:5 +error: trait `PrivTr1` is more private than the item `aliases_priv::Tr2` + --> $DIR/private-in-public-warn.rs:224:5 | LL | pub trait Tr2: PrivUseAliasTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 +note: but trait `PrivTr1` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:208:5 + | +LL | trait PrivTr1 { + | ^^^^^^^^^^^^^^^^^^^^^ -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 {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)` + | +note: but type `Priv2` is only usable at visibility `pub(self)` + --> $DIR/private-in-public-warn.rs:206:5 | - = 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 +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; | ^^^^^^ @@ -323,7 +409,7 @@ LL + pub type Alias = 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 where T: PrivTr = T; | ^^^^^^^^^ diff --git a/tests/ui/privacy/private-in-public.rs b/tests/ui/privacy/private-in-public.rs index dbd1c483f81b9..f54f9e38faa9d 100644 --- a/tests/ui/privacy/private-in-public.rs +++ b/tests/ui/privacy/private-in-public.rs @@ -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); pub trait PubTr {} - pub enum E { V(T) } //~ ERROR private trait `traits::PrivTr` in public interface - pub fn f(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface - pub struct S1(T); //~ ERROR private trait `traits::PrivTr` in public interface - impl Pub { //~ ERROR private trait `traits::PrivTr` in public interface - pub fn f(arg: U) {} //~ ERROR private trait `traits::PrivTr` in public interface + pub enum E { V(T) } //~ WARNING trait `traits::PrivTr` is more private than the item `traits::E` + pub fn f(arg: T) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::f` + pub struct S1(T); //~ WARNING trait `traits::PrivTr` is more private than the item `traits::S1` + impl Pub { //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub` + pub fn f(arg: U) {} //~ WARNING trait `traits::PrivTr` is more private than the item `traits::Pub::::f` } } @@ -42,15 +44,15 @@ mod traits_where { pub trait PubTr {} pub enum E 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(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) 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 Pub 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` pub fn f(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::::f` } } @@ -60,10 +62,10 @@ mod generics { trait PrivTr {} pub trait PubTr {} - pub fn f1(arg: [Priv; 1]) {} //~ ERROR private type `generics::Priv` in public interface - pub fn f2(arg: Pub) {} //~ 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) {} //~ WARNING type `generics::Priv` is more private than the item `generics::f2` pub fn f3(arg: Priv) {} - //~^ ERROR private type `generics::Priv` in public interface + //~^ WARNING type `generics::Priv` 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: ::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: ::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 = ::std::result::Result; pub fn f2(arg: PrivAliasGeneric) {} - //~^ ERROR private type `aliases_params::Priv` in public interface - pub fn f3(arg: Result) {} //~ 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) {} //~ WARNING type `aliases_params::Priv` is more private than the item `aliases_params::f3` } fn main() {} diff --git a/tests/ui/privacy/private-in-public.stderr b/tests/ui/privacy/private-in-public.stderr index 887eebf53efac..d8f9fd0071681 100644 --- a/tests/ui/privacy/private-in-public.stderr +++ b/tests/ui/privacy/private-in-public.stderr @@ -1,292 +1,376 @@ -error[E0446]: private type `types::Priv` in public interface - --> $DIR/private-in-public.rs:13:5 +warning: type `types::Priv` is more private than the item `C` + --> $DIR/private-in-public.rs:15: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 + | ^^^^^^^^^^^^^^^^^ constant `C` is reachable at visibility `pub(crate)` | -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 - --> $DIR/private-in-public.rs:15:5 +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 -... -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 +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; - | ----------- `types::Priv` declared as private -... -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 +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!() } + | ^^^^^^^^^^^^^^^^^^^ 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 -... -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 +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); + | ^^^^^^^^ 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 -... -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 +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 } + | ^^^^^^^^^^^^^^^ 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 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 -... -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 +warning: type `types::Priv` is more private than the item `types::Pub::f1` + --> $DIR/private-in-public.rs:23:9 | -LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub enum E { V(T) } - | ^^^^^^^^^^^^^^^^^^^^^ can't leak private trait +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; + | ^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:32:5 +warning: type `types::Priv` is more private than the item `types::Pub::f2` + --> $DIR/private-in-public.rs:24:9 | -LL | trait PrivTr {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub fn f(arg: T) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait +LL | pub fn f2() -> Priv { panic!() } + | ^^^^^^^^^^^^^^^^^^^ associated function `types::Pub::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; + | ^^^^^^^^^^^ -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 { 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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ 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(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 -... -LL | impl Pub { - | ^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits::PrivTr` in public interface - --> $DIR/private-in-public.rs:35:9 +warning: trait `traits::PrivTr` is more private than the item `traits::S1` + --> $DIR/private-in-public.rs:35:5 + | +LL | pub struct S1(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 {} - | ------------ `traits::PrivTr` declared as private -... -LL | pub fn f(arg: U) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface - --> $DIR/private-in-public.rs:44:5 +warning: trait `traits::PrivTr` is more private than the item `traits::Pub` + --> $DIR/private-in-public.rs:36:5 + | +LL | impl Pub { + | ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub` 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 where T: PrivTr { V(T) } - | ^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^ -error[E0445]: private trait `traits_where::PrivTr` in public interface +warning: trait `traits::PrivTr` is more private than the item `traits::Pub::::f` + --> $DIR/private-in-public.rs:37:9 + | +LL | pub fn f(arg: U) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Pub::::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 {} + | ^^^^^^^^^^^^ + +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 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(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(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) 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) 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 -... -LL | impl Pub 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 +warning: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub` + --> $DIR/private-in-public.rs:52:5 + | +LL | impl Pub where T: PrivTr { + | ^^^^^^^^^^^^^^ implementation `traits_where::Pub` 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::::f` + --> $DIR/private-in-public.rs:54:9 + | LL | pub fn f(arg: U) where U: PrivTr {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Pub::::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 {} + | ^^^^^^^^^^^^ -error[E0446]: private type `generics::Priv` in public interface - --> $DIR/private-in-public.rs:63:5 +warning: type `generics::Priv` is more private than the item `generics::f1` + --> $DIR/private-in-public.rs:65:5 | -LL | struct Priv(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 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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); - | ------------------- `generics::Priv` declared as private -... -LL | pub fn f2(arg: Pub) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `generics::Priv` in public interface - --> $DIR/private-in-public.rs:65:5 +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) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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); - | ------------------- `generics::Priv` declared as private -... + | ^^^^^^^^^^^^^^^^^^^ + +warning: type `generics::Priv` is more private than the item `generics::f3` + --> $DIR/private-in-public.rs:67:5 + | LL | pub fn f3(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^ function `generics::f3` 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); + | ^^^^^^^^^^^^^^^^^^^ -error[E0446]: private type `impls::Priv` in public interface - --> $DIR/private-in-public.rs:80:9 +warning: type `impls::Priv` is more private than the item `impls::Pub::f` + --> $DIR/private-in-public.rs:82:9 | -LL | struct Priv; - | ----------- `impls::Priv` declared as private -... LL | pub fn f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^ 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; + | ^^^^^^^^^^^ -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 | trait PrivTr { - | ------------ `aliases_pub::PrivTr` declared as private -... LL | pub fn f3(arg: ::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 { + | ^^^^^^^^^^^^ -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 | struct Priv; - | ----------- `aliases_pub::Priv` declared as private -... LL | pub fn f3(arg: ::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `aliases_pub::Priv` in public interface - --> $DIR/private-in-public.rs:109:9 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 f(arg: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^ -error[E0446]: private type `Priv1` in public interface - --> $DIR/private-in-public.rs:131:5 +warning: type `Priv1` is more private than the item `aliases_priv::f1` + --> $DIR/private-in-public.rs:133:5 | -LL | struct Priv1; - | ------------ `Priv1` declared as private -... LL | pub fn f1(arg: PrivUseAlias) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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; + | ^^^^^^^^^^^^ -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 | struct Priv2; - | ------------ `Priv2` declared as private -... LL | pub fn f2(arg: PrivAlias) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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; + | ^^^^^^^^^^^^ -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 | trait PrivTr { - | ------------ `aliases_priv::PrivTr` declared as private -... LL | pub fn f3(arg: ::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private trait + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 { + | ^^^^^^^^^^^^ -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 | struct Priv; - | ----------- `aliases_priv::Priv` declared as private -... LL | pub fn f3(arg: ::Assoc) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type - -error[E0446]: private type `aliases_params::Priv` in public interface - --> $DIR/private-in-public.rs:143:5 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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_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) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`. diff --git a/tests/ui/privacy/private-inferred-type-2.rs b/tests/ui/privacy/private-inferred-type-2.rs index 15b263b38144b..1c4c52bea289f 100644 --- a/tests/ui/privacy/private-inferred-type-2.rs +++ b/tests/ui/privacy/private-inferred-type-2.rs @@ -1,4 +1,5 @@ // aux-build:private-inferred-type.rs +#![allow(private_interfaces)] extern crate private_inferred_type as ext; diff --git a/tests/ui/privacy/private-inferred-type-2.stderr b/tests/ui/privacy/private-inferred-type-2.stderr index 3a0fc03b4d507..8a905f5d88ab3 100644 --- a/tests/ui/privacy/private-inferred-type-2.stderr +++ b/tests/ui/privacy/private-inferred-type-2.stderr @@ -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 diff --git a/tests/ui/privacy/private-inferred-type.rs b/tests/ui/privacy/private-inferred-type.rs index e8743dd968feb..8c07226fe0e4d 100644 --- a/tests/ui/privacy/private-inferred-type.rs +++ b/tests/ui/privacy/private-inferred-type.rs @@ -1,5 +1,5 @@ #![feature(decl_macro)] -#![allow(private_in_public)] +#![allow(private_interfaces)] mod m { fn priv_fn() {} diff --git a/tests/ui/privacy/private-type-in-interface.rs b/tests/ui/privacy/private-type-in-interface.rs index 7fbdbaf5f313c..39e0bf23cacb2 100644 --- a/tests/ui/privacy/private-type-in-interface.rs +++ b/tests/ui/privacy/private-type-in-interface.rs @@ -1,6 +1,7 @@ // aux-build:private-inferred-type.rs #![allow(warnings)] +#![allow(private_interfaces)] extern crate private_inferred_type as ext; diff --git a/tests/ui/privacy/private-type-in-interface.stderr b/tests/ui/privacy/private-type-in-interface.stderr index 4e87caa341569..03225d84fdb34 100644 --- a/tests/ui/privacy/private-type-in-interface.stderr +++ b/tests/ui/privacy/private-type-in-interface.stderr @@ -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 = ::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 { 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 { 0 } | ^^^^^^^^^^^^^^^^^^^^ private type diff --git a/tests/ui/privacy/restricted/private-in-public.rs b/tests/ui/privacy/restricted/private-in-public.rs index 1e3dbdf73b96c..80a7e6ad0a7ec 100644 --- a/tests/ui/privacy/restricted/private-in-public.rs +++ b/tests/ui/privacy/restricted/private-in-public.rs @@ -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) {} } } diff --git a/tests/ui/privacy/restricted/private-in-public.stderr b/tests/ui/privacy/restricted/private-in-public.stderr deleted file mode 100644 index 65d996f0f0709..0000000000000 --- a/tests/ui/privacy/restricted/private-in-public.stderr +++ /dev/null @@ -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`. diff --git a/tests/ui/privacy/unnameable_types.rs b/tests/ui/privacy/unnameable_types.rs index 46e249152594b..e35aaec5b3baf 100644 --- a/tests/ui/privacy/unnameable_types.rs +++ b/tests/ui/privacy/unnameable_types.rs @@ -1,5 +1,4 @@ #![feature(type_privacy_lints)] -#![allow(private_in_public)] #![deny(unnameable_types)] mod m { diff --git a/tests/ui/privacy/unnameable_types.stderr b/tests/ui/privacy/unnameable_types.stderr index 904127525758f..d68a11c9728f6 100644 --- a/tests/ui/privacy/unnameable_types.stderr +++ b/tests/ui/privacy/unnameable_types.stderr @@ -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)` diff --git a/tests/ui/privacy/where-priv-type.rs b/tests/ui/privacy/where-priv-type.rs index 2e0a6b3e72cc1..cd9cce7ec3e8d 100644 --- a/tests/ui/privacy/where-priv-type.rs +++ b/tests/ui/privacy/where-priv-type.rs @@ -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 ` as Trait>::AssocTy` fn assoc_fn() -> Self::AssocTy { Const } diff --git a/tests/ui/privacy/where-priv-type.stderr b/tests/ui/privacy/where-priv-type.stderr index d6baf22b3fbc0..dcc249c635119 100644 --- a/tests/ui/privacy/where-priv-type.stderr +++ b/tests/ui/privacy/where-priv-type.stderr @@ -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 - = 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 + = 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 - 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 - 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 ` as Trait>::AssocTy` - --> $DIR/where-priv-type.rs:91:5 - | -LL | type AssocTy = Const<{ my_const_fn(U) }>; - | ^^^^^^^^^^^^ associated type ` 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`. diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs index c59fdb7c7a960..d5e797b52b30b 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.rs +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.rs @@ -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 {} diff --git a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr index e2d7ce4469242..c476874332c57 100644 --- a/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr +++ b/tests/ui/privacy/where-pub-type-impls-priv-trait.stderr @@ -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`. diff --git a/tests/ui/proc-macro/allowed-signatures.rs b/tests/ui/proc-macro/allowed-signatures.rs index 8685087611248..ce327901b1a24 100644 --- a/tests/ui/proc-macro/allowed-signatures.rs +++ b/tests/ui/proc-macro/allowed-signatures.rs @@ -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; diff --git a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs index cdeea6224b208..7930964c83bfd 100644 --- a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs +++ b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.rs @@ -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 { pub(crate) creature: T, } pub type Helix_pomatia = Shell; -//~^ 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; -//~^ 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; -//~^ 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() {} diff --git a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr index 20e51e1901ff2..26dfa2e7d4f61 100644 --- a/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr +++ b/tests/ui/pub/issue-33174-restricted-type-in-public-interface.stderr @@ -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; - | ^^^^^^^^^^^^^^^^^^^^^^ 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; | ^^^^^^^^^^^^^^^^^^^^^^ 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; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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; - | ^^^^^^^^^^^^^^^^^^^^^^^ 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; | ^^^^^^^^^^^^^^^^^^^^^^^ 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`. diff --git a/tests/ui/test-attrs/issue-36768.rs b/tests/ui/test-attrs/issue-36768.rs index f671cbc820505..7531f3621f50f 100644 --- a/tests/ui/test-attrs/issue-36768.rs +++ b/tests/ui/test-attrs/issue-36768.rs @@ -1,6 +1,6 @@ // run-pass // compile-flags:--test -#![deny(private_in_public)] +#![deny(private_interfaces)] #[test] fn foo() {} mod foo {} diff --git a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs index 546fcbaa3de23..b61291633330b 100644 --- a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs +++ b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.rs @@ -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` } } diff --git a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr index be83b7ce33f24..80099388d6354 100644 --- a/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr +++ b/tests/ui/transmutability/visibility/assume/should_accept_if_dst_has_unreachable_field.stderr @@ -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 | #[repr(C)] pub(self) struct Zst; // <- unreachable type - | -------------------- `dst::Zst` declared as private -... LL | pub(in super) field: Zst, - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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 + | ^^^^^^^^^^^^^^^^^^^^ + = 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`. diff --git a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs index 9c8345a8e91a9..e7742058c57f5 100644 --- a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs +++ b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.rs @@ -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` } } diff --git a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr index 39b73302e364d..55fb339230578 100644 --- a/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr +++ b/tests/ui/transmutability/visibility/should_accept_if_src_has_unreachable_field.stderr @@ -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 | #[repr(C)] pub(self) struct Zst; // <- unreachable type - | -------------------- `src::Zst` declared as private -... LL | pub(in super) field: Zst, - | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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 + | ^^^^^^^^^^^^^^^^^^^^ + = 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`. diff --git a/tests/ui/type-alias-impl-trait/privacy.rs b/tests/ui/type-alias-impl-trait/privacy.rs index aa092f6f8ecc6..3efbfaf09167e 100644 --- a/tests/ui/type-alias-impl-trait/privacy.rs +++ b/tests/ui/type-alias-impl-trait/privacy.rs @@ -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() {} diff --git a/tests/ui/type-alias-impl-trait/privacy.stderr b/tests/ui/type-alias-impl-trait/privacy.stderr index e8c6039cdc84b..50870905c30dd 100644 --- a/tests/ui/type-alias-impl-trait/privacy.stderr +++ b/tests/ui/type-alias-impl-trait/privacy.stderr @@ -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 | type Foo = (impl Sized, u8); - | -------- `Foo` declared as private LL | pub fn foo() -> Foo { - | ^^^^^^^^^^^^^^^^^^^ can't leak private type alias + | ^^^^^^^^^^^^^^^^^^^ 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); + | ^^^^^^^^ + = 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`.