Skip to content

Commit e4221e8

Browse files
committed
clippy: Enable warning when not using Self on applicable
1 parent dca911b commit e4221e8

13 files changed

+39
-38
lines changed

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl Cfg {
9595
);
9696
let dist_root = dist_root_server.clone() + "/dist";
9797

98-
let cfg = Cfg {
98+
let cfg = Self {
9999
rustup_dir,
100100
settings_file,
101101
toolchains_dir,

src/diskio/immediate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use super::{perform, Executor, Item};
77
#[derive(Default)]
88
pub struct ImmediateUnpacker {}
99
impl ImmediateUnpacker {
10-
pub fn new() -> ImmediateUnpacker {
11-
ImmediateUnpacker {}
10+
pub fn new() -> Self {
11+
Self {}
1212
}
1313
}
1414

src/diskio/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub struct Item {
8989

9090
impl Item {
9191
pub fn make_dir(full_path: PathBuf, mode: u32) -> Self {
92-
Item {
92+
Self {
9393
full_path,
9494
kind: Kind::Directory,
9595
start: 0.0,
@@ -102,7 +102,7 @@ impl Item {
102102

103103
pub fn write_file(full_path: PathBuf, content: Vec<u8>, mode: u32) -> Self {
104104
let len = content.len();
105-
Item {
105+
Self {
106106
full_path,
107107
kind: Kind::File(content),
108108
start: 0.0,

src/dist/component/components.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Components {
2020

2121
impl Components {
2222
pub fn open(prefix: InstallPrefix) -> Result<Self> {
23-
let c = Components { prefix };
23+
let c = Self { prefix };
2424

2525
// Validate that the metadata uses a format we know
2626
if let Some(v) = c.read_version()? {
@@ -152,7 +152,7 @@ impl ComponentPart {
152152
}
153153
pub fn decode(line: &str) -> Option<Self> {
154154
line.find(':')
155-
.map(|pos| ComponentPart(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
155+
.map(|pos| Self(line[0..pos].to_owned(), PathBuf::from(&line[(pos + 1)..])))
156156
}
157157
}
158158

src/dist/component/package.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl DirectoryPackage {
5252
.lines()
5353
.map(std::borrow::ToOwned::to_owned)
5454
.collect();
55-
Ok(DirectoryPackage {
55+
Ok(Self {
5656
path,
5757
components,
5858
copy,
@@ -165,7 +165,7 @@ struct MemoryBudget {
165165

166166
// Probably this should live in diskio but ¯\_(ツ)_/¯
167167
impl MemoryBudget {
168-
fn new(max_file_size: usize) -> MemoryBudget {
168+
fn new(max_file_size: usize) -> Self {
169169
const DEFAULT_UNPACK_RAM: usize = 400 * 1024 * 1024;
170170
let unpack_ram = if let Ok(budget_str) = env::var("RUSTUP_UNPACK_RAM") {
171171
if let Ok(budget) = budget_str.parse::<usize>() {
@@ -179,7 +179,7 @@ impl MemoryBudget {
179179
if max_file_size > unpack_ram {
180180
panic!("RUSTUP_UNPACK_RAM must be larger than {}", max_file_size);
181181
}
182-
MemoryBudget {
182+
Self {
183183
limit: unpack_ram,
184184
used: 0,
185185
}

src/dist/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl Config {
2222
let components =
2323
Self::toml_to_components(components, &format!("{}{}.", path, "components"))?;
2424

25-
Ok(Config {
25+
Ok(Self {
2626
config_version: version,
2727
components,
2828
})
@@ -77,7 +77,7 @@ impl Config {
7777

7878
impl Default for Config {
7979
fn default() -> Self {
80-
Config {
80+
Self {
8181
config_version: DEFAULT_CONFIG_VERSION.to_owned(),
8282
components: Vec::new(),
8383
}

src/dist/dist.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ static TRIPLE_MIPS64_UNKNOWN_LINUX_GNUABI64: &str = "mips64el-unknown-linux-gnua
120120

121121
impl TargetTriple {
122122
pub fn new(name: &str) -> Self {
123-
TargetTriple(name.to_string())
123+
Self(name.to_string())
124124
}
125125

126126
pub fn from_build() -> Self {
127127
if let Some(triple) = option_env!("RUSTUP_OVERRIDE_BUILD_TRIPLE") {
128-
TargetTriple::new(triple)
128+
Self::new(triple)
129129
} else {
130-
TargetTriple::new(env!("TARGET"))
130+
Self::new(env!("TARGET"))
131131
}
132132
}
133133

@@ -207,7 +207,7 @@ impl TargetTriple {
207207
}
208208

209209
if let Ok(triple) = env::var("RUSTUP_OVERRIDE_HOST_TRIPLE") {
210-
Some(TargetTriple(triple))
210+
Some(Self(triple))
211211
} else {
212212
inner()
213213
}
@@ -221,7 +221,7 @@ impl TargetTriple {
221221
impl PartialTargetTriple {
222222
pub fn new(name: &str) -> Option<Self> {
223223
if name.is_empty() {
224-
return Some(PartialTargetTriple {
224+
return Some(Self {
225225
arch: None,
226226
os: None,
227227
env: None,
@@ -250,7 +250,7 @@ impl PartialTargetTriple {
250250
}
251251
}
252252

253-
PartialTargetTriple {
253+
Self {
254254
arch: c.get(1).map(|s| s.as_str()).and_then(fn_map),
255255
os: c.get(2).map(|s| s.as_str()).and_then(fn_map),
256256
env: c.get(3).map(|s| s.as_str()).and_then(fn_map),
@@ -288,7 +288,7 @@ impl FromStr for PartialToolchainDesc {
288288

289289
let trip = c.get(3).map(|c| c.as_str()).unwrap_or("");
290290
let trip = PartialTargetTriple::new(&trip);
291-
trip.map(|t| PartialToolchainDesc {
291+
trip.map(|t| Self {
292292
channel: c.get(1).unwrap().as_str().to_owned(),
293293
date: c.get(2).map(|s| s.as_str()).and_then(fn_map),
294294
target: t,
@@ -382,7 +382,7 @@ impl FromStr for ToolchainDesc {
382382
}
383383
}
384384

385-
ToolchainDesc {
385+
Self {
386386
channel: c.get(1).unwrap().as_str().to_owned(),
387387
date: c.get(2).map(|s| s.as_str()).and_then(fn_map),
388388
target: TargetTriple(c.get(3).unwrap().as_str().to_owned()),

src/dist/manifest.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Manifest {
7979
return Err(ErrorKind::UnsupportedVersion(version).into());
8080
}
8181
let (renames, reverse_renames) = Self::table_to_renames(&mut table, path)?;
82-
Ok(Manifest {
82+
Ok(Self {
8383
manifest_version: version,
8484
date: get_string(&mut table, "date", path)?,
8585
packages: Self::table_to_packages(&mut table, path)?,
@@ -217,7 +217,7 @@ impl Manifest {
217217

218218
impl Package {
219219
pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
220-
Ok(Package {
220+
Ok(Self {
221221
version: get_string(&mut table, "version", path)?,
222222
targets: Self::toml_to_targets(table, path)?,
223223
})
@@ -303,7 +303,7 @@ impl TargetedPackage {
303303
let extensions = get_array(&mut table, "extensions", path)?;
304304

305305
if get_bool(&mut table, "available", path)? {
306-
Ok(TargetedPackage {
306+
Ok(Self {
307307
bins: Some(PackageBins {
308308
url: get_string(&mut table, "url", path)?,
309309
hash: get_string(&mut table, "hash", path)?,
@@ -320,7 +320,7 @@ impl TargetedPackage {
320320
)?,
321321
})
322322
} else {
323-
Ok(TargetedPackage {
323+
Ok(Self {
324324
bins: None,
325325
components: vec![],
326326
extensions: vec![],
@@ -377,17 +377,17 @@ impl TargetedPackage {
377377
}
378378

379379
impl Component {
380-
pub fn new(pkg: String, target: Option<TargetTriple>) -> Component {
381-
Component { pkg, target }
380+
pub fn new(pkg: String, target: Option<TargetTriple>) -> Self {
381+
Self { pkg, target }
382382
}
383-
pub fn wildcard(&self) -> Component {
384-
Component {
383+
pub fn wildcard(&self) -> Self {
384+
Self {
385385
pkg: self.pkg.clone(),
386386
target: None,
387387
}
388388
}
389389
pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
390-
Ok(Component {
390+
Ok(Self {
391391
pkg: get_string(&mut table, "pkg", path)?,
392392
target: get_string(&mut table, "target", path).map(|s| {
393393
if s == "*" {

src/dist/manifestation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Changes {
3535

3636
impl Changes {
3737
pub fn none() -> Self {
38-
Changes {
38+
Self {
3939
add_extensions: Vec::new(),
4040
remove_extensions: Vec::new(),
4141
}
@@ -83,7 +83,7 @@ impl Manifestation {
8383
pub fn open(prefix: InstallPrefix, triple: TargetTriple) -> Result<Self> {
8484
// TODO: validate the triple with the existing install as well
8585
// as the metadata format of the existing install
86-
Ok(Manifestation {
86+
Ok(Self {
8787
installation: Components::open(prefix)?,
8888
target_triple: triple,
8989
})
@@ -459,7 +459,7 @@ impl Update {
459459
new_manifest: &Manifest,
460460
changes: Changes,
461461
notify_handler: &dyn Fn(Notification<'_>),
462-
) -> Result<Update> {
462+
) -> Result<Self> {
463463
// Load the configuration and list of installed components.
464464
let config = manifestation.read_config()?;
465465

@@ -475,7 +475,7 @@ impl Update {
475475
.map(|c| c.components.clone())
476476
.unwrap_or_default();
477477

478-
let mut result = Update {
478+
let mut result = Self {
479479
components_to_uninstall: vec![],
480480
components_to_install: vec![],
481481
final_component_list: vec![],

src/dist/prefix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct InstallPrefix {
88
}
99
impl InstallPrefix {
1010
pub fn from(path: PathBuf) -> Self {
11-
InstallPrefix { path }
11+
Self { path }
1212
}
1313
pub fn path(&self) -> &Path {
1414
&self.path

src/dist/temp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl Cfg {
128128
dist_server: &str,
129129
notify_handler: Box<dyn Fn(Notification<'_>)>,
130130
) -> Self {
131-
Cfg {
131+
Self {
132132
root_directory,
133133
dist_server: dist_server.to_owned(),
134134
notify_handler,

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(rust_2018_idioms)]
2+
#![warn(clippy::use_self)]
23
#![recursion_limit = "1024"]
34

45
pub use crate::config::*;

src/settings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct SettingsFile {
1717

1818
impl SettingsFile {
1919
pub fn new(path: PathBuf) -> Self {
20-
SettingsFile {
20+
Self {
2121
path,
2222
cache: RefCell::new(None),
2323
}
@@ -72,7 +72,7 @@ pub struct Settings {
7272

7373
impl Default for Settings {
7474
fn default() -> Self {
75-
Settings {
75+
Self {
7676
version: DEFAULT_METADATA_VERSION.to_owned(),
7777
default_host_triple: None,
7878
default_toolchain: None,
@@ -134,7 +134,7 @@ impl Settings {
134134
if !SUPPORTED_METADATA_VERSIONS.contains(&&*version) {
135135
return Err(ErrorKind::UnknownMetadataVersion(version).into());
136136
}
137-
Ok(Settings {
137+
Ok(Self {
138138
version,
139139
default_host_triple: get_opt_string(&mut table, "default_host_triple", path)?,
140140
default_toolchain: get_opt_string(&mut table, "default_toolchain", path)?,

0 commit comments

Comments
 (0)