privacy: Synchronize PrivateItemsInPublicInterfacesChecker and EmbargoVisitor

This commit is contained in:
Vadim Petrochenkov 2026-01-18 15:01:51 +03:00
parent 88f2e79b77
commit 7b5a4d8653
6 changed files with 59 additions and 64 deletions

View file

@ -652,6 +652,19 @@ impl<'tcx> EmbargoVisitor<'tcx> {
}
impl<'tcx> EmbargoVisitor<'tcx> {
fn check_assoc_item(&mut self, item: &ty::AssocItem, item_ev: EffectiveVisibility) {
let def_id = item.def_id.expect_local();
let tcx = self.tcx;
let mut reach = self.reach(def_id, item_ev);
reach.generics().predicates();
if assoc_has_type_of(tcx, item) {
reach.ty();
}
if item.is_type() && item.container == AssocContainer::Trait {
reach.bounds();
}
}
fn check_def_id(&mut self, owner_id: OwnerId) {
// Update levels of nested things and mark all items
// in interfaces of reachable items as reachable.
@ -682,19 +695,10 @@ impl<'tcx> EmbargoVisitor<'tcx> {
self.reach(owner_id.def_id, item_ev).generics().predicates();
for assoc_item in self.tcx.associated_items(owner_id).in_definition_order() {
if assoc_item.is_impl_trait_in_trait() {
continue;
}
let def_id = assoc_item.def_id.expect_local();
self.update(def_id, item_ev, Level::Reachable);
let tcx = self.tcx;
let mut reach = self.reach(def_id, item_ev);
reach.generics().predicates();
if assoc_has_type_of(tcx, assoc_item) {
reach.ty();
}
self.check_assoc_item(assoc_item, item_ev);
}
}
}
@ -732,17 +736,13 @@ impl<'tcx> EmbargoVisitor<'tcx> {
}
for assoc_item in self.tcx.associated_items(owner_id).in_definition_order() {
if assoc_item.is_impl_trait_in_trait() {
continue;
}
let def_id = assoc_item.def_id.expect_local();
let max_vis =
if of_trait { None } else { Some(self.tcx.local_visibility(def_id)) };
self.update_eff_vis(def_id, item_ev, max_vis, Level::Direct);
if let Some(impl_item_ev) = self.get(def_id) {
self.reach(def_id, impl_item_ev).generics().predicates().ty();
self.check_assoc_item(assoc_item, impl_item_ev);
}
}
}
@ -834,7 +834,12 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
}
fn predicates(&mut self) -> &mut Self {
self.visit_predicates(self.ev.tcx.predicates_of(self.item_def_id));
self.visit_predicates(self.ev.tcx.explicit_predicates_of(self.item_def_id));
self
}
fn bounds(&mut self) -> &mut Self {
self.visit_clauses(self.ev.tcx.explicit_item_bounds(self.item_def_id).skip_binder());
self
}
@ -1372,17 +1377,11 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
fn generics(&mut self) -> &mut Self {
self.in_primary_interface = true;
for param in &self.tcx.generics_of(self.item_def_id).own_params {
match param.kind {
GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => {
if has_default {
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
}
}
// FIXME(generic_const_exprs): May want to look inside const here
GenericParamDefKind::Const { .. } => {
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
}
if let GenericParamDefKind::Const { .. } = param.kind {
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
}
if let Some(default) = param.default_value(self.tcx) {
let _ = self.visit(default.instantiate_identity());
}
}
self

View file

@ -108,6 +108,18 @@ LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
LL | [2u32].into_iter()
| ------------------ return type was inferred to be `std::array::IntoIter<u32, 1>` here
error[E0271]: expected `impl Iterator<Item = u32>` to be an iterator that yields `i32`, but it yields `u32`
--> $DIR/duplicate-bound-err.rs:111:17
|
LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
|
note: required by a bound in `Trait3::foo::{anon_assoc#0}`
--> $DIR/duplicate-bound-err.rs:107:31
|
LL | fn foo() -> impl Iterator<Item = i32, Item = u32>;
| ^^^^^^^^^^ required by this bound in `Trait3::foo::{anon_assoc#0}`
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
--> $DIR/duplicate-bound-err.rs:87:42
|
@ -158,18 +170,6 @@ LL | type MustFail4 = dyn Trait2<ASSOC = 3u32, ASSOC = 3u32>;
| |
| `ASSOC` bound here first
error[E0271]: expected `impl Iterator<Item = u32>` to be an iterator that yields `i32`, but it yields `u32`
--> $DIR/duplicate-bound-err.rs:111:17
|
LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
|
note: required by a bound in `Trait3::foo::{anon_assoc#0}`
--> $DIR/duplicate-bound-err.rs:107:31
|
LL | fn foo() -> impl Iterator<Item = i32, Item = u32>;
| ^^^^^^^^^^ required by this bound in `Trait3::foo::{anon_assoc#0}`
error[E0271]: expected `Empty<u32>` to be an iterator that yields `i32`, but it yields `u32`
--> $DIR/duplicate-bound-err.rs:119:16
|

View file

@ -29,11 +29,7 @@ note: ...which requires comparing an impl and trait method signature, inferring
LL | reuse ToReuse::opaque_ret;
| ^^^^^^^^^^
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:32:5: 32:25>::opaque_ret::{anon_assoc#0}`, completing the cycle
note: cycle used when checking assoc item `opaque::<impl at $DIR/unsupported.rs:32:5: 32:25>::opaque_ret` is compatible with trait definition
--> $DIR/unsupported.rs:33:24
|
LL | reuse ToReuse::opaque_ret;
| ^^^^^^^^^^
= note: cycle used when checking effective visibilities
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0283]: type annotations needed

View file

@ -25,7 +25,7 @@ note: ...which requires comparing an impl and trait method signature, inferring
LL | reuse ToReuse::opaque_ret;
| ^^^^^^^^^^
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:32:5: 32:25>::opaque_ret::{anon_assoc#0}`, completing the cycle
= note: cycle used when computing implied outlives bounds for `<u16 as opaque::ToReuse>::opaque_ret::{anon_assoc#0}` (hack disabled = false)
= note: cycle used when checking effective visibilities
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0283]: type annotations needed

View file

@ -1,8 +1,8 @@
warning: use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
--> $DIR/lint-stability-deprecated.rs:97:48
warning: use of deprecated function `lint_stability::deprecated`: text
--> $DIR/lint-stability-deprecated.rs:24:9
|
LL | struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
| ^^^^^^^^^^^^^^^^^
LL | deprecated();
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/lint-stability-deprecated.rs:6:9
@ -10,12 +10,6 @@ note: the lint level is defined here
LL | #![warn(deprecated)]
| ^^^^^^^^^^
warning: use of deprecated function `lint_stability::deprecated`: text
--> $DIR/lint-stability-deprecated.rs:24:9
|
LL | deprecated();
| ^^^^^^^^^^
warning: use of deprecated method `lint_stability::Trait::trait_deprecated`: text
--> $DIR/lint-stability-deprecated.rs:29:16
|
@ -322,6 +316,12 @@ warning: use of deprecated function `this_crate::MethodTester::test_method_body:
LL | fn_in_body();
| ^^^^^^^^^^
warning: use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
--> $DIR/lint-stability-deprecated.rs:97:48
|
LL | struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
| ^^^^^^^^^^^^^^^^^
warning: use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
--> $DIR/lint-stability-deprecated.rs:101:13
|

View file

@ -1,12 +1,3 @@
error[E0658]: use of unstable library feature `unstable_test_feature`
--> $DIR/lint-stability.rs:88:48
|
LL | struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
| ^^^^^^^^^^^^^^^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `unstable_test_feature`
--> $DIR/lint-stability.rs:17:5
|
@ -376,6 +367,15 @@ LL | let _ = Unstable::StableVariant;
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `unstable_test_feature`
--> $DIR/lint-stability.rs:88:48
|
LL | struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
| ^^^^^^^^^^^^^^^
|
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `unstable_test_feature`
--> $DIR/lint-stability.rs:92:13
|