-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
librustc_*: Use pub(crate)
instead of pub
and remove dead code
#43192
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc/lint/mod.rs
Outdated
(pub(crate) $name:ident, $level:ident, $desc:expr) => ( | ||
pub(crate) static $name: &'static ::rustc::lint::Lint | ||
= &lint_initializer!($name, $level, $desc); | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use :vis
to combine all 3 arms here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, it requires #![feature(macro_vis_matcher)]
in all crates where the macro containing it is used, including tests.
pub(crate)
instead of pub
and remove dead codepub(crate)
instead of pub
and remove dead code
@@ -43,24 +42,6 @@ impl DynamicLibrary { | |||
} | |||
} | |||
|
|||
/// Prepends a path to this process's search path for dynamic libraries | |||
pub fn prepend_search_path(path: &Path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance a bunch of these are used on only some host OSes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like no, but CI should catch if I missed anything.
We'd be lucky if something like that does not break Clippy. Cc @Manishearth, @llogiq, @oli-obk |
This is great! Would you be so kind and also test whether clippy and miri keep building and adjust your PR accordingly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a pass over rustc_data_structures
.
@@ -23,13 +23,6 @@ impl BitVector { | |||
BitVector { data: vec![0; num_words] } | |||
} | |||
|
|||
#[inline] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this one.
@@ -70,29 +70,29 @@ impl<A> Clone for ArrayVec<A> | |||
} | |||
|
|||
impl<A: Array> ArrayVec<A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to keep this type publicly available.
@@ -43,29 +43,25 @@ impl<A> Clone for AccumulateVec<A> | |||
} | |||
|
|||
impl<A: Array> AccumulateVec<A> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep these pub
.
@@ -13,7 +13,7 @@ | |||
|
|||
use std::str; | |||
|
|||
pub const MAX_BASE: u64 = 64; | |||
pub(crate) const MAX_BASE: u64 = 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this pub
.
@@ -66,7 +60,7 @@ impl BitVector { | |||
} | |||
|
|||
#[inline] | |||
pub fn grow(&mut self, num_bits: usize) { | |||
pub(crate) fn grow(&mut self, num_bits: usize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep pub
.
@@ -81,7 +81,7 @@ impl<A: Array> SmallVec<A> { | |||
} | |||
} | |||
|
|||
pub fn reserve(&mut self, n: usize) { | |||
pub(crate) fn reserve(&mut self, n: usize) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep pub
.
@@ -76,7 +76,7 @@ impl<D: SnapshotVecDelegate> SnapshotVec<D> { | |||
} | |||
} | |||
|
|||
pub fn len(&self) -> usize { | |||
pub(crate) fn len(&self) -> usize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep pub
.
@@ -98,13 +98,13 @@ impl<D: SnapshotVecDelegate> SnapshotVec<D> { | |||
/// Returns a mutable pointer into the vec; whatever changes you make here cannot be undone | |||
/// automatically, so you should be sure call `record()` with some sort of suitable undo | |||
/// action. | |||
pub fn get_mut(&mut self, index: usize) -> &mut D::Value { | |||
pub(crate) fn get_mut(&mut self, index: usize) -> &mut D::Value { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep pub
.
&mut self.values[index] | ||
} | ||
|
||
/// Updates the element at the given index. The old value will saved (and perhaps restored) if | ||
/// a snapshot is active. | ||
pub fn set(&mut self, index: usize, new_elem: D::Value) { | ||
pub(crate) fn set(&mut self, index: usize, new_elem: D::Value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep pub
.
@@ -1,70 +0,0 @@ | |||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still seems like a useful type to have.
Thanks! |
265ae78
to
55694ca
Compare
Updated, comments addresses. |
}, | ||
]; | ||
|
||
pub struct AllocatorMethod { | ||
pub name: &'static str, | ||
pub inputs: &'static [AllocatorTy], | ||
pub output: AllocatorTy, | ||
pub is_unsafe: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_unsafe
being unused looks like a bug. It should be used in expansion, but it's ignored and all methods are expanded as unsafe.
@alexcrichton, is this intentional or just an omission?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes historically used but no longer used! Should be safe to remove.
9b1c051
to
9153114
Compare
I think these changes look good. I am sad to see some of the code go (e.g., useful algorithms on graphs etc), but I think that it's best to kill dead code. Those bits are still around in the git history if we ever want them. (In any case, I suspect we should start moving the |
ping r? @eddyb |
@@ -598,12 +598,3 @@ impl Level { | |||
} | |||
} | |||
} | |||
|
|||
pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good riddance! 🎉
@@ -19,7 +19,7 @@ use IntrinsicDef::Named; | |||
// The default inlining settings trigger a pathological behaviour in | |||
// LLVM, which causes makes compilation very slow. See #28273. | |||
#[inline(never)] | |||
pub fn find(name: &str) -> Option<Intrinsic> { | |||
pub(crate) fn find(name: &str) -> Option<Intrinsic> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the generator for these updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in the latest commit.
src/librustc_privacy/lib.rs
Outdated
@@ -156,7 +156,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { | |||
hir::ItemForeignMod(..) => { | |||
self.prev_level | |||
} | |||
// Other `pub` items inherit levels from parents | |||
// Other `pub(crate)` items inherit levels from parents |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? Seems a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, I fixed several similar cases, but haven't seen this one.
I grepped a bit harder and found a few more, fixed in the last commit.
src/librustc_typeck/diagnostics.rs
Outdated
You can read more about trait objects in the [Trait Objects] section of the | ||
Reference. | ||
You can read more about trait objects in the Trait Object section of the | ||
Reference: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file some sort of rebase failure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went through the entire diff and left some comments. Not that worried about deletions, because of git history, but some of the changes seemed unintentional.
src/librustc_save_analysis/lib.rs
Outdated
@@ -78,15 +78,13 @@ pub struct SaveContext<'l, 'tcx: 'l> { | |||
} | |||
|
|||
#[derive(Debug)] | |||
pub enum Data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These Data
structures should all be pub
still, they are expected to be used by clients
src/librustc_save_analysis/lib.rs
Outdated
RefData(Ref), | ||
DefData(Def), | ||
RelationData(Relation), | ||
} | ||
|
||
pub trait Dump { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LIkewsie this trait and the functions below are API and should still be public
src/librustc_driver/driver.rs
Outdated
pub after_hir_lowering: PhaseController<'a>, | ||
pub after_analysis: PhaseController<'a>, | ||
pub after_llvm: PhaseController<'a>, | ||
pub compilation_done: PhaseController<'a>, | ||
pub(crate) compilation_done: PhaseController<'a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These fields should still be pub
src/librustc_driver/driver.rs
Outdated
@@ -273,7 +271,7 @@ pub fn anon_src() -> String { | |||
"<anon>".to_string() | |||
} | |||
|
|||
pub fn source_name(input: &Input) -> String { | |||
pub(crate) fn source_name(input: &Input) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be pub
still
src/librustc_driver/driver.rs
Outdated
@@ -329,7 +327,7 @@ pub struct PhaseController<'a> { | |||
} | |||
|
|||
impl<'a> PhaseController<'a> { | |||
pub fn basic() -> PhaseController<'a> { | |||
pub(crate) fn basic() -> PhaseController<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these changes from here on down are bogus and should still be pub.
src/librustc_driver/lib.rs
Outdated
@@ -273,7 +273,7 @@ pub enum Compilation { | |||
} | |||
|
|||
impl Compilation { | |||
pub fn and_then<F: FnOnce() -> Compilation>(self, next: F) -> Compilation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub
src/librustc_driver/lib.rs
Outdated
@@ -617,7 +617,7 @@ fn save_analysis_format(sess: &Session) -> save::Format { | |||
} | |||
|
|||
impl RustcDefaultCalls { | |||
pub fn list_metadata(sess: &Session, matches: &getopts::Matches, input: &Input) -> Compilation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub
src/librustc_driver/lib.rs
Outdated
@@ -1016,7 +1016,7 @@ fn print_flag_list<T>(cmdline_opt: &str, | |||
/// | |||
/// So with all that in mind, the comments below have some more detail about the | |||
/// contortions done here to get things to work out correctly. | |||
pub fn handle_options(args: &[String]) -> Option<getopts::Matches> { | |||
fn handle_options(args: &[String]) -> Option<getopts::Matches> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub
src/librustc_driver/lib.rs
Outdated
@@ -1200,7 +1200,7 @@ fn exit_on_err() -> ! { | |||
panic!(); | |||
} | |||
|
|||
pub fn diagnostics_registry() -> errors::registry::Registry { | |||
fn diagnostics_registry() -> errors::registry::Registry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub
src/librustc_errors/diagnostic.rs
Outdated
@@ -20,7 +20,7 @@ use snippet::Style; | |||
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)] | |||
pub struct Diagnostic { | |||
pub level: Level, | |||
pub message: Vec<(String, Style)>, | |||
pub(crate) message: Vec<(String, Style)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty much everything here should be pub
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where 'here' = all of the _errors crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made all the interface of Diagnostic
public, but kept stuff in other modules containing implementation details crate-private.
I think that any change from pub -> pub(crate) in a non-public module is just noise (both in the git history and the source code). I think I'm generally a bit sad about how much noisier this is making the code, even if the tighter encapsulation and dead code removal have benefits. |
☔ The latest upstream changes (presumably #43183) made this pull request unmergeable. Please resolve the merge conflicts. |
Revert some `pub(crate)`s to `pub`s to make sure Miri and Clippy work Revert some `pub(crate)`s to `pub`s to address Michael Woerister's comments
Rebased, comments addressed. |
Interesting, this was kinda the point for me. |
pub(crate)
instead of pub
and remove dead codepub(crate)
instead of pub
and remove dead code
☔ The latest upstream changes (presumably #43387) made this pull request unmergeable. Please resolve the merge conflicts. |
This is pretty much a weakness in Rust's privacy system (and one the lang team has been debating recently). Does the privacy annotation on an item mean that item is 'at most' this public or 'at least' this public? Using Given that this is only helpful for crate-level encapsulation and it is so noisey, I'd prefer not to do it. |
At least with |
The primary benefit from |
This probably needs some collective decision from people working on these crates.
|
I think the dead code removal is certainly worth landing. I would prefer not to land the rest, however, I don't work much on the crates which are mostly affected so if others want the changes, I won't object. |
This annoys me too, btw. |
@petrochenkov looks like this needs a rebase!
Who are you referring to here? i.e. is this with a rust team to come to a decision? |
@aidanhs @rfcbot fcp merge Questions:
|
@rfcbot fcp merge |
Team member @eddyb has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Too much bit rot and not enough interest, closing. |
This PR does the next things:
pub
s inlibrustc*
crates (except forlibrustc
itself) withpub(crate)
s.x.py test
from passing and RLS/Miri/Clippy from building.The changes are 99% mechanical. I didn't judge and (semi-automatically) removed everything the compiler told me. Now this needs to be reviewed and some false positives need to be reverted (either for interface completeness or because they are needed by some third party tools).
EDIT: Changes mentioned in review comments are reverted.
cc @nikomatsakis and @michaelwoerister for
rustc_data_structures
cc @nrc for
librustc_driver
APIs and toolscc @rust-lang/compiler for everything else, if you see something that should be kept please leave a comment!
Next steps after reviewing:
pub(crate)
with nothing in crate roots.