-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
532bb60
Use `pub(crate)` instead of `pub` where possible in librustc_* crates
petrochenkov dc6b8ed
Remove dead code
petrochenkov 68d442d
Use `$vis` in `declare_lint`
petrochenkov dcc5c7c
Remove `pub(crate)` in crate roots
petrochenkov b9b1013
Fix tidy and formatting
petrochenkov 8898cdb
Address more comments
petrochenkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,8 @@ | |
//! | ||
//! A simple wrapper over the platform's dynamic library facilities | ||
|
||
use std::env; | ||
use std::ffi::{CString, OsString}; | ||
use std::path::{Path, PathBuf}; | ||
use std::ffi::CString; | ||
use std::path::Path; | ||
|
||
pub struct DynamicLibrary { | ||
handle: *mut u8 | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Looks like no, but CI should catch if I missed anything. |
||
let mut search_path = DynamicLibrary::search_path(); | ||
search_path.insert(0, path.to_path_buf()); | ||
env::set_var(DynamicLibrary::envvar(), &DynamicLibrary::create_path(&search_path)); | ||
} | ||
|
||
/// From a slice of paths, create a new vector which is suitable to be an | ||
/// environment variable for this platforms dylib search path. | ||
pub fn create_path(path: &[PathBuf]) -> OsString { | ||
let mut newvar = OsString::new(); | ||
for (i, path) in path.iter().enumerate() { | ||
if i > 0 { newvar.push(DynamicLibrary::separator()); } | ||
newvar.push(path); | ||
} | ||
return newvar; | ||
} | ||
|
||
/// Returns the environment variable for this process's dynamic library | ||
/// search path | ||
pub fn envvar() -> &'static str { | ||
|
@@ -75,19 +56,6 @@ impl DynamicLibrary { | |
} | ||
} | ||
|
||
fn separator() -> &'static str { | ||
if cfg!(windows) { ";" } else { ":" } | ||
} | ||
|
||
/// Returns the current search path for dynamic libraries being used by this | ||
/// process | ||
pub fn search_path() -> Vec<PathBuf> { | ||
match env::var_os(DynamicLibrary::envvar()) { | ||
Some(var) => env::split_paths(&var).collect(), | ||
None => Vec::new(), | ||
} | ||
} | ||
|
||
/// Accesses the value at the symbol of the dynamic library. | ||
pub unsafe fn symbol<T>(&self, symbol: &str) -> Result<*mut T, String> { | ||
// This function should have a lifetime constraint of 'a on | ||
|
@@ -166,7 +134,7 @@ mod dl { | |
use std::ptr; | ||
use std::str; | ||
|
||
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { | ||
pub(crate) fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { | ||
check_for_errors_in(|| { | ||
unsafe { | ||
match filename { | ||
|
@@ -188,7 +156,7 @@ mod dl { | |
libc::dlopen(ptr::null(), LAZY) as *mut u8 | ||
} | ||
|
||
pub fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where | ||
pub(crate) fn check_for_errors_in<T, F>(f: F) -> Result<T, String> where | ||
F: FnOnce() -> T, | ||
{ | ||
use std::sync::{Mutex, Once, ONCE_INIT}; | ||
|
@@ -217,14 +185,14 @@ mod dl { | |
} | ||
} | ||
|
||
pub unsafe fn symbol(handle: *mut u8, | ||
symbol: *const libc::c_char) | ||
-> Result<*mut u8, String> { | ||
pub(crate) unsafe fn symbol(handle: *mut u8, | ||
symbol: *const libc::c_char) | ||
-> Result<*mut u8, String> { | ||
check_for_errors_in(|| { | ||
libc::dlsym(handle as *mut libc::c_void, symbol) as *mut u8 | ||
}) | ||
} | ||
pub unsafe fn close(handle: *mut u8) { | ||
pub(crate) unsafe fn close(handle: *mut u8) { | ||
libc::dlclose(handle as *mut libc::c_void); () | ||
} | ||
} | ||
|
@@ -256,7 +224,7 @@ mod dl { | |
fn FreeLibrary(handle: HMODULE) -> BOOL; | ||
} | ||
|
||
pub fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { | ||
pub(crate) fn open(filename: Option<&OsStr>) -> Result<*mut u8, String> { | ||
// disable "dll load failed" error dialog. | ||
let prev_error_mode = unsafe { | ||
// SEM_FAILCRITICALERRORS 0x01 | ||
|
@@ -299,14 +267,14 @@ mod dl { | |
result | ||
} | ||
|
||
pub unsafe fn symbol(handle: *mut u8, | ||
pub(crate) unsafe fn symbol(handle: *mut u8, | ||
symbol: *const c_char) | ||
-> Result<*mut u8, String> { | ||
let ptr = GetProcAddress(handle as HMODULE, symbol) as *mut u8; | ||
ptr_result(ptr) | ||
} | ||
|
||
pub unsafe fn close(handle: *mut u8) { | ||
pub(crate) unsafe fn close(handle: *mut u8) { | ||
FreeLibrary(handle as HMODULE); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.