]> git.lizzy.rs Git - rust.git/commitdiff
A few cleanups for rustc_target
authorljedrz <ljedrz@gmail.com>
Thu, 9 Aug 2018 13:42:43 +0000 (15:42 +0200)
committerljedrz <ljedrz@gmail.com>
Thu, 9 Aug 2018 13:42:43 +0000 (15:42 +0200)
src/librustc_target/abi/call/mips64.rs
src/librustc_target/abi/call/mod.rs
src/librustc_target/abi/call/x86_64.rs
src/librustc_target/abi/mod.rs
src/librustc_target/spec/abi.rs
src/librustc_target/spec/apple_base.rs
src/librustc_target/spec/apple_ios_base.rs
src/librustc_target/spec/mod.rs

index 3734e563d585e5fb65b5e943bf1380b0585ebb92..8e2dd99696e176d3e78c1833cdce0ef1189a7bea 100644 (file)
@@ -145,7 +145,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>)
     // Extract first 8 chunks as the prefix
     let rest_size = size - Size::from_bytes(8) * prefix_index as u64;
     arg.cast_to(CastTarget {
-        prefix: prefix,
+        prefix,
         prefix_chunk: Size::from_bytes(8),
         rest: Uniform { unit: Reg::i64(), total: rest_size }
     });
index f65fa341231e3893facf13ff9de9fe84b373a5d5..af874b1035b89a81cb2e265faf25bdcf65a27b45 100644 (file)
@@ -90,7 +90,7 @@ pub fn new() -> Self {
     }
 
     pub fn set(&mut self, attr: ArgAttribute) -> &mut Self {
-        self.regular = self.regular | attr;
+        self.regular |= attr;
         self
     }
 
@@ -229,7 +229,7 @@ pub fn size<C: HasDataLayout>(&self, cx: C) -> Size {
 
     pub fn align<C: HasDataLayout>(&self, cx: C) -> Align {
         self.prefix.iter()
-            .filter_map(|x| x.map(|kind| Reg { kind: kind, size: self.prefix_chunk }.align(cx)))
+            .filter_map(|x| x.map(|kind| Reg { kind, size: self.prefix_chunk }.align(cx)))
             .fold(cx.data_layout().aggregate_align.max(self.rest.align(cx)),
                 |acc, align| acc.max(align))
     }
index a443255b9700f1bf5b425661565bf6f3a8d82944..eade086ec48eca0bfba54a6fecd70f8fab072476 100644 (file)
@@ -199,10 +199,8 @@ pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>)
                         _ => {}
                     }
                 }
-                if arg.layout.is_aggregate() {
-                    if int_regs < needed_int || sse_regs < needed_sse {
-                        cls_or_mem = Err(Memory);
-                    }
+                if arg.layout.is_aggregate() && (int_regs < needed_int || sse_regs < needed_sse) {
+                    cls_or_mem = Err(Memory);
                 }
             }
         }
