Skip to content

Commit b0c8fdc

Browse files
committed
privacy: Synchronize PrivateItemsInPublicInterfacesChecker and EmbargoVisitor
1 parent 8895341 commit b0c8fdc

6 files changed

Lines changed: 59 additions & 64 deletions

File tree

compiler/rustc_privacy/src/lib.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,19 @@ impl<'tcx> EmbargoVisitor<'tcx> {
652652
}
653653

654654
impl<'tcx> EmbargoVisitor<'tcx> {
655+
fn check_assoc_item(&mut self, item: &ty::AssocItem, item_ev: EffectiveVisibility) {
656+
let def_id = item.def_id.expect_local();
657+
let tcx = self.tcx;
658+
let mut reach = self.reach(def_id, item_ev);
659+
reach.generics().predicates();
660+
if assoc_has_type_of(tcx, item) {
661+
reach.ty();
662+
}
663+
if item.is_type() && item.container == AssocContainer::Trait {
664+
reach.bounds();
665+
}
666+
}
667+
655668
fn check_def_id(&mut self, owner_id: OwnerId) {
656669
// Update levels of nested things and mark all items
657670
// in interfaces of reachable items as reachable.
@@ -682,19 +695,10 @@ impl<'tcx> EmbargoVisitor<'tcx> {
682695
self.reach(owner_id.def_id, item_ev).generics().predicates();
683696

684697
for assoc_item in self.tcx.associated_items(owner_id).in_definition_order() {
685-
if assoc_item.is_impl_trait_in_trait() {
686-
continue;
687-
}
688-
689698
let def_id = assoc_item.def_id.expect_local();
690699
self.update(def_id, item_ev, Level::Reachable);
691700

692-
let tcx = self.tcx;
693-
let mut reach = self.reach(def_id, item_ev);
694-
reach.generics().predicates();
695-
if assoc_has_type_of(tcx, assoc_item) {
696-
reach.ty();
697-
}
701+
self.check_assoc_item(assoc_item, item_ev);
698702
}
699703
}
700704
}
@@ -732,17 +736,13 @@ impl<'tcx> EmbargoVisitor<'tcx> {
732736
}
733737

734738
for assoc_item in self.tcx.associated_items(owner_id).in_definition_order() {
735-
if assoc_item.is_impl_trait_in_trait() {
736-
continue;
737-
}
738-
739739
let def_id = assoc_item.def_id.expect_local();
740740
let max_vis =
741741
if of_trait { None } else { Some(self.tcx.local_visibility(def_id)) };
742742
self.update_eff_vis(def_id, item_ev, max_vis, Level::Direct);
743743

744744
if let Some(impl_item_ev) = self.get(def_id) {
745-
self.reach(def_id, impl_item_ev).generics().predicates().ty();
745+
self.check_assoc_item(assoc_item, impl_item_ev);
746746
}
747747
}
748748
}
@@ -834,7 +834,12 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
834834
}
835835

836836
fn predicates(&mut self) -> &mut Self {
837-
self.visit_predicates(self.ev.tcx.predicates_of(self.item_def_id));
837+
self.visit_predicates(self.ev.tcx.explicit_predicates_of(self.item_def_id));
838+
self
839+
}
840+
841+
fn bounds(&mut self) -> &mut Self {
842+
self.visit_clauses(self.ev.tcx.explicit_item_bounds(self.item_def_id).skip_binder());
838843
self
839844
}
840845

@@ -1372,17 +1377,11 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13721377
fn generics(&mut self) -> &mut Self {
13731378
self.in_primary_interface = true;
13741379
for param in &self.tcx.generics_of(self.item_def_id).own_params {
1375-
match param.kind {
1376-
GenericParamDefKind::Lifetime => {}
1377-
GenericParamDefKind::Type { has_default, .. } => {
1378-
if has_default {
1379-
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
1380-
}
1381-
}
1382-
// FIXME(generic_const_exprs): May want to look inside const here
1383-
GenericParamDefKind::Const { .. } => {
1384-
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
1385-
}
1380+
if let GenericParamDefKind::Const { .. } = param.kind {
1381+
let _ = self.visit(self.tcx.type_of(param.def_id).instantiate_identity());
1382+
}
1383+
if let Some(default) = param.default_value(self.tcx) {
1384+
let _ = self.visit(default.instantiate_identity());
13861385
}
13871386
}
13881387
self

tests/ui/associated-type-bounds/duplicate-bound-err.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
108108
LL | [2u32].into_iter()
109109
| ------------------ return type was inferred to be `std::array::IntoIter<u32, 1>` here
110110

111+
error[E0271]: expected `impl Iterator<Item = u32>` to be an iterator that yields `i32`, but it yields `u32`
112+
--> $DIR/duplicate-bound-err.rs:111:17
113+
|
114+
LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
116+
|
117+
note: required by a bound in `Trait3::foo::{anon_assoc#0}`
118+
--> $DIR/duplicate-bound-err.rs:107:31
119+
|
120+
LL | fn foo() -> impl Iterator<Item = i32, Item = u32>;
121+
| ^^^^^^^^^^ required by this bound in `Trait3::foo::{anon_assoc#0}`
122+
111123
error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified
112124
--> $DIR/duplicate-bound-err.rs:87:42
113125
|
@@ -158,18 +170,6 @@ LL | type MustFail4 = dyn Trait2<ASSOC = 3u32, ASSOC = 3u32>;
158170
| |
159171
| `ASSOC` bound here first
160172

161-
error[E0271]: expected `impl Iterator<Item = u32>` to be an iterator that yields `i32`, but it yields `u32`
162-
--> $DIR/duplicate-bound-err.rs:111:17
163-
|
164-
LL | fn foo() -> impl Iterator<Item = i32, Item = u32> {
165-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32`
166-
|
167-
note: required by a bound in `Trait3::foo::{anon_assoc#0}`
168-
--> $DIR/duplicate-bound-err.rs:107:31
169-
|
170-
LL | fn foo() -> impl Iterator<Item = i32, Item = u32>;
171-
| ^^^^^^^^^^ required by this bound in `Trait3::foo::{anon_assoc#0}`
172-
173173
error[E0271]: expected `Empty<u32>` to be an iterator that yields `i32`, but it yields `u32`
174174
--> $DIR/duplicate-bound-err.rs:119:16
175175
|

tests/ui/delegation/unsupported.current.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ note: ...which requires comparing an impl and trait method signature, inferring
2929
LL | reuse ToReuse::opaque_ret;
3030
| ^^^^^^^^^^
3131
= 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
32-
note: cycle used when checking assoc item `opaque::<impl at $DIR/unsupported.rs:32:5: 32:25>::opaque_ret` is compatible with trait definition
33-
--> $DIR/unsupported.rs:33:24
34-
|
35-
LL | reuse ToReuse::opaque_ret;
36-
| ^^^^^^^^^^
32+
= note: cycle used when checking effective visibilities
3733
= 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
3834

3935
error[E0283]: type annotations needed

tests/ui/delegation/unsupported.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ note: ...which requires comparing an impl and trait method signature, inferring
2525
LL | reuse ToReuse::opaque_ret;
2626
| ^^^^^^^^^^
2727
= 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
28-
= note: cycle used when computing implied outlives bounds for `<u16 as opaque::ToReuse>::opaque_ret::{anon_assoc#0}` (hack disabled = false)
28+
= note: cycle used when checking effective visibilities
2929
= 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
3030

3131
error[E0283]: type annotations needed

tests/ui/lint/lint-stability-deprecated.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
warning: use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
2-
--> $DIR/lint-stability-deprecated.rs:97:48
1+
warning: use of deprecated function `lint_stability::deprecated`: text
2+
--> $DIR/lint-stability-deprecated.rs:24:9
33
|
4-
LL | struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
5-
| ^^^^^^^^^^^^^^^^^
4+
LL | deprecated();
5+
| ^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/lint-stability-deprecated.rs:6:9
99
|
1010
LL | #![warn(deprecated)]
1111
| ^^^^^^^^^^
1212

13-
warning: use of deprecated function `lint_stability::deprecated`: text
14-
--> $DIR/lint-stability-deprecated.rs:24:9
15-
|
16-
LL | deprecated();
17-
| ^^^^^^^^^^
18-
1913
warning: use of deprecated method `lint_stability::Trait::trait_deprecated`: text
2014
--> $DIR/lint-stability-deprecated.rs:29:16
2115
|
@@ -322,6 +316,12 @@ warning: use of deprecated function `this_crate::MethodTester::test_method_body:
322316
LL | fn_in_body();
323317
| ^^^^^^^^^^
324318

319+
warning: use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
320+
--> $DIR/lint-stability-deprecated.rs:97:48
321+
|
322+
LL | struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
323+
| ^^^^^^^^^^^^^^^^^
324+
325325
warning: use of deprecated associated type `lint_stability::TraitWithAssociatedTypes::TypeDeprecated`: text
326326
--> $DIR/lint-stability-deprecated.rs:101:13
327327
|

tests/ui/lint/lint-stability.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error[E0658]: use of unstable library feature `unstable_test_feature`
2-
--> $DIR/lint-stability.rs:88:48
3-
|
4-
LL | struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
5-
| ^^^^^^^^^^^^^^^
6-
|
7-
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
8-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9-
101
error[E0658]: use of unstable library feature `unstable_test_feature`
112
--> $DIR/lint-stability.rs:17:5
123
|
@@ -376,6 +367,15 @@ LL | let _ = Unstable::StableVariant;
376367
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
377368
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
378369

370+
error[E0658]: use of unstable library feature `unstable_test_feature`
371+
--> $DIR/lint-stability.rs:88:48
372+
|
373+
LL | struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
374+
| ^^^^^^^^^^^^^^^
375+
|
376+
= help: add `#![feature(unstable_test_feature)]` to the crate attributes to enable
377+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
378+
379379
error[E0658]: use of unstable library feature `unstable_test_feature`
380380
--> $DIR/lint-stability.rs:92:13
381381
|

0 commit comments

Comments
 (0)