Skip to content

Commit 126913d

Browse files
authored
Merge pull request #1759 from lzutao/unused-deps
Clean up dependency and code base
2 parents e2d6af0 + ffce617 commit 126913d

File tree

11 files changed

+120
-140
lines changed

11 files changed

+120
-140
lines changed

Cargo.lock

Lines changed: 22 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,26 @@ vendored-openssl = ['openssl/vendored']
2020
# Include in the default set to disable self-update and uninstall.
2121
no-self-update = []
2222

23+
# Sorted by alphabetic order
2324
[dependencies]
25+
clap = "2"
2426
dirs = "1"
2527
download = { path = "download" }
26-
clap = "2"
2728
error-chain = "0.12"
2829
flate2 = "1"
29-
itertools = "0.8"
30+
git-testament = "0.1.4"
31+
lazy_static = "1"
3032
libc = "0.2"
3133
markdown = "0.2"
32-
ole32-sys = "0.2"
34+
# Used by `curl` or `reqwest` backend although it isn't imported
35+
# by our rustup.
36+
openssl = { version = "0.10", optional = true }
3337
rand = "0.6"
3438
regex = "1"
3539
remove_dir_all = "0.5.1"
3640
same-file = "1"
37-
semver = "0.9"
3841
scopeguard = "1"
42+
semver = "0.9"
3943
sha2 = "0.8"
4044
tar = "0.4"
4145
tempdir = "0.3.4"
@@ -46,17 +50,11 @@ url = "1"
4650
wait-timeout = "0.2"
4751
walkdir = "2"
4852
xz2 = "0.1.3"
49-
openssl = { version = "0.10", optional = true }
50-
git-testament = "0.1.4"
51-
lazy_static = "1"
5253

5354
[target."cfg(windows)".dependencies]
55+
cc = "1"
5456
winapi = { version = "0.3", features = ["combaseapi", "errhandlingapi", "fileapi", "handleapi", "ioapiset", "jobapi", "jobapi2", "minwindef", "processthreadsapi", "psapi", "shlobj", "shtypes", "synchapi", "sysinfoapi", "tlhelp32", "userenv", "winbase", "winerror", "winioctl", "winnt", "winuser"] }
5557
winreg = "0.6"
56-
cc = "1"
57-
58-
[dev-dependencies]
59-
lazy_static = "1"
6058

6159
[workspace]
6260
members = ["download"]

src/cli/help.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub static RUSTUP_HELP: &'static str = r"DISCUSSION:
1+
pub static RUSTUP_HELP: &str = r"DISCUSSION:
22
rustup installs The Rust Programming Language from the official
33
release channels, enabling you to easily switch between stable,
44
beta, and nightly compilers and keep them updated. It makes
@@ -8,7 +8,7 @@ pub static RUSTUP_HELP: &'static str = r"DISCUSSION:
88
If you are new to Rust consider running `rustup doc --book` to
99
learn Rust.";
1010

11-
pub static SHOW_HELP: &'static str = r"DISCUSSION:
11+
pub static SHOW_HELP: &str = r"DISCUSSION:
1212
Shows the name of the active toolchain and the version of `rustc`.
1313
1414
If the active toolchain has installed support for additional
@@ -17,7 +17,7 @@ pub static SHOW_HELP: &'static str = r"DISCUSSION:
1717
If there are multiple toolchains installed then all installed
1818
toolchains are listed as well.";
1919

20-
pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
20+
pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &str = r"DISCUSSION:
2121
Shows the name of the active toolchain.
2222
2323
This is useful for figuring out the active tool chain from
@@ -26,24 +26,24 @@ pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
2626
You should use `rustc --print sysroot` to get the sysroot, or
2727
`rustc --version` to get the toolchain version.";
2828

29-
pub static UPDATE_HELP: &'static str = r"DISCUSSION:
29+
pub static UPDATE_HELP: &str = r"DISCUSSION:
3030
With no toolchain specified, the `update` command updates each of
3131
the installed toolchains from the official release channels, then
3232
updates rustup itself.
3333
3434
If given a toolchain argument then `update` updates that
3535
toolchain, the same as `rustup toolchain install`.";
3636

37-
pub static INSTALL_HELP: &'static str = r"DISCUSSION:
37+
pub static INSTALL_HELP: &str = r"DISCUSSION:
3838
Installs a specific rust toolchain.
3939
4040
The 'install' command is an alias for 'rustup update <toolchain>'.";
4141

42-
pub static DEFAULT_HELP: &'static str = r"DISCUSSION:
42+
pub static DEFAULT_HELP: &str = r"DISCUSSION:
4343
Sets the default toolchain to the one specified. If the toolchain
4444
is not already installed then it is installed first.";
4545

46-
pub static TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
46+
pub static TOOLCHAIN_HELP: &str = r"DISCUSSION:
4747
Many `rustup` commands deal with *toolchains*, a single
4848
installation of the Rust compiler. `rustup` supports multiple
4949
types of toolchains. The most basic track the official release
@@ -80,7 +80,7 @@ pub static TOOLCHAIN_HELP: &'static str = r"DISCUSSION:
8080
often used to for developing Rust itself. For more information see
8181
`rustup toolchain help link`.";
8282

83-
pub static TOOLCHAIN_LINK_HELP: &'static str = r"DISCUSSION:
83+
pub static TOOLCHAIN_LINK_HELP: &str = r"DISCUSSION:
8484
'toolchain' is the custom name to be assigned to the new toolchain.
8585
Any name is permitted as long as it does not fully match an initial
8686
substring of a standard release channel. For example, you can use
@@ -99,7 +99,7 @@ pub static TOOLCHAIN_LINK_HELP: &'static str = r"DISCUSSION:
9999
If you now compile a crate in the current directory, the custom
100100
toolchain 'latest-stage1' will be used.";
101101

102-
pub static OVERRIDE_HELP: &'static str = r"DISCUSSION:
102+
pub static OVERRIDE_HELP: &str = r"DISCUSSION:
103103
Overrides configure rustup to use a specific toolchain when
104104
running in a specific directory.
105105
@@ -120,14 +120,14 @@ pub static OVERRIDE_HELP: &'static str = r"DISCUSSION:
120120
override and use the default toolchain again, `rustup override
121121
unset`.";
122122

123-
pub static OVERRIDE_UNSET_HELP: &'static str = r"DISCUSSION:
123+
pub static OVERRIDE_UNSET_HELP: &str = r"DISCUSSION:
124124
If `--path` argument is present, removes the override toolchain
125125
for the specified directory. If `--nonexistent` argument is
126126
present, removes the override toolchain for all nonexistent
127127
directories. Otherwise, removes the override toolchain for the
128128
current directory.";
129129

130-
pub static RUN_HELP: &'static str = r"DISCUSSION:
130+
pub static RUN_HELP: &str = r"DISCUSSION:
131131
Configures an environment to use the given toolchain and then runs
132132
the specified program. The command may be any program, not just
133133
rustc or cargo. This can be used for testing arbitrary toolchains
@@ -142,14 +142,14 @@ pub static RUN_HELP: &'static str = r"DISCUSSION:
142142
143143
$ rustup run nightly cargo build";
144144

145-
pub static DOC_HELP: &'static str = r"DISCUSSION:
145+
pub static DOC_HELP: &str = r"DISCUSSION:
146146
Opens the documentation for the currently active toolchain with
147147
the default browser.
148148
149149
By default, it opens the documentation index. Use the various
150150
flags to open specific pieces of documentation.";
151151

152-
pub static COMPLETIONS_HELP: &'static str =
152+
pub static COMPLETIONS_HELP: &str =
153153
r"DISCUSSION:
154154
One can generate a completion script for `rustup` that is
155155
compatible with a given shell. The script is output on `stdout`
@@ -268,6 +268,6 @@ r"DISCUSSION:
268268
269269
$ rustup completions zsh cargo > ~/.zfunc/_cargo";
270270

271-
pub static TOOLCHAIN_ARG_HELP: &'static str = "Toolchain name, such as 'stable', 'nightly', \
272-
or '1.8.0'. For more information see `rustup \
273-
help toolchain`";
271+
pub static TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
272+
or '1.8.0'. For more information see `rustup \
273+
help toolchain`";

src/cli/main.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@ mod term2;
3030

3131
use crate::errors::*;
3232
use rustup::env_var::RUST_RECURSION_COUNT_MAX;
33-
use std::alloc::System;
3433
use std::env;
3534
use std::path::PathBuf;
3635

37-
// Always use the system allocator, to reduce binary size.
38-
#[global_allocator]
39-
static _ALLOCATOR: System = System;
40-
4136
fn main() {
4237
if let Err(ref e) = run_rustup() {
4338
common::report_error(e);

src/cli/self_update.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
use crate::common::{self, Confirm};
3434
use crate::errors::*;
3535
use crate::term2;
36-
use regex::Regex;
3736
use rustup::dist::dist;
3837
use rustup::utils::utils;
3938
use rustup::{DUP_TOOLS, TOOLS};
@@ -170,7 +169,7 @@ This will uninstall all Rust toolchains and data, and remove
170169
};
171170
}
172171

173-
static MSVC_MESSAGE: &'static str = r#"# Rust Visual C++ prerequisites
172+
static MSVC_MESSAGE: &str = r#"# Rust Visual C++ prerequisites
174173
175174
Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
176175
later, but they don't seem to be installed.
@@ -197,7 +196,7 @@ doing then it is fine to continue installation without the build
197196
tools, but otherwise, install the C++ build tools before proceeding.
198197
"#;
199198

200-
static UPDATE_ROOT: &'static str = "https://static.rust-lang.org/rustup";
199+
static UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";
201200

202201
/// `CARGO_HOME` suitable for display, possibly with $HOME
203202
/// substituted for the directory prefix
@@ -220,7 +219,7 @@ fn canonical_cargo_home() -> Result<String> {
220219
}
221220

222221
/// Installing is a simple matter of coping the running binary to
223-
/// `CARGO_HOME`/bin, hardlinking the various Rust tools to it,
222+
/// `CARGO_HOME`/bin, hard-linking the various Rust tools to it,
224223
/// and adding `CARGO_HOME`/bin to PATH.
225224
pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<()> {
226225
do_pre_install_sanity_checks()?;
@@ -465,7 +464,7 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
465464
libc::getpwuid_r(
466465
libc::geteuid(),
467466
&mut pwd,
468-
&mut buf as *mut [u8] as *mut i8,
467+
&mut buf as *mut [u8] as *mut libc::c_char,
469468
buf.len(),
470469
&mut pwdp,
471470
)
@@ -1379,8 +1378,14 @@ fn get_new_rustup_version(path: &Path) -> Option<String> {
13791378
}
13801379

13811380
fn parse_new_rustup_version(version: String) -> String {
1382-
let re = Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap();
1383-
let capture = re.captures(&version);
1381+
use lazy_static::lazy_static;
1382+
use regex::Regex;
1383+
1384+
lazy_static! {
1385+
static ref RE: Regex = Regex::new(r"\d+.\d+.\d+[0-9a-zA-Z-]*").unwrap();
1386+
}
1387+
1388+
let capture = RE.captures(&version);
13841389
let matched_version = match capture {
13851390
Some(cap) => cap.get(0).unwrap().as_str(),
13861391
None => "(unknown)",

src/dist/dist.rs

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ use crate::dist::temp;
88
use crate::errors::*;
99
use crate::utils::utils;
1010

11+
use lazy_static::lazy_static;
12+
use regex::Regex;
13+
1114
use std::env;
1215
use std::fmt;
1316
use std::path::Path;
1417

15-
use regex::Regex;
16-
17-
pub const DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org";
18+
pub static DEFAULT_DIST_SERVER: &str = "https://static.rust-lang.org";
1819

1920
// Deprecated
20-
pub const DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist";
21+
pub static DEFAULT_DIST_ROOT: &str = "https://static.rust-lang.org/dist";
2122

2223
// A toolchain descriptor from rustup's perspective. These contain
2324
// 'partial target triples', which allow toolchain names like
@@ -56,7 +57,7 @@ pub struct TargetTriple(String);
5657
// These lists contain the targets known to rustup, and used to build
5758
// the PartialTargetTriple.
5859

59-
static LIST_ARCHS: &'static [&'static str] = &[
60+
static LIST_ARCHS: &[&str] = &[
6061
"i386",
6162
"i586",
6263
"i686",
@@ -74,7 +75,7 @@ static LIST_ARCHS: &'static [&'static str] = &[
7475
"powerpc64le",
7576
"s390x",
7677
];
77-
static LIST_OSES: &'static [&'static str] = &[
78+
static LIST_OSES: &[&str] = &[
7879
"pc-windows",
7980
"unknown-linux",
8081
"apple-darwin",
@@ -84,7 +85,7 @@ static LIST_OSES: &'static [&'static str] = &[
8485
"rumprun-netbsd",
8586
"unknown-freebsd",
8687
];
87-
static LIST_ENVS: &'static [&'static str] = &[
88+
static LIST_ENVS: &[&str] = &[
8889
"gnu",
8990
"msvc",
9091
"gnueabi",
@@ -100,14 +101,14 @@ static LIST_ENVS: &'static [&'static str] = &[
100101
// Hence we could distinguish between the variants with compile-time cfg()
101102
// attributes alone.
102103
#[cfg(all(not(windows), target_endian = "big"))]
103-
const TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mips-unknown-linux-gnu";
104+
static TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mips-unknown-linux-gnu";
104105
#[cfg(all(not(windows), target_endian = "little"))]
105-
const TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mipsel-unknown-linux-gnu";
106+
static TRIPLE_MIPS_UNKNOWN_LINUX_GNU: &str = "mipsel-unknown-linux-gnu";
106107

107108
#[cfg(all(not(windows), target_endian = "big"))]
108-
const TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64-unknown-linux-gnuabi64";
109+
static TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64-unknown-linux-gnuabi64";
109110
#[cfg(all(not(windows), target_endian = "little"))]
110-
const TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64el-unknown-linux-gnuabi64";
111+
static TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64el-unknown-linux-gnuabi64";
111112

112113
impl TargetTriple {
113114
pub fn from_str(name: &str) -> Self {
@@ -223,15 +224,16 @@ impl PartialTargetTriple {
223224
// we can count on all triple components being
224225
// delineated by it.
225226
let name = format!("-{}", name);
226-
let pattern = format!(
227-
r"^(?:-({}))?(?:-({}))?(?:-({}))?$",
228-
LIST_ARCHS.join("|"),
229-
LIST_OSES.join("|"),
230-
LIST_ENVS.join("|")
231-
);
232-
233-
let re = Regex::new(&pattern).unwrap();
234-
re.captures(&name).map(|c| {
227+
lazy_static! {
228+
static ref PATTERN: String = format!(
229+
r"^(?:-({}))?(?:-({}))?(?:-({}))?$",
230+
LIST_ARCHS.join("|"),
231+
LIST_OSES.join("|"),
232+
LIST_ENVS.join("|")
233+
);
234+
static ref RE: Regex = Regex::new(&PATTERN).unwrap();
235+
}
236+
RE.captures(&name).map(|c| {
235237
fn fn_map(s: &str) -> Option<String> {
236238
if s == "" {
237239
None
@@ -251,21 +253,22 @@ impl PartialTargetTriple {
251253

252254
impl PartialToolchainDesc {
253255
pub fn from_str(name: &str) -> Result<Self> {
254-
let channels = [
256+
static CHANNELS: &[&str] = &[
255257
"nightly",
256258
"beta",
257259
"stable",
258260
r"\d{1}\.\d{1}\.\d{1}",
259261
r"\d{1}\.\d{2}\.\d{1}",
260262
];
261263

262-
let pattern = format!(
263-
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.*))?$",
264-
channels.join("|")
265-
);
266-
267-
let re = Regex::new(&pattern).unwrap();
268-
let d = re.captures(name).map(|c| {
264+
lazy_static! {
265+
static ref PATTERN: String = format!(
266+
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?(?:-(.*))?$",
267+
CHANNELS.join("|")
268+
);
269+
static ref RE: Regex = Regex::new(&PATTERN).unwrap();
270+
}
271+
let d = RE.captures(name).map(|c| {
269272
fn fn_map(s: &str) -> Option<String> {
270273
if s == "" {
271274
None
@@ -341,21 +344,23 @@ impl PartialToolchainDesc {
341344

342345
impl ToolchainDesc {
343346
pub fn from_str(name: &str) -> Result<Self> {
344-
let channels = [
347+
static CHANNELS: &[&str] = &[
345348
"nightly",
346349
"beta",
347350
"stable",
348351
r"\d{1}\.\d{1}\.\d{1}",
349352
r"\d{1}\.\d{2}\.\d{1}",
350353
];
351354

352-
let pattern = format!(
353-
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?-(.*)?$",
354-
channels.join("|"),
355-
);
355+
lazy_static! {
356+
static ref PATTERN: String = format!(
357+
r"^({})(?:-(\d{{4}}-\d{{2}}-\d{{2}}))?-(.*)?$",
358+
CHANNELS.join("|"),
359+
);
360+
static ref RE: Regex = Regex::new(&PATTERN).unwrap();
361+
}
356362

357-
let re = Regex::new(&pattern).unwrap();
358-
re.captures(name)
363+
RE.captures(name)
359364
.map(|c| {
360365
fn fn_map(s: &str) -> Option<String> {
361366
if s == "" {

0 commit comments

Comments
 (0)