mirror of
https://github.com/servo/servo.git
synced 2025-08-10 16:05:43 +01:00
Fix some clippy warnings in components/gfx
and components/script
(#32215)
* clippy: Squish warnings and errors in gfx warning: redundant closure (gfx/font.rs:415:18) warning: useless conversion to the same type (gfx/font.rs:534:9) warning: the following explicit lifetimes could be elided: 'a (gfx/font.rs:619:16) error: this loop never actually loops (gfx/font_cache_thread.rs:112:9) warning: this expression creates a reference which is immediately dereferenced by the compiler (gfx/font_cache_thread.rs:229:51) warning: redundant closure (gfx/font_cache_thread.rs:551:18) 3 instances of: warning: casting integer literal to `f64` is unnecessary (gfx/platform/freetype/font_list.rs:271-273) * clippy: methods called `from_*` usually take no `self` It reports that by standard convention, from_* methods should not take any `&self` parameter * clippy: you should consider adding a `Default` implementation It reports that public types with a pub fn new() -> Self should have a Default implementation since they can be constructed without arguments * clippy: casting to the same type is unnecessary (`f32` -> `f32`) * clippy: use of `unwrap_or_else` to construct default value * clippy: methods called `is_*` usually take `self` by mutable reference or `self` by reference or no `self` * clippy: manual `!RangeInclusive::contains` implementation contains expresses the intent better and has less failure modes (such as fencepost errors or using || instead of &&) * clippy: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]` * clippy: Fix some new warnings warning: this `if` statement can be collapsed (gfx/font.rs:468:130) warning: this lifetime isn't used in the impl (gfx/platform/freetype/font.rs:341:6) warning: field assignment outside of initializer for an instance created with Default::default() (compositor.rs:881:17)
This commit is contained in:
parent
ca064eaa51
commit
160c7c0b0f
19 changed files with 56 additions and 47 deletions
|
@ -443,7 +443,7 @@ impl FontGroup {
|
|||
.font_family
|
||||
.families
|
||||
.iter()
|
||||
.map(|family| FontGroupFamily::new(family))
|
||||
.map(FontGroupFamily::new)
|
||||
.collect();
|
||||
|
||||
FontGroup {
|
||||
|
@ -465,10 +465,8 @@ impl FontGroup {
|
|||
let should_look_for_small_caps = self.descriptor.variant == font_variant_caps::T::SmallCaps &&
|
||||
codepoint.is_ascii_lowercase();
|
||||
let font_or_synthesized_small_caps = |font: FontRef| {
|
||||
if should_look_for_small_caps {
|
||||
if font.synthesized_small_caps.is_some() {
|
||||
return font.synthesized_small_caps.clone();
|
||||
}
|
||||
if should_look_for_small_caps && font.synthesized_small_caps.is_some() {
|
||||
return font.synthesized_small_caps.clone();
|
||||
}
|
||||
Some(font)
|
||||
};
|
||||
|
@ -565,7 +563,6 @@ impl FontGroup {
|
|||
.chain(fallback_font_families(codepoint).into_iter().map(|family| {
|
||||
FontFamilyDescriptor::new(FontFamilyName::from(family), FontSearchScope::Local)
|
||||
}))
|
||||
.into_iter()
|
||||
.filter_map(|family_descriptor| {
|
||||
FontGroupFamily {
|
||||
family_descriptor,
|
||||
|
@ -646,11 +643,11 @@ impl FontGroupFamily {
|
|||
.next()
|
||||
}
|
||||
|
||||
fn members<'a, S: FontSource>(
|
||||
&'a mut self,
|
||||
fn members<S: FontSource>(
|
||||
&mut self,
|
||||
font_descriptor: &FontDescriptor,
|
||||
font_context: &FontContext<S>,
|
||||
) -> impl Iterator<Item = &mut FontGroupFamilyMember> + 'a {
|
||||
) -> impl Iterator<Item = &mut FontGroupFamilyMember> {
|
||||
let family_descriptor = &self.family_descriptor;
|
||||
let members = self.members.get_or_insert_with(|| {
|
||||
font_context
|
||||
|
|
|
@ -108,7 +108,7 @@ impl FontTemplates {
|
|||
// If a request is made for a font family that exists,
|
||||
// pick the first valid font in the family if we failed
|
||||
// to find an exact match for the descriptor.
|
||||
for template in &mut self.templates.iter() {
|
||||
if let Some(template) = self.templates.first() {
|
||||
return vec![template.clone()];
|
||||
}
|
||||
|
||||
|
@ -231,7 +231,7 @@ impl FontCache {
|
|||
.font_data
|
||||
.entry(identifier)
|
||||
.or_insert_with(|| font_template.data());
|
||||
let _ = bytes_sender.send(&data);
|
||||
let _ = bytes_sender.send(data);
|
||||
}
|
||||
},
|
||||
Command::GetFontInstance(identifier, pt_size, flags, result) => {
|
||||
|
@ -557,10 +557,7 @@ impl From<&FontFaceRuleData> for CSSFontFaceDescriptors {
|
|||
),
|
||||
}
|
||||
}
|
||||
let style = rule_data
|
||||
.style
|
||||
.as_ref()
|
||||
.map(|style| style_to_computed(style));
|
||||
let style = rule_data.style.as_ref().map(style_to_computed);
|
||||
let unicode_range = rule_data
|
||||
.unicode_range
|
||||
.as_ref()
|
||||
|
|
|
@ -338,7 +338,7 @@ impl PlatformFontMethods for PlatformFont {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> PlatformFont {
|
||||
impl PlatformFont {
|
||||
fn set_char_size(face: FT_Face, pt_size: Au) -> Result<(), &'static str> {
|
||||
let char_size = pt_size.to_f64_px() * 64.0 + 0.5;
|
||||
|
||||
|
|
|
@ -268,9 +268,9 @@ fn font_weight_from_fontconfig_pattern(pattern: *mut FcPattern) -> Option<FontWe
|
|||
|
||||
let mapping = [
|
||||
(0., 0.),
|
||||
(FC_WEIGHT_REGULAR as f64, 400 as f64),
|
||||
(FC_WEIGHT_BOLD as f64, 700 as f64),
|
||||
(FC_WEIGHT_EXTRABLACK as f64, 1000 as f64),
|
||||
(FC_WEIGHT_REGULAR as f64, 400_f64),
|
||||
(FC_WEIGHT_BOLD as f64, 700_f64),
|
||||
(FC_WEIGHT_EXTRABLACK as f64, 1000_f64),
|
||||
];
|
||||
|
||||
let mapped_weight = map_platform_values_to_style_values(&mapping, weight as f64);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue