Auto merge of #9123 - karyon:clippy_cleanup, r=Manishearth

Fix a bunch of clippy lints

This fixes about 130 clippy lints. Let me know if i should split up the commit.

I wasn't sure about some of the changes, especially map_or instead of map(...).unwrap_or(...) and if let instead of single arm match were not always a strict improvement in my opinion, but i'll leave that decision to the reviewer :)

There are about 150 lints left which i thought were clippy bugs or i didn't know how to fix.

cc @Manishearth

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9123)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-01-03 09:16:34 +05:30
commit 9da739acef
58 changed files with 281 additions and 356 deletions

View file

@ -941,7 +941,7 @@ impl StackingContextLayerCreator {
return Some(LayerInfo::new(layer.id, ScrollPolicy::Scrollable, None));
}
return self.last_child_layer_info;
self.last_child_layer_info
}
#[inline]

View file

@ -39,7 +39,7 @@ impl FontTemplates {
}
/// Find a font in this family that matches a given descriptor.
fn find_font_for_style<'a>(&'a mut self, desc: &FontTemplateDescriptor, fctx: &FontContextHandle)
fn find_font_for_style(&mut self, desc: &FontTemplateDescriptor, fctx: &FontContextHandle)
-> Option<Arc<FontTemplateData>> {
// TODO(Issue #189): optimize lookup for
// regular/bold/italic/bolditalic with fixed offsets and a
@ -251,7 +251,7 @@ impl FontCache {
}
}
fn find_font_in_local_family<'a>(&'a mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
fn find_font_in_local_family(&mut self, family_name: &LowercaseString, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
// TODO(Issue #188): look up localized font family names if canonical name not found
// look up canonical name
@ -275,14 +275,13 @@ impl FontCache {
}
}
fn find_font_in_web_family<'a>(&'a mut self, family: &FontFamily, desc: &FontTemplateDescriptor)
fn find_font_in_web_family(&mut self, family: &FontFamily, desc: &FontTemplateDescriptor)
-> Option<Arc<FontTemplateData>> {
let family_name = LowercaseString::new(family.name());
if self.web_families.contains_key(&family_name) {
let templates = self.web_families.get_mut(&family_name).unwrap();
let maybe_font = templates.find_font_for_style(desc, &self.font_context);
maybe_font
templates.find_font_for_style(desc, &self.font_context)
} else {
None
}

View file

@ -166,12 +166,12 @@ impl FontHandleMethods for FontHandle {
assert!(!self.face.is_null());
unsafe {
let idx = FT_Get_Char_Index(self.face, codepoint as FT_ULong);
return if idx != 0 as FT_UInt {
if idx != 0 as FT_UInt {
Some(idx as GlyphId)
} else {
debug!("Invalid codepoint: {}", codepoint);
None
};
}
}
}
@ -196,10 +196,10 @@ impl FontHandleMethods for FontHandle {
let advance = (*slot).metrics.horiAdvance;
debug!("h_advance for {} is {}", glyph, advance);
let advance = advance as i32;
return Some(fixed_to_float_ft(advance) as FractionalPixel);
Some(fixed_to_float_ft(advance) as FractionalPixel)
} else {
debug!("Unable to load glyph {}. reason: {}", glyph, res);
return None;
None
}
}
}
@ -239,8 +239,7 @@ impl FontHandleMethods for FontHandle {
let average_advance = self.glyph_index('0')
.and_then(|idx| self.glyph_h_advance(idx))
.map(|advance| self.font_units_to_au(advance))
.unwrap_or(max_advance);
.map_or(max_advance, |advance| self.font_units_to_au(advance));
let metrics = FontMetrics {
underline_size: underline_size,
@ -258,7 +257,7 @@ impl FontHandleMethods for FontHandle {
};
debug!("Font metrics (@{}px): {:?}", em_size.to_f32_px(), metrics);
return metrics;
metrics
}
fn table_for_tag(&self, tag: FontTableTag) -> Option<Box<FontTable>> {
@ -310,6 +309,6 @@ impl<'a> FontHandle {
// If this isn't true then we're scaling one of the axes wrong
assert!(metrics.x_ppem == metrics.y_ppem);
return Au::from_f64_px(value * x_scale);
Au::from_f64_px(value * x_scale)
}
}