]> git.lizzy.rs Git - rust.git/commitdiff
Make tidy
authorAustin Hicks <camlorn@camlorn.net>
Mon, 21 Nov 2016 19:23:15 +0000 (14:23 -0500)
committerAustin Hicks <camlorn@camlorn.net>
Wed, 14 Dec 2016 17:28:21 +0000 (12:28 -0500)
src/librustc/ty/layout.rs
src/librustc_lint/types.rs
src/librustc_trans/debuginfo/metadata.rs
src/test/run-pass/enum-size-variance.rs

index bcbafc8a28a5ed73817826ab2a1aacb5220fcb71..ebda879e9086f4556b761c50447cda9e7d1c26cd 100644 (file)
@@ -538,7 +538,10 @@ pub fn new(dl: &TargetDataLayout, fields: &Vec<&'a Layout>,
             min_size: Size::from_bytes(0),
         };
 
-        if is_enum_variant { assert!(fields.len() >= 1, "Enum variants must have at least a discriminant field.") }
+        if is_enum_variant {
+            assert!(fields.len() >= 1, "Enum variants must have at least a discriminant field.")
+        }
+
         if fields.len() == 0 {return Ok(ret)};
 
         ret.offsets = vec![Size::from_bytes(0); fields.len()];
@@ -546,7 +549,8 @@ pub fn new(dl: &TargetDataLayout, fields: &Vec<&'a Layout>,
 
         if repr == attr::ReprAny {
             let start = if is_enum_variant {1} else {0};
-            // FIXME(camlorn): we can't reorder the last field because it is possible for structs to be coerced to unsized.
+            // FIXME(camlorn): we can't reorder the last field because
+            // it is possible for structs to be coerced to unsized.
             // Example: struct Foo<T: ?Sized> { x: i32, y: T }
             // We can coerce &Foo<u8> to &Foo<Trait>.
             let end = inverse_memory_index.len()-1;
@@ -554,12 +558,16 @@ pub fn new(dl: &TargetDataLayout, fields: &Vec<&'a Layout>,
                 let optimizing  = &mut inverse_memory_index[start..end];
                 optimizing.sort_by_key(|&x| fields[x as usize].align(dl).abi());
             }
-            if is_enum_variant { assert_eq!(inverse_memory_index[0], 0, "Enums must have field 0 as the field with lowest offset.") }
+            if is_enum_variant {
+                assert_eq!(inverse_memory_index[0], 0,
+                  "Enums must have field 0 as the field with lowest offset.")
+            }
         }
-        
+
         // At this point, inverse_memory_index holds field indices by increasing offset.
         // That is, if field 5 has offset 0, the first element of inverse_memory_index is 5.
-        // We now write field offsets to the corresponding offset slot; field 5 with offset 0 puts 0 in offsets[5].
+        // We now write field offsets to the corresponding offset slot;
+        // field 5 with offset 0 puts 0 in offsets[5].
         // At the bottom of this function, we use inverse_memory_index to produce memory_index.
 
         let mut offset = Size::from_bytes(0);
@@ -976,7 +984,10 @@ pub fn compute_uncached(ty: Ty<'gcx>,
             ty::TyFnPtr(_) => Scalar { value: Pointer, non_zero: true },
 
             // The never type.
-            ty::TyNever => Univariant { variant: Struct::new(dl, &vec![], attr::ReprAny, false, ty)?, non_zero: false },
+            ty::TyNever => Univariant {
+                variant: Struct::new(dl, &vec![], attr::ReprAny, false, ty)?,
+                non_zero: false
+            },
 
             // Potentially-fat pointers.
             ty::TyBox(pointee) |
@@ -1179,7 +1190,7 @@ pub fn compute_uncached(ty: Ty<'gcx>,
                               .collect::<Result<Vec<_>, _>>()?,
                             hint, false, ty)?;
 
-                        // We have to fix the last element of path here as only we know the right value.
+                        // We have to fix the last element of path here.
                         let mut i = *path.last().unwrap();
                         i = st.memory_index[i as usize];
                         *path.last_mut().unwrap() = i;
index 49bbcc18efb2891e799694ca59d2827c2f72fcd4..751c9c3440f66326a06454204416c9cf237f388f 100644 (file)
@@ -750,7 +750,8 @@ fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
                 if let Layout::General { ref variants, ref size, discr, .. } = *layout {
                     let discr_size = Primitive::Int(discr).size(&cx.tcx.data_layout).bytes();
 
-                    debug!("enum `{}` is {} bytes large with layout:\n{:#?}", t, size.bytes(), layout);
+                    debug!("enum `{}` is {} bytes large with layout:\n{:#?}",
+                      t, size.bytes(), layout);
 
                     let (largest, slargest, largest_index) = enum_definition.variants
                         .iter()
index ad6103965986cad4fd2513a1aebecfd303971199..f6b5bde6ebb445b359427f970ff024971871ab66 100644 (file)
@@ -891,15 +891,15 @@ impl<'tcx> StructMemberDescriptionFactory<'tcx> {
     fn create_member_descriptions<'a>(&self, cx: &CrateContext<'a, 'tcx>)
                                       -> Vec<MemberDescription> {
         let layout = cx.layout_of(self.ty);
-        
-        // The following code is slightly convoluted as to allow us to avoid allocating in the Univariant case.
-        // tmp exists only so we can take a reference to it in the second match arm below.
+
         let tmp;
         let offsets = match *layout {
             layout::Univariant { ref variant, .. } => &variant.offsets,
             layout::Vector { element, count } => {
                 let element_size = element.size(&cx.tcx().data_layout).bytes();
-                tmp = (0..count).map(|i| layout::Size::from_bytes(i*element_size)).collect::<Vec<layout::Size>>();
+                tmp = (0..count).
+                  map(|i| layout::Size::from_bytes(i*element_size))
+                  .collect::<Vec<layout::Size>>();
                 &tmp
             }
             _ => bug!("{} is not a struct", self.ty)
index beccbf5eb0394a64c3202a9863912d74b631d50e..a3e95a153418dbd3116fceacc3aa23614930a3bd 100644 (file)
@@ -11,8 +11,8 @@
 #![warn(variant_size_differences)]
 #![allow(dead_code)]
 
-// Note that the following test only works because all fields of the enum variants are of the same size.
-// If this test is modified so that the reordering logic in librustc/ty/layout.rs kicks in, it will fail.
+// Note that the following test works because all fields of the enum variants are of the same size.
+// If this test is modified and the reordering logic in librustc/ty/layout.rs kicks in, it fails.
 
 enum Enum1 { }