mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +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
|
@ -877,8 +877,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
||||||
let key = self.webrender_api.generate_font_instance_key();
|
let key = self.webrender_api.generate_font_instance_key();
|
||||||
let mut transaction = Transaction::new();
|
let mut transaction = Transaction::new();
|
||||||
|
|
||||||
let mut font_instance_options = FontInstanceOptions::default();
|
let font_instance_options = FontInstanceOptions {
|
||||||
font_instance_options.flags = flags;
|
flags,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
transaction.add_font_instance(
|
transaction.add_font_instance(
|
||||||
key,
|
key,
|
||||||
font_key,
|
font_key,
|
||||||
|
|
|
@ -443,7 +443,7 @@ impl FontGroup {
|
||||||
.font_family
|
.font_family
|
||||||
.families
|
.families
|
||||||
.iter()
|
.iter()
|
||||||
.map(|family| FontGroupFamily::new(family))
|
.map(FontGroupFamily::new)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
FontGroup {
|
FontGroup {
|
||||||
|
@ -465,10 +465,8 @@ impl FontGroup {
|
||||||
let should_look_for_small_caps = self.descriptor.variant == font_variant_caps::T::SmallCaps &&
|
let should_look_for_small_caps = self.descriptor.variant == font_variant_caps::T::SmallCaps &&
|
||||||
codepoint.is_ascii_lowercase();
|
codepoint.is_ascii_lowercase();
|
||||||
let font_or_synthesized_small_caps = |font: FontRef| {
|
let font_or_synthesized_small_caps = |font: FontRef| {
|
||||||
if should_look_for_small_caps {
|
if should_look_for_small_caps && font.synthesized_small_caps.is_some() {
|
||||||
if font.synthesized_small_caps.is_some() {
|
return font.synthesized_small_caps.clone();
|
||||||
return font.synthesized_small_caps.clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(font)
|
Some(font)
|
||||||
};
|
};
|
||||||
|
@ -565,7 +563,6 @@ impl FontGroup {
|
||||||
.chain(fallback_font_families(codepoint).into_iter().map(|family| {
|
.chain(fallback_font_families(codepoint).into_iter().map(|family| {
|
||||||
FontFamilyDescriptor::new(FontFamilyName::from(family), FontSearchScope::Local)
|
FontFamilyDescriptor::new(FontFamilyName::from(family), FontSearchScope::Local)
|
||||||
}))
|
}))
|
||||||
.into_iter()
|
|
||||||
.filter_map(|family_descriptor| {
|
.filter_map(|family_descriptor| {
|
||||||
FontGroupFamily {
|
FontGroupFamily {
|
||||||
family_descriptor,
|
family_descriptor,
|
||||||
|
@ -646,11 +643,11 @@ impl FontGroupFamily {
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn members<'a, S: FontSource>(
|
fn members<S: FontSource>(
|
||||||
&'a mut self,
|
&mut self,
|
||||||
font_descriptor: &FontDescriptor,
|
font_descriptor: &FontDescriptor,
|
||||||
font_context: &FontContext<S>,
|
font_context: &FontContext<S>,
|
||||||
) -> impl Iterator<Item = &mut FontGroupFamilyMember> + 'a {
|
) -> impl Iterator<Item = &mut FontGroupFamilyMember> {
|
||||||
let family_descriptor = &self.family_descriptor;
|
let family_descriptor = &self.family_descriptor;
|
||||||
let members = self.members.get_or_insert_with(|| {
|
let members = self.members.get_or_insert_with(|| {
|
||||||
font_context
|
font_context
|
||||||
|
|
|
@ -108,7 +108,7 @@ impl FontTemplates {
|
||||||
// If a request is made for a font family that exists,
|
// If a request is made for a font family that exists,
|
||||||
// pick the first valid font in the family if we failed
|
// pick the first valid font in the family if we failed
|
||||||
// to find an exact match for the descriptor.
|
// 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()];
|
return vec![template.clone()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ impl FontCache {
|
||||||
.font_data
|
.font_data
|
||||||
.entry(identifier)
|
.entry(identifier)
|
||||||
.or_insert_with(|| font_template.data());
|
.or_insert_with(|| font_template.data());
|
||||||
let _ = bytes_sender.send(&data);
|
let _ = bytes_sender.send(data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Command::GetFontInstance(identifier, pt_size, flags, result) => {
|
Command::GetFontInstance(identifier, pt_size, flags, result) => {
|
||||||
|
@ -557,10 +557,7 @@ impl From<&FontFaceRuleData> for CSSFontFaceDescriptors {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let style = rule_data
|
let style = rule_data.style.as_ref().map(style_to_computed);
|
||||||
.style
|
|
||||||
.as_ref()
|
|
||||||
.map(|style| style_to_computed(style));
|
|
||||||
let unicode_range = rule_data
|
let unicode_range = rule_data
|
||||||
.unicode_range
|
.unicode_range
|
||||||
.as_ref()
|
.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> {
|
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;
|
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 = [
|
let mapping = [
|
||||||
(0., 0.),
|
(0., 0.),
|
||||||
(FC_WEIGHT_REGULAR as f64, 400 as f64),
|
(FC_WEIGHT_REGULAR as f64, 400_f64),
|
||||||
(FC_WEIGHT_BOLD as f64, 700 as f64),
|
(FC_WEIGHT_BOLD as f64, 700_f64),
|
||||||
(FC_WEIGHT_EXTRABLACK as f64, 1000 as f64),
|
(FC_WEIGHT_EXTRABLACK as f64, 1000_f64),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mapped_weight = map_platform_values_to_style_values(&mapping, weight as f64);
|
let mapped_weight = map_platform_values_to_style_values(&mapping, weight as f64);
|
||||||
|
|
|
@ -91,9 +91,9 @@ pub trait WorkerEventLoopMethods {
|
||||||
fn task_queue(&self) -> &TaskQueue<Self::WorkerMsg>;
|
fn task_queue(&self) -> &TaskQueue<Self::WorkerMsg>;
|
||||||
fn handle_event(&self, event: Self::Event) -> bool;
|
fn handle_event(&self, event: Self::Event) -> bool;
|
||||||
fn handle_worker_post_event(&self, worker: &TrustedWorkerAddress) -> Option<AutoWorkerReset>;
|
fn handle_worker_post_event(&self, worker: &TrustedWorkerAddress) -> Option<AutoWorkerReset>;
|
||||||
fn from_control_msg(&self, msg: Self::ControlMsg) -> Self::Event;
|
fn from_control_msg(msg: Self::ControlMsg) -> Self::Event;
|
||||||
fn from_worker_msg(&self, msg: Self::WorkerMsg) -> Self::Event;
|
fn from_worker_msg(msg: Self::WorkerMsg) -> Self::Event;
|
||||||
fn from_devtools_msg(&self, msg: DevtoolScriptControlMsg) -> Self::Event;
|
fn from_devtools_msg(msg: DevtoolScriptControlMsg) -> Self::Event;
|
||||||
fn control_receiver(&self) -> &Receiver<Self::ControlMsg>;
|
fn control_receiver(&self) -> &Receiver<Self::ControlMsg>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,13 +114,13 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
|
||||||
.map(|_| scope.from_devtools_receiver());
|
.map(|_| scope.from_devtools_receiver());
|
||||||
let task_queue = worker_scope.task_queue();
|
let task_queue = worker_scope.task_queue();
|
||||||
let event = select! {
|
let event = select! {
|
||||||
recv(worker_scope.control_receiver()) -> msg => worker_scope.from_control_msg(msg.unwrap()),
|
recv(worker_scope.control_receiver()) -> msg => T::from_control_msg(msg.unwrap()),
|
||||||
recv(task_queue.select()) -> msg => {
|
recv(task_queue.select()) -> msg => {
|
||||||
task_queue.take_tasks(msg.unwrap());
|
task_queue.take_tasks(msg.unwrap());
|
||||||
worker_scope.from_worker_msg(task_queue.recv().unwrap())
|
T::from_worker_msg(task_queue.recv().unwrap())
|
||||||
},
|
},
|
||||||
recv(devtools_port.unwrap_or(&crossbeam_channel::never())) -> msg =>
|
recv(devtools_port.unwrap_or(&crossbeam_channel::never())) -> msg =>
|
||||||
worker_scope.from_devtools_msg(msg.unwrap()),
|
T::from_devtools_msg(msg.unwrap()),
|
||||||
};
|
};
|
||||||
let mut sequential = vec![];
|
let mut sequential = vec![];
|
||||||
sequential.push(event);
|
sequential.push(event);
|
||||||
|
@ -136,9 +136,9 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
|
||||||
Err(_) => match devtools_port.map(|port| port.try_recv()) {
|
Err(_) => match devtools_port.map(|port| port.try_recv()) {
|
||||||
None => {},
|
None => {},
|
||||||
Some(Err(_)) => break,
|
Some(Err(_)) => break,
|
||||||
Some(Ok(ev)) => sequential.push(worker_scope.from_devtools_msg(ev)),
|
Some(Ok(ev)) => sequential.push(T::from_devtools_msg(ev)),
|
||||||
},
|
},
|
||||||
Ok(ev) => sequential.push(worker_scope.from_worker_msg(ev)),
|
Ok(ev) => sequential.push(T::from_worker_msg(ev)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Step 3
|
// Step 3
|
||||||
|
|
|
@ -195,3 +195,9 @@ where
|
||||||
rval.set(ObjectValue(js_object.handle().get()));
|
rval.set(ObjectValue(js_object.handle().get()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K: RecordKey, V> Default for Record<K, V> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -98,6 +98,12 @@ impl BluetoothExtraPermissionData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for BluetoothExtraPermissionData {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct BluetoothContext<T: AsyncBluetoothListener + DomObject> {
|
struct BluetoothContext<T: AsyncBluetoothListener + DomObject> {
|
||||||
promise: Option<TrustedPromise>,
|
promise: Option<TrustedPromise>,
|
||||||
receiver: Trusted<T>,
|
receiver: Trusted<T>,
|
||||||
|
|
|
@ -219,15 +219,15 @@ impl WorkerEventLoopMethods for DedicatedWorkerGlobalScope {
|
||||||
Some(ar)
|
Some(ar)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_control_msg(&self, msg: DedicatedWorkerControlMsg) -> MixedMessage {
|
fn from_control_msg(msg: DedicatedWorkerControlMsg) -> MixedMessage {
|
||||||
MixedMessage::Control(msg)
|
MixedMessage::Control(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_worker_msg(&self, msg: DedicatedWorkerScriptMsg) -> MixedMessage {
|
fn from_worker_msg(msg: DedicatedWorkerScriptMsg) -> MixedMessage {
|
||||||
MixedMessage::Worker(msg)
|
MixedMessage::Worker(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_devtools_msg(&self, msg: DevtoolScriptControlMsg) -> MixedMessage {
|
fn from_devtools_msg(msg: DevtoolScriptControlMsg) -> MixedMessage {
|
||||||
MixedMessage::Devtools(msg)
|
MixedMessage::Devtools(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -994,8 +994,8 @@ impl Document {
|
||||||
// (like Acid2).
|
// (like Acid2).
|
||||||
let device_pixel_ratio = self.window.device_pixel_ratio().get();
|
let device_pixel_ratio = self.window.device_pixel_ratio().get();
|
||||||
(
|
(
|
||||||
rect.origin.x.to_nearest_pixel(device_pixel_ratio) as f32,
|
rect.origin.x.to_nearest_pixel(device_pixel_ratio),
|
||||||
rect.origin.y.to_nearest_pixel(device_pixel_ratio) as f32,
|
rect.origin.y.to_nearest_pixel(device_pixel_ratio),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
|
|
|
@ -238,7 +238,7 @@ impl ElementInternalsMethods for ElementInternals {
|
||||||
if bits.is_empty() {
|
if bits.is_empty() {
|
||||||
self.set_validation_message(DOMString::new());
|
self.set_validation_message(DOMString::new());
|
||||||
} else {
|
} else {
|
||||||
self.set_validation_message(message.unwrap_or_else(DOMString::new));
|
self.set_validation_message(message.unwrap_or_default());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6: If element's customError validity flag is true, then set element's custom validity error
|
// Step 6: If element's customError validity flag is true, then set element's custom validity error
|
||||||
|
|
|
@ -218,3 +218,9 @@ impl Identities {
|
||||||
self.select(id.backend()).render_bundles.free(id);
|
self.select(id.backend()).render_bundles.free(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Identities {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1325,7 +1325,7 @@ pub trait LayoutNodeHelpers<'dom> {
|
||||||
fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>;
|
fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>;
|
||||||
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||||
|
|
||||||
fn is_element_for_layout(self) -> bool;
|
fn is_element_for_layout(&self) -> bool;
|
||||||
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
||||||
unsafe fn set_flag(self, flag: NodeFlags, value: bool);
|
unsafe fn set_flag(self, flag: NodeFlags, value: bool);
|
||||||
|
|
||||||
|
@ -1387,8 +1387,8 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_element_for_layout(self) -> bool {
|
fn is_element_for_layout(&self) -> bool {
|
||||||
self.is::<Element>()
|
(*self).is::<Element>()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -81,8 +81,7 @@ impl OfflineAudioContext {
|
||||||
if channel_count > MAX_CHANNEL_COUNT ||
|
if channel_count > MAX_CHANNEL_COUNT ||
|
||||||
channel_count == 0 ||
|
channel_count == 0 ||
|
||||||
length == 0 ||
|
length == 0 ||
|
||||||
sample_rate < MIN_SAMPLE_RATE ||
|
!(MIN_SAMPLE_RATE..=MAX_SAMPLE_RATE).contains(&sample_rate)
|
||||||
sample_rate > MAX_SAMPLE_RATE
|
|
||||||
{
|
{
|
||||||
return Err(Error::NotSupported);
|
return Err(Error::NotSupported);
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,15 +201,15 @@ impl WorkerEventLoopMethods for ServiceWorkerGlobalScope {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_control_msg(&self, msg: ServiceWorkerControlMsg) -> MixedMessage {
|
fn from_control_msg(msg: ServiceWorkerControlMsg) -> MixedMessage {
|
||||||
MixedMessage::Control(msg)
|
MixedMessage::Control(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_worker_msg(&self, msg: ServiceWorkerScriptMsg) -> MixedMessage {
|
fn from_worker_msg(msg: ServiceWorkerScriptMsg) -> MixedMessage {
|
||||||
MixedMessage::ServiceWorker(msg)
|
MixedMessage::ServiceWorker(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_devtools_msg(&self, msg: DevtoolScriptControlMsg) -> MixedMessage {
|
fn from_devtools_msg(msg: DevtoolScriptControlMsg) -> MixedMessage {
|
||||||
MixedMessage::Devtools(msg)
|
MixedMessage::Devtools(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,6 @@ impl Tokenizer {
|
||||||
tokenizer
|
tokenizer
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
||||||
let mut send_tendrils = VecDeque::new();
|
let mut send_tendrils = VecDeque::new();
|
||||||
while let Some(str) = input.pop_front() {
|
while let Some(str) = input.pop_front() {
|
||||||
|
|
|
@ -78,7 +78,6 @@ impl Tokenizer {
|
||||||
Tokenizer { inner }
|
Tokenizer { inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
||||||
match self.inner.feed(input) {
|
match self.inner.feed(input) {
|
||||||
TokenizerResult::Done => TokenizerResult::Done,
|
TokenizerResult::Done => TokenizerResult::Done,
|
||||||
|
|
|
@ -698,7 +698,6 @@ enum Tokenizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tokenizer {
|
impl Tokenizer {
|
||||||
#[must_use]
|
|
||||||
fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
||||||
match *self {
|
match *self {
|
||||||
Tokenizer::Html(ref mut tokenizer) => tokenizer.feed(input),
|
Tokenizer::Html(ref mut tokenizer) => tokenizer.feed(input),
|
||||||
|
|
|
@ -41,7 +41,6 @@ impl Tokenizer {
|
||||||
Tokenizer { inner: tok }
|
Tokenizer { inner: tok }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
||||||
self.inner.run(input);
|
self.inner.run(input);
|
||||||
match self.inner.sink.sink.script.take() {
|
match self.inner.sink.sink.script.take() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue