Skip to content
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
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/etc/platform-intrinsics/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def open(platform):
// 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> {{
if !name.starts_with("{0}") {{ return None }}
Some(match &name["{0}".len()..] {{'''.format(platform.platform_prefix())

Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#![feature(discriminant_value)]
#![feature(i128_type)]
#![feature(libc)]
#![feature(macro_vis_matcher)]
#![feature(never_type)]
#![feature(nonzero)]
#![feature(quote)]
Expand Down
11 changes: 3 additions & 8 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,9 @@ macro_rules! lint_initializer {
/// Declare a static item of type `&'static Lint`.
#[macro_export]
macro_rules! declare_lint {
(pub $name:ident, $level:ident, $desc:expr) => (
pub static $name: &'static ::rustc::lint::Lint
= &lint_initializer!($name, $level, $desc);
);
($name:ident, $level:ident, $desc:expr) => (
static $name: &'static ::rustc::lint::Lint
= &lint_initializer!($name, $level, $desc);
);
($vis: vis $name: ident, $level: ident, $desc: expr) => {
$vis static $name: &$crate::lint::Lint = &lint_initializer!($name, $level, $desc);
}
}

/// Declare a static `LintArray` and return it as an expression.
Expand Down
13 changes: 2 additions & 11 deletions src/librustc_allocator/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(warnings)]

#![feature(rustc_private)]

extern crate rustc;
Expand All @@ -22,69 +24,58 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
name: "alloc",
inputs: &[AllocatorTy::Layout],
output: AllocatorTy::ResultPtr,
is_unsafe: true,
},
AllocatorMethod {
name: "oom",
inputs: &[AllocatorTy::AllocErr],
output: AllocatorTy::Bang,
is_unsafe: false,
},
AllocatorMethod {
name: "dealloc",
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout],
output: AllocatorTy::Unit,
is_unsafe: true,
},
AllocatorMethod {
name: "usable_size",
inputs: &[AllocatorTy::LayoutRef],
output: AllocatorTy::UsizePair,
is_unsafe: false,
},
AllocatorMethod {
name: "realloc",
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Layout],
output: AllocatorTy::ResultPtr,
is_unsafe: true,
},
AllocatorMethod {
name: "alloc_zeroed",
inputs: &[AllocatorTy::Layout],
output: AllocatorTy::ResultPtr,
is_unsafe: true,
},
AllocatorMethod {
name: "alloc_excess",
inputs: &[AllocatorTy::Layout],
output: AllocatorTy::ResultExcess,
is_unsafe: true,
},
AllocatorMethod {
name: "realloc_excess",
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Layout],
output: AllocatorTy::ResultExcess,
is_unsafe: true,
},
AllocatorMethod {
name: "grow_in_place",
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Layout],
output: AllocatorTy::ResultUnit,
is_unsafe: true,
},
AllocatorMethod {
name: "shrink_in_place",
inputs: &[AllocatorTy::Ptr, AllocatorTy::Layout, AllocatorTy::Layout],
output: AllocatorTy::ResultUnit,
is_unsafe: true,
},
];

pub struct AllocatorMethod {
pub name: &'static str,
pub inputs: &'static [AllocatorTy],
pub output: AllocatorTy,
pub is_unsafe: bool,
Copy link
Contributor Author

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?

Copy link
Member

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.

}

pub enum AllocatorTy {
Expand Down
54 changes: 11 additions & 43 deletions src/librustc_back/dynamic_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Copy link
Member

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?

Copy link
Contributor Author

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.

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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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};
Expand Down Expand Up @@ -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); ()
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_apple_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};
use super::apple_ios_base::{opts, Arch};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let base = opts(Arch::Arm64)?;
Ok(Target {
llvm_target: "arm64-apple-ios".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use target::{Target, TargetOptions, TargetResult};
// See https://developer.android.com/ndk/guides/abis.html#arm64-v8a
// for target ABI requirements.

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::android_base::opts();
base.max_atomic_width = Some(128);
// As documented in http://developer.android.com/ndk/guides/cpu-features.html
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_unknown_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::freebsd_base::opts();
base.max_atomic_width = Some(128);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_unknown_fuchsia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::fuchsia_base::opts();
base.max_atomic_width = Some(128);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/aarch64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = Some(128);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/android_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::TargetOptions;

pub fn opts() -> TargetOptions {
pub(crate) fn opts() -> TargetOptions {
let mut base = super::linux_base::opts();
// Many of the symbols defined in compiler-rt are also defined in libgcc.
// Android's linker doesn't like that by default.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::env;

use target::{LinkArgs, TargetOptions};

pub fn opts() -> TargetOptions {
pub(crate) fn opts() -> TargetOptions {
// ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6
// either the linker will complain if it is used or the binary will end up
// segfaulting at runtime when run on 10.6. Rust by default supports macOS
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_back/target/apple_ios_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use self::Arch::*;

#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub enum Arch {
pub(crate) enum Arch {
Armv7,
Armv7s,
Arm64,
Expand All @@ -26,7 +26,7 @@ pub enum Arch {
}

impl Arch {
pub fn to_string(&self) -> &'static str {
pub(crate) fn to_string(&self) -> &'static str {
match self {
&Armv7 => "armv7",
&Armv7s => "armv7s",
Expand All @@ -37,7 +37,7 @@ impl Arch {
}
}

pub fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
pub(crate) fn get_sdk_root(sdk_name: &str) -> Result<String, String> {
let res = Command::new("xcrun")
.arg("--show-sdk-path")
.arg("-sdk")
Expand Down Expand Up @@ -91,7 +91,7 @@ fn target_cpu(arch: Arch) -> String {
}.to_string()
}

pub fn opts(arch: Arch) -> Result<TargetOptions, String> {
pub(crate) fn opts(arch: Arch) -> Result<TargetOptions, String> {
let pre_link_args = build_pre_link_args(arch)?;
Ok(TargetOptions {
cpu: target_cpu(arch),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/arm_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
use syntax::abi::Abi;

// All the calling conventions trigger an assertion(Unsupported calling convention) in llvm on arm
pub fn abi_blacklist() -> Vec<Abi> {
pub(crate) fn abi_blacklist() -> Vec<Abi> {
vec![Abi::Stdcall, Abi::Fastcall, Abi::Vectorcall, Abi::Thiscall, Abi::Win64, Abi::SysV64]
}
2 changes: 1 addition & 1 deletion src/librustc_back/target/arm_linux_androideabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::android_base::opts();
// https://developer.android.com/ndk/guides/abis.html#armeabi
base.features = "+v5te".to_string();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/arm_unknown_linux_gnueabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = Some(64);
Ok(Target {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/arm_unknown_linux_gnueabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::linux_base::opts();
base.max_atomic_width = Some(64);
Ok(Target {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/arm_unknown_linux_musleabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::linux_musl_base::opts();

// Most of these settings are copied from the arm_unknown_linux_gnueabi
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/arm_unknown_linux_musleabihf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let mut base = super::linux_musl_base::opts();

// Most of these settings are copied from the arm_unknown_linux_gnueabihf
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_back/target/armv5te_unknown_linux_gnueabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use LinkerFlavor;
use target::{Target, TargetOptions, TargetResult};

pub fn target() -> TargetResult {
pub(crate) fn target() -> TargetResult {
let base = super::linux_base::opts();
Ok(Target {
llvm_target: "armv5te-unknown-linux-gnueabi".to_string(),
Expand Down
Loading