Skip to content

Commit 25a58af

Browse files
committed
A few cleanups for rustc_target
1 parent 76b69a6 commit 25a58af

File tree

8 files changed

+46
-50
lines changed

8 files changed

+46
-50
lines changed

src/librustc_target/abi/call/mips64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>)
145145
// Extract first 8 chunks as the prefix
146146
let rest_size = size - Size::from_bytes(8) * prefix_index as u64;
147147
arg.cast_to(CastTarget {
148-
prefix: prefix,
148+
prefix,
149149
prefix_chunk: Size::from_bytes(8),
150150
rest: Uniform { unit: Reg::i64(), total: rest_size }
151151
});

src/librustc_target/abi/call/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl ArgAttributes {
9090
}
9191

9292
pub fn set(&mut self, attr: ArgAttribute) -> &mut Self {
93-
self.regular = self.regular | attr;
93+
self.regular |= attr;
9494
self
9595
}
9696

@@ -229,7 +229,7 @@ impl CastTarget {
229229

230230
pub fn align<C: HasDataLayout>(&self, cx: C) -> Align {
231231
self.prefix.iter()
232-
.filter_map(|x| x.map(|kind| Reg { kind: kind, size: self.prefix_chunk }.align(cx)))
232+
.filter_map(|x| x.map(|kind| Reg { kind, size: self.prefix_chunk }.align(cx)))
233233
.fold(cx.data_layout().aggregate_align.max(self.rest.align(cx)),
234234
|acc, align| acc.max(align))
235235
}

src/librustc_target/abi/call/x86_64.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,8 @@ pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>)
199199
_ => {}
200200
}
201201
}
202-
if arg.layout.is_aggregate() {
203-
if int_regs < needed_int || sse_regs < needed_sse {
204-
cls_or_mem = Err(Memory);
205-
}
202+
if arg.layout.is_aggregate() && (int_regs < needed_int || sse_regs < needed_sse) {
203+
cls_or_mem = Err(Memory);
206204
}
207205
}
208206
}

src/librustc_target/abi/mod.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ impl TargetDataLayout {
9393
let mut dl = TargetDataLayout::default();
9494
let mut i128_align_src = 64;
9595
for spec in target.data_layout.split('-') {
96-
match &spec.split(':').collect::<Vec<_>>()[..] {
97-
&["e"] => dl.endian = Endian::Little,
98-
&["E"] => dl.endian = Endian::Big,
99-
&["a", ref a..] => dl.aggregate_align = align(a, "a")?,
100-
&["f32", ref a..] => dl.f32_align = align(a, "f32")?,
101-
&["f64", ref a..] => dl.f64_align = align(a, "f64")?,
102-
&[p @ "p", s, ref a..] | &[p @ "p0", s, ref a..] => {
96+
match spec.split(':').collect::<Vec<_>>()[..] {
97+
["e"] => dl.endian = Endian::Little,
98+
["E"] => dl.endian = Endian::Big,
99+
["a", ref a..] => dl.aggregate_align = align(a, "a")?,
100+
["f32", ref a..] => dl.f32_align = align(a, "f32")?,
101+
["f64", ref a..] => dl.f64_align = align(a, "f64")?,
102+
[p @ "p", s, ref a..] | [p @ "p0", s, ref a..] => {
103103
dl.pointer_size = size(s, p)?;
104104
dl.pointer_align = align(a, p)?;
105105
}
106-
&[s, ref a..] if s.starts_with("i") => {
106+
[s, ref a..] if s.starts_with("i") => {
107107
let bits = match s[1..].parse::<u64>() {
108108
Ok(bits) => bits,
109109
Err(_) => {
@@ -127,7 +127,7 @@ impl TargetDataLayout {
127127
dl.i128_align = a;
128128
}
129129
}
130-
&[s, ref a..] if s.starts_with("v") => {
130+
[s, ref a..] if s.starts_with("v") => {
131131
let v_size = size(&s[1..], "v")?;
132132
let a = align(a, s)?;
133133
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
@@ -429,8 +429,8 @@ pub enum Integer {
429429
}
430430

431431
impl Integer {
432-
pub fn size(&self) -> Size {
433-
match *self {
432+
pub fn size(self) -> Size {
433+
match self {
434434
I8 => Size::from_bytes(1),
435435
I16 => Size::from_bytes(2),
436436
I32 => Size::from_bytes(4),
@@ -439,10 +439,10 @@ impl Integer {
439439
}
440440
}
441441

442-
pub fn align<C: HasDataLayout>(&self, cx: C) -> Align {
442+
pub fn align<C: HasDataLayout>(self, cx: C) -> Align {
443443
let dl = cx.data_layout();
444444

445-
match *self {
445+
match self {
446446
I8 => dl.i8_align,
447447
I16 => dl.i16_align,
448448
I32 => dl.i32_align,
@@ -522,15 +522,15 @@ impl fmt::Display for FloatTy {
522522
}
523523

524524
impl FloatTy {
525-
pub fn ty_to_string(&self) -> &'static str {
526-
match *self {
525+
pub fn ty_to_string(self) -> &'static str {
526+
match self {
527527
FloatTy::F32 => "f32",
528528
FloatTy::F64 => "f64",
529529
}
530530
}
531531

532-
pub fn bit_width(&self) -> usize {
533-
match *self {
532+
pub fn bit_width(self) -> usize {
533+
match self {
534534
FloatTy::F32 => 32,
535535
FloatTy::F64 => 64,
536536
}

src/librustc_target/spec/abi.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct AbiData {
5151
}
5252

5353
#[allow(non_upper_case_globals)]
54-
const AbiDatas: &'static [AbiData] = &[
54+
const AbiDatas: &[AbiData] = &[
5555
// Platform-specific ABIs
5656
AbiData {abi: Abi::Cdecl, name: "cdecl", generic: false },
5757
AbiData {abi: Abi::Stdcall, name: "stdcall", generic: false },
@@ -87,20 +87,20 @@ pub fn all_names() -> Vec<&'static str> {
8787

8888
impl Abi {
8989
#[inline]
90-
pub fn index(&self) -> usize {
91-
*self as usize
90+
pub fn index(self) -> usize {
91+
self as usize
9292
}
9393

9494
#[inline]
95-
pub fn data(&self) -> &'static AbiData {
95+
pub fn data(self) -> &'static AbiData {
9696
&AbiDatas[self.index()]
9797
}
9898

99-
pub fn name(&self) -> &'static str {
99+
pub fn name(self) -> &'static str {
100100
self.data().name
101101
}
102102

103-
pub fn generic(&self) -> bool {
103+
pub fn generic(self) -> bool {
104104
self.data().generic
105105
}
106106
}

src/librustc_target/spec/apple_base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn opts() -> TargetOptions {
2626
// TLS is flagged as enabled if it looks to be supported.
2727
let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
2828
let version = deployment_target.as_ref().and_then(|s| {
29-
let mut i = s.splitn(2, ".");
29+
let mut i = s.splitn(2, '.');
3030
i.next().and_then(|a| i.next().map(|b| (a, b)))
3131
}).and_then(|(a, b)| {
3232
a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()

src/librustc_target/spec/apple_ios_base.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ pub enum Arch {
2525
}
2626

2727
impl Arch {
28-
pub fn to_string(&self) -> &'static str {
28+
pub fn to_string(self) -> &'static str {
2929
match self {
30-
&Armv7 => "armv7",
31-
&Armv7s => "armv7s",
32-
&Arm64 => "arm64",
33-
&I386 => "i386",
34-
&X86_64 => "x86_64"
30+
Armv7 => "armv7",
31+
Armv7s => "armv7s",
32+
Arm64 => "arm64",
33+
I386 => "i386",
34+
X86_64 => "x86_64"
3535
}
3636
}
3737
}

src/librustc_target/spec/mod.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ impl Target {
747747
/// Maximum integer size in bits that this target can perform atomic
748748
/// operations on.
749749
pub fn max_atomic_width(&self) -> u64 {
750-
self.options.max_atomic_width.unwrap_or(self.target_pointer_width.parse().unwrap())
750+
self.options.max_atomic_width.unwrap_or_else(|| self.target_pointer_width.parse().unwrap())
751751
}
752752

753753
pub fn is_abi_supported(&self, abi: Abi) -> bool {
@@ -777,7 +777,7 @@ impl Target {
777777
let get_opt_field = |name: &str, default: &str| {
778778
obj.find(name).and_then(|s| s.as_string())
779779
.map(|s| s.to_string())
780-
.unwrap_or(default.to_string())
780+
.unwrap_or_else(|| default.to_string())
781781
};
782782

783783
let mut base = Target {
@@ -1007,7 +1007,6 @@ impl Target {
10071007
/// filesystem access and JSON decoding.
10081008
pub fn search(target_triple: &TargetTriple) -> Result<Target, String> {
10091009
use std::env;
1010-
use std::ffi::OsString;
10111010
use std::fs;
10121011
use serialize::json;
10131012

@@ -1018,8 +1017,8 @@ impl Target {
10181017
Target::from_json(obj)
10191018
}
10201019

1021-
match target_triple {
1022-
&TargetTriple::TargetTriple(ref target_triple) => {
1020+
match *target_triple {
1021+
TargetTriple::TargetTriple(ref target_triple) => {
10231022
// check if triple is in list of supported targets
10241023
if let Ok(t) = load_specific(target_triple) {
10251024
return Ok(t)
@@ -1032,8 +1031,7 @@ impl Target {
10321031
PathBuf::from(target)
10331032
};
10341033

1035-
let target_path = env::var_os("RUST_TARGET_PATH")
1036-
.unwrap_or(OsString::new());
1034+
let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default();
10371035

10381036
// FIXME 16351: add a sane default search path?
10391037

@@ -1045,7 +1043,7 @@ impl Target {
10451043
}
10461044
Err(format!("Could not find specification for target {:?}", target_triple))
10471045
}
1048-
&TargetTriple::TargetPath(ref target_path) => {
1046+
TargetTriple::TargetPath(ref target_path) => {
10491047
if target_path.is_file() {
10501048
return load_file(&target_path);
10511049
}
@@ -1190,7 +1188,7 @@ impl ToJson for Target {
11901188

11911189
if default.abi_blacklist != self.options.abi_blacklist {
11921190
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
1193-
.map(Abi::name).map(|name| name.to_json())
1191+
.map(|&name| Abi::name(name).to_json())
11941192
.collect::<Vec<_>>().to_json());
11951193
}
11961194

@@ -1229,9 +1227,9 @@ impl TargetTriple {
12291227
///
12301228
/// If this target is a path, the file name (without extension) is returned.
12311229
pub fn triple(&self) -> &str {
1232-
match self {
1233-
&TargetTriple::TargetTriple(ref triple) => triple,
1234-
&TargetTriple::TargetPath(ref path) => {
1230+
match *self {
1231+
TargetTriple::TargetTriple(ref triple) => triple,
1232+
TargetTriple::TargetPath(ref path) => {
12351233
path.file_stem().expect("target path must not be empty").to_str()
12361234
.expect("target path must be valid unicode")
12371235
}
@@ -1247,7 +1245,7 @@ impl TargetTriple {
12471245
use std::collections::hash_map::DefaultHasher;
12481246

12491247
let triple = self.triple();
1250-
if let &TargetTriple::TargetPath(ref path) = self {
1248+
if let TargetTriple::TargetPath(ref path) = *self {
12511249
let mut hasher = DefaultHasher::new();
12521250
path.hash(&mut hasher);
12531251
let hash = hasher.finish();

0 commit comments

Comments
 (0)