index dac4738e2b4bf15eef230ee33e18dda16df30481..4f25360d8eae226685c68817e472596c42019968 100644 (file)
@@ -93,17 +93,17 @@ pub fn parse(target: &Target) -> Result<TargetDataLayout, String> {
         let mut dl = TargetDataLayout::default();
         let mut i128_align_src = 64;
         for spec in target.data_layout.split('-') {
-            match &spec.split(':').collect::<Vec<_>>()[..] {
-                &["e"] => dl.endian = Endian::Little,
-                &["E"] => dl.endian = Endian::Big,
-                &["a", ref a..] => dl.aggregate_align = align(a, "a")?,
-                &["f32", ref a..] => dl.f32_align = align(a, "f32")?,
-                &["f64", ref a..] => dl.f64_align = align(a, "f64")?,
-                &[p @ "p", s, ref a..] | &[p @ "p0", s, ref a..] => {
+            match spec.split(':').collect::<Vec<_>>()[..] {
+                ["e"] => dl.endian = Endian::Little,
+                ["E"] => dl.endian = Endian::Big,
+                ["a", ref a..] => dl.aggregate_align = align(a, "a")?,
+                ["f32", ref a..] => dl.f32_align = align(a, "f32")?,
+                ["f64", ref a..] => dl.f64_align = align(a, "f64")?,
+                [p @ "p", s, ref a..] | [p @ "p0", s, ref a..] => {
                     dl.pointer_size = size(s, p)?;
                     dl.pointer_align = align(a, p)?;
                 }
-                &[s, ref a..] if s.starts_with("i") => {
+                [s, ref a..] if s.starts_with("i") => {
                     let bits = match s[1..].parse::<u64>() {
                         Ok(bits) => bits,
                         Err(_) => {
@@ -127,7 +127,7 @@ pub fn parse(target: &Target) -> Result<TargetDataLayout, String> {
                         dl.i128_align = a;
                     }
                 }
-                &[s, ref a..] if s.starts_with("v") => {
+                [s, ref a..] if s.starts_with("v") => {
                     let v_size = size(&s[1..], "v")?;
                     let a = align(a, s)?;
                     if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
@@ -429,8 +429,8 @@ pub enum Integer {
 }
 
 impl Integer {
-    pub fn size(&self) -> Size {
-        match *self {
+    pub fn size(self) -> Size {
+        match self {
             I8 => Size::from_bytes(1),
             I16 => Size::from_bytes(2),
             I32 => Size::from_bytes(4),
@@ -439,10 +439,10 @@ pub fn size(&self) -> Size {
         }
     }
 
-    pub fn align<C: HasDataLayout>(&self, cx: C) -> Align {
+    pub fn align<C: HasDataLayout>(self, cx: C) -> Align {
         let dl = cx.data_layout();
 
-        match *self {
+        match self {
             I8 => dl.i8_align,
             I16 => dl.i16_align,
             I32 => dl.i32_align,
@@ -522,15 +522,15 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 }
 
 impl FloatTy {
-    pub fn ty_to_string(&self) -> &'static str {
-        match *self {
+    pub fn ty_to_string(self) -> &'static str {
+        match self {
             FloatTy::F32 => "f32",
             FloatTy::F64 => "f64",
         }
     }
 
-    pub fn bit_width(&self) -> usize {
-        match *self {
+    pub fn bit_width(self) -> usize {
+        match self {
             FloatTy::F32 => 32,
             FloatTy::F64 => 64,
         }
index 317cdb400636c943ffeb6d9dd7c4bfb9d15803ac..6d8c8eb19f057c25a87815f7c17655446309f4a1 100644 (file)
@@ -51,7 +51,7 @@ pub struct AbiData {
 }
 
 #[allow(non_upper_case_globals)]
-const AbiDatas: &'static [AbiData] = &[
+const AbiDatas: &[AbiData] = &[
     // Platform-specific ABIs
     AbiData {abi: Abi::Cdecl, name: "cdecl", generic: false },
     AbiData {abi: Abi::Stdcall, name: "stdcall", generic: false },
@@ -87,20 +87,20 @@ pub fn all_names() -> Vec<&'static str> {
 
 impl Abi {
     #[inline]
-    pub fn index(&self) -> usize {
-        *self as usize
+    pub fn index(self) -> usize {
+        self as usize
     }
 
     #[inline]
-    pub fn data(&self) -> &'static AbiData {
+    pub fn data(self) -> &'static AbiData {
         &AbiDatas[self.index()]
     }
 
-    pub fn name(&self) -> &'static str {
+    pub fn name(self) -> &'static str {
         self.data().name
     }
 
-    pub fn generic(&self) -> bool {
+    pub fn generic(self) -> bool {
         self.data().generic
     }
 }
index 4b66891e36f8c9975c11d406fe0f0fbd9b1dfb13..38b3f2528fe8694bb922d8657760173a935444e7 100644 (file)
@@ -26,7 +26,7 @@ pub fn opts() -> TargetOptions {
     // TLS is flagged as enabled if it looks to be supported.
     let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
     let version = deployment_target.as_ref().and_then(|s| {
-        let mut i = s.splitn(2, ".");
+        let mut i = s.splitn(2, '.');
         i.next().and_then(|a| i.next().map(|b| (a, b)))
     }).and_then(|(a, b)| {
         a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()
index 46bb01e7c420dfe1f92a90dd8cdeb94022d45509..296eaca7c7df013dac7c7cd23cf7cc6a74a2484a 100644 (file)
@@ -25,13 +25,13 @@ pub enum Arch {
 }
 
 impl Arch {
-    pub fn to_string(&self) -> &'static str {
+    pub fn to_string(self) -> &'static str {
         match self {
-            &Armv7 => "armv7",
-            &Armv7s => "armv7s",
-            &Arm64 => "arm64",
-            &I386 => "i386",
-            &X86_64 => "x86_64"
+            Armv7 => "armv7",
+            Armv7s => "armv7s",
+            Arm64 => "arm64",
+            I386 => "i386",
+            X86_64 => "x86_64"
         }
     }
 }
index 6faab77d7709f3cc7d320f12f742f928dde72e6c..4945784659517b63537ed5d85ac08b9cb9edf120 100644 (file)
@@ -747,7 +747,7 @@ pub fn min_atomic_width(&self) -> u64 {
     /// Maximum integer size in bits that this target can perform atomic
     /// operations on.
     pub fn max_atomic_width(&self) -> u64 {
-        self.options.max_atomic_width.unwrap_or(self.target_pointer_width.parse().unwrap())
+        self.options.max_atomic_width.unwrap_or_else(|| self.target_pointer_width.parse().unwrap())
     }
 
     pub fn is_abi_supported(&self, abi: Abi) -> bool {
@@ -777,7 +777,7 @@ pub fn from_json(obj: Json) -> TargetResult {
         let get_opt_field = |name: &str, default: &str| {
             obj.find(name).and_then(|s| s.as_string())
                .map(|s| s.to_string())
-               .unwrap_or(default.to_string())
+               .unwrap_or_else(|| default.to_string())
         };
 
         let mut base = Target {
@@ -1007,7 +1007,6 @@ macro_rules! key {
     /// filesystem access and JSON decoding.
     pub fn search(target_triple: &TargetTriple) -> Result<Target, String> {
         use std::env;
-        use std::ffi::OsString;
         use std::fs;
         use serialize::json;
 
@@ -1018,8 +1017,8 @@ fn load_file(path: &Path) -> Result<Target, String> {
             Target::from_json(obj)
         }
 
-        match target_triple {
-            &TargetTriple::TargetTriple(ref target_triple) => {
+        match *target_triple {
+            TargetTriple::TargetTriple(ref target_triple) => {
                 // check if triple is in list of supported targets
                 if let Ok(t) = load_specific(target_triple) {
                     return Ok(t)
@@ -1032,8 +1031,7 @@ fn load_file(path: &Path) -> Result<Target, String> {
                     PathBuf::from(target)
                 };
 
-                let target_path = env::var_os("RUST_TARGET_PATH")
-                                    .unwrap_or(OsString::new());
+                let target_path = env::var_os("RUST_TARGET_PATH").unwrap_or_default();
 
                 // FIXME 16351: add a sane default search path?
 
@@ -1045,7 +1043,7 @@ fn load_file(path: &Path) -> Result<Target, String> {
                 }
                 Err(format!("Could not find specification for target {:?}", target_triple))
             }
-            &TargetTriple::TargetPath(ref target_path) => {
+            TargetTriple::TargetPath(ref target_path) => {
                 if target_path.is_file() {
                     return load_file(&target_path);
                 }
@@ -1190,7 +1188,7 @@ macro_rules! target_option_val {
 
         if default.abi_blacklist != self.options.abi_blacklist {
             d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
-                .map(Abi::name).map(|name| name.to_json())
+                .map(|&name| Abi::name(name).to_json())
                 .collect::<Vec<_>>().to_json());
         }
 
@@ -1229,9 +1227,9 @@ pub fn from_path(path: &Path) -> Result<Self, io::Error> {
     ///
     /// If this target is a path, the file name (without extension) is returned.
     pub fn triple(&self) -> &str {
-        match self {
-            &TargetTriple::TargetTriple(ref triple) => triple,
-            &TargetTriple::TargetPath(ref path) => {
+        match *self {
+            TargetTriple::TargetTriple(ref triple) => triple,
+            TargetTriple::TargetPath(ref path) => {
                 path.file_stem().expect("target path must not be empty").to_str()
                     .expect("target path must be valid unicode")
             }
@@ -1247,7 +1245,7 @@ pub fn debug_triple(&self) -> String {
         use std::collections::hash_map::DefaultHasher;
 
         let triple = self.triple();
-        if let &TargetTriple::TargetPath(ref path) = self {
+        if let TargetTriple::TargetPath(ref path) = *self {
             let mut hasher = DefaultHasher::new();
             path.hash(&mut hasher);
             let hash = hasher.finish();