From 025456e8a4e418813edf77bd9c1e69213276d447 Mon Sep 17 00:00:00 2001 From: Austin Hicks Date: Wed, 23 Nov 2016 17:43:36 -0500 Subject: [PATCH] Incorporate review comments --- src/librustc/ty/layout.rs | 20 +++++++------------- src/test/run-pass/closure-immediate.rs | 2 +- src/test/run-pass/multiple-reprs.rs | 1 - 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 6f63b15abe8..96d66153d77 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -459,11 +459,7 @@ fn repr_discr(tcx: TyCtxt, ty: Ty, hints: &[attr::ReprAttr], min: i64, max: i64) } } - let at_least = if let Some(i) = min_from_extern { - i - } else { - min_default - }; + let at_least = min_from_extern.unwrap_or(min_default); // If there are no negative values, we can use the unsigned fit. if min >= 0 { @@ -571,13 +567,11 @@ fn new(dl: &TargetDataLayout, fields: &Vec<&'a Layout>, if can_optimize { // This exhaustive match makes new reprs force the adder to modify this function. // Otherwise, things can silently break. - // Note the inversion, return true to stop matching. + // Note the inversion, return true to stop optimizing. can_optimize = !reprs.iter().any(|r| { match *r { - attr::ReprAny => false, - attr::ReprInt(_) => false, - attr::ReprExtern => true, - attr::ReprPacked => true, + attr::ReprAny | attr::ReprInt(_) => false, + attr::ReprExtern | attr::ReprPacked => true, attr::ReprSimd => bug!("Simd vectors should be represented as layout::Vector") } }); @@ -588,7 +582,7 @@ fn new(dl: &TargetDataLayout, fields: &Vec<&'a Layout>, StructKind::MaybeUnsizedUnivariant => (can_optimize, false), StructKind::EnumVariant => { assert!(fields.len() >= 1, "Enum variants must have discriminants."); - (can_optimize || fields[0].size(dl).bytes() == 1, true) + (can_optimize && fields[0].size(dl).bytes() == 1, true) } }; @@ -1189,7 +1183,7 @@ pub fn compute_uncached(ty: Ty<'gcx>, }); } - if !def.is_enum() || def.variants.len() == 1 && hints.len() == 0 { + if !def.is_enum() || def.variants.len() == 1 && hints.is_empty() { // Struct, or union, or univariant enum equivalent to a struct. // (Typechecking will reject discriminant-sizing attrs.) @@ -1239,7 +1233,7 @@ pub fn compute_uncached(ty: Ty<'gcx>, v.fields.iter().map(|field| field.ty(tcx, substs)).collect::>() }).collect::>(); - if variants.len() == 2 && hints.len() == 0 { + if variants.len() == 2 && hints.is_empty() { // Nullable pointer optimization for discr in 0..2 { let other_fields = variants[1 - discr].iter().map(|ty| { diff --git a/src/test/run-pass/closure-immediate.rs b/src/test/run-pass/closure-immediate.rs index 69aa16c3fb5..e566c105835 100644 --- a/src/test/run-pass/closure-immediate.rs +++ b/src/test/run-pass/closure-immediate.rs @@ -19,4 +19,4 @@ fn main() { assert_eq!(c, 3); }; c(1, 2, 3); -} \ No newline at end of file +} diff --git a/src/test/run-pass/multiple-reprs.rs b/src/test/run-pass/multiple-reprs.rs index 726563e5b49..c2fe943eed8 100644 --- a/src/test/run-pass/multiple-reprs.rs +++ b/src/test/run-pass/multiple-reprs.rs @@ -28,7 +28,6 @@ enum E2 { } // From pr 37429 -pub const SIZEOF_QUERY: usize = 21; #[repr(C,packed)] pub struct p0f_api_query {