Skip to content

Commit 73b15e4

Browse files
committed
Remove detection of private dependency leaks for use and extern from rustc_privacy
1 parent 6e8f9dd commit 73b15e4

File tree

4 files changed

+14
-82
lines changed

4 files changed

+14
-82
lines changed

compiler/rustc_privacy/src/lib.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,33 +1789,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
17891789
}
17901790
}
17911791
}
1792-
DefKind::Use => {
1793-
let item = tcx.hir_item(id);
1794-
if let hir::ItemKind::Use(path, use_kind) = item.kind
1795-
// List imports are desugared as single ones so skip `ListStem`s
1796-
&& use_kind != rustc_hir::UseKind::ListStem
1797-
{
1798-
if let Some(def_id) = path.res.iter().filter_map(Res::opt_def_id).last() {
1799-
// normally, public items in a private modules can be re-exported but this should be linted for
1800-
// leakages of a private dependencies
1801-
self.check_private_dep_leaks_only(item.owner_id.def_id, item_visibility)
1802-
.check_def_id(
1803-
def_id,
1804-
item.kind.descr(),
1805-
&LazyDefPathStr { def_id, tcx },
1806-
);
1807-
}
1808-
}
1809-
}
1810-
DefKind::ExternCrate => {
1811-
let item = tcx.hir_item(id);
1812-
if let Some(cnum) = tcx.extern_mod_stmt_cnum(item.owner_id.def_id) {
1813-
let def_id = cnum.as_def_id();
1814-
// `pub extern some_dep` should be linted if and only if `some_dep` is a private dependency
1815-
self.check_private_dep_leaks_only(item.owner_id.def_id, item_visibility)
1816-
.visit_def_id(def_id, item.kind.descr(), &LazyDefPathStr { def_id, tcx });
1817-
}
1818-
}
18191792
_ => {}
18201793
}
18211794
}

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ hashbrown = { version = "0.15", default-features = false, features = [
2525
] }
2626
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = [
2727
'rustc-dep-of-std',
28-
], public = true }
28+
] }
2929

3030
# Dependencies of the `backtrace` crate
3131
rustc-demangle = { version = "0.1.24", features = ['rustc-dep-of-std'] }

tests/ui/privacy/pub-priv-dep/pub-priv1.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#![allow(hidden_glob_reexports)]
1111

1212
// This crate is a private dependency
13+
// FIXME: This should trigger.
1314
pub extern crate priv_dep;
14-
//~^ ERROR extern crate `priv_dep` from private dependency 'priv_dep' in public interface
1515
// This crate is a public dependency
1616
extern crate pub_dep;
1717
// This crate is a private dependency
@@ -91,17 +91,18 @@ pub struct AllowedPrivType {
9191
pub allowed: OtherType,
9292
}
9393

94+
// FIXME: This should trigger.
9495
pub use priv_dep::m;
95-
//~^ ERROR `use` import `m` from private dependency 'priv_dep' in public interface
96+
// FIXME: This should trigger.
9697
pub use pm::fn_like;
97-
//~^ ERROR `use` import `fn_like` from private dependency 'pm' in public interface
98+
// FIXME: This should trigger.
9899
pub use pm::PmDerive;
99-
//~^ ERROR `use` import `PmDerive` from private dependency 'pm' in public interface
100+
// FIXME: This should trigger.
100101
pub use pm::pm_attr;
101-
//~^ ERROR `use` import `pm_attr` from private dependency 'pm' in public interface
102+
103+
// FIXME: This should trigger.
102104
pub use priv_dep::E::V1;
103-
//~^ ERROR `use` import `V1` from private dependency 'priv_dep' in public interface
105+
// FIXME: This should trigger.
104106
pub use priv_dep::*;
105-
//~^ ERROR `use` import `priv_dep` from private dependency 'priv_dep' in public interface
106107

107108
fn main() {}

tests/ui/privacy/pub-priv-dep/pub-priv1.stderr

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
error: extern crate `priv_dep` from private dependency 'priv_dep' in public interface
2-
--> $DIR/pub-priv1.rs:13:1
1+
error: type `OtherType` from private dependency 'priv_dep' in public interface
2+
--> $DIR/pub-priv1.rs:30:5
33
|
4-
LL | pub extern crate priv_dep;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | pub field: OtherType,
5+
| ^^^^^^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/pub-priv1.rs:9:9
99
|
1010
LL | #![deny(exported_private_dependencies)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: type `OtherType` from private dependency 'priv_dep' in public interface
14-
--> $DIR/pub-priv1.rs:30:5
15-
|
16-
LL | pub field: OtherType,
17-
| ^^^^^^^^^^^^^^^^^^^^
18-
1913
error: type `OtherType` from private dependency 'priv_dep' in public interface
2014
--> $DIR/pub-priv1.rs:37:5
2115
|
@@ -88,41 +82,5 @@ error: type `OtherType` from private dependency 'priv_dep' in public interface
8882
LL | impl PubTraitOnPrivate for OtherType {}
8983
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9084

91-
error: `use` import `m` from private dependency 'priv_dep' in public interface
92-
--> $DIR/pub-priv1.rs:94:9
93-
|
94-
LL | pub use priv_dep::m;
95-
| ^^^^^^^^^^^
96-
97-
error: `use` import `fn_like` from private dependency 'pm' in public interface
98-
--> $DIR/pub-priv1.rs:96:9
99-
|
100-
LL | pub use pm::fn_like;
101-
| ^^^^^^^^^^^
102-
103-
error: `use` import `PmDerive` from private dependency 'pm' in public interface
104-
--> $DIR/pub-priv1.rs:98:9
105-
|
106-
LL | pub use pm::PmDerive;
107-
| ^^^^^^^^^^^^
108-
109-
error: `use` import `pm_attr` from private dependency 'pm' in public interface
110-
--> $DIR/pub-priv1.rs:100:9
111-
|
112-
LL | pub use pm::pm_attr;
113-
| ^^^^^^^^^^^
114-
115-
error: `use` import `V1` from private dependency 'priv_dep' in public interface
116-
--> $DIR/pub-priv1.rs:102:9
117-
|
118-
LL | pub use priv_dep::E::V1;
119-
| ^^^^^^^^^^^^^^^
120-
121-
error: `use` import `priv_dep` from private dependency 'priv_dep' in public interface
122-
--> $DIR/pub-priv1.rs:104:9
123-
|
124-
LL | pub use priv_dep::*;
125-
| ^^^^^^^^
126-
127-
error: aborting due to 20 previous errors
85+
error: aborting due to 13 previous errors
12886

0 commit comments

Comments
 (0)