Skip to content

fix: Implement missing logics in exported_private_dependencies lint #134176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove detection of private dependency leaks for use and extern f…
…rom `rustc_privacy`
  • Loading branch information
ShoyuVanilla committed Feb 25, 2025
commit 73b15e48ab3218baa4024c25e1292ac010e2d9a4
27 changes: 0 additions & 27 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,33 +1789,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
}
}
}
DefKind::Use => {
let item = tcx.hir_item(id);
if let hir::ItemKind::Use(path, use_kind) = item.kind
// List imports are desugared as single ones so skip `ListStem`s
&& use_kind != rustc_hir::UseKind::ListStem
{
if let Some(def_id) = path.res.iter().filter_map(Res::opt_def_id).last() {
// normally, public items in a private modules can be re-exported but this should be linted for
// leakages of a private dependencies
self.check_private_dep_leaks_only(item.owner_id.def_id, item_visibility)
.check_def_id(
def_id,
item.kind.descr(),
&LazyDefPathStr { def_id, tcx },
);
}
}
}
DefKind::ExternCrate => {
let item = tcx.hir_item(id);
if let Some(cnum) = tcx.extern_mod_stmt_cnum(item.owner_id.def_id) {
let def_id = cnum.as_def_id();
// `pub extern some_dep` should be linted if and only if `some_dep` is a private dependency
self.check_private_dep_leaks_only(item.owner_id.def_id, item_visibility)
.visit_def_id(def_id, item.kind.descr(), &LazyDefPathStr { def_id, tcx });
}
}
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hashbrown = { version = "0.15", default-features = false, features = [
] }
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = [
'rustc-dep-of-std',
], public = true }
] }

# Dependencies of the `backtrace` crate
rustc-demangle = { version = "0.1.24", features = ['rustc-dep-of-std'] }
Expand Down
15 changes: 8 additions & 7 deletions tests/ui/privacy/pub-priv-dep/pub-priv1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#![allow(hidden_glob_reexports)]

// This crate is a private dependency
// FIXME: This should trigger.
pub extern crate priv_dep;
//~^ ERROR extern crate `priv_dep` from private dependency 'priv_dep' in public interface
// This crate is a public dependency
extern crate pub_dep;
// This crate is a private dependency
Expand Down Expand Up @@ -91,17 +91,18 @@ pub struct AllowedPrivType {
pub allowed: OtherType,
}

// FIXME: This should trigger.
pub use priv_dep::m;
//~^ ERROR `use` import `m` from private dependency 'priv_dep' in public interface
// FIXME: This should trigger.
pub use pm::fn_like;
//~^ ERROR `use` import `fn_like` from private dependency 'pm' in public interface
// FIXME: This should trigger.
pub use pm::PmDerive;
//~^ ERROR `use` import `PmDerive` from private dependency 'pm' in public interface
// FIXME: This should trigger.
pub use pm::pm_attr;
//~^ ERROR `use` import `pm_attr` from private dependency 'pm' in public interface

// FIXME: This should trigger.
pub use priv_dep::E::V1;
//~^ ERROR `use` import `V1` from private dependency 'priv_dep' in public interface
// FIXME: This should trigger.
pub use priv_dep::*;
//~^ ERROR `use` import `priv_dep` from private dependency 'priv_dep' in public interface

fn main() {}
52 changes: 5 additions & 47 deletions tests/ui/privacy/pub-priv-dep/pub-priv1.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
error: extern crate `priv_dep` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:13:1
error: type `OtherType` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:30:5
|
LL | pub extern crate priv_dep;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL | pub field: OtherType,
| ^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/pub-priv1.rs:9:9
|
LL | #![deny(exported_private_dependencies)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: type `OtherType` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:30:5
|
LL | pub field: OtherType,
| ^^^^^^^^^^^^^^^^^^^^

error: type `OtherType` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:37:5
|
Expand Down Expand Up @@ -88,41 +82,5 @@ error: type `OtherType` from private dependency 'priv_dep' in public interface
LL | impl PubTraitOnPrivate for OtherType {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `use` import `m` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:94:9
|
LL | pub use priv_dep::m;
| ^^^^^^^^^^^

error: `use` import `fn_like` from private dependency 'pm' in public interface
--> $DIR/pub-priv1.rs:96:9
|
LL | pub use pm::fn_like;
| ^^^^^^^^^^^

error: `use` import `PmDerive` from private dependency 'pm' in public interface
--> $DIR/pub-priv1.rs:98:9
|
LL | pub use pm::PmDerive;
| ^^^^^^^^^^^^

error: `use` import `pm_attr` from private dependency 'pm' in public interface
--> $DIR/pub-priv1.rs:100:9
|
LL | pub use pm::pm_attr;
| ^^^^^^^^^^^

error: `use` import `V1` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:102:9
|
LL | pub use priv_dep::E::V1;
| ^^^^^^^^^^^^^^^

error: `use` import `priv_dep` from private dependency 'priv_dep' in public interface
--> $DIR/pub-priv1.rs:104:9
|
LL | pub use priv_dep::*;
| ^^^^^^^^

error: aborting due to 20 previous errors
error: aborting due to 13 previous errors

Loading