Skip to content

Commit

Permalink
Clippy polish
Browse files Browse the repository at this point in the history
  • Loading branch information
hunger committed Jun 23, 2023
1 parent 7da6f98 commit e115d1e
Show file tree
Hide file tree
Showing 74 changed files with 361 additions and 419 deletions.
2 changes: 1 addition & 1 deletion api/rs/macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn fill_token_vec(stream: impl Iterator<Item = TokenTree>, vec: &mut Vec<parser:
let f = s.chars().next().unwrap();
let kind = if f == '"' {
SyntaxKind::StringLiteral
} else if f.is_digit(10) {
} else if f.is_ascii_digit() {
if let Some(last) = vec.last_mut() {
if (last.kind == SyntaxKind::ColorLiteral && last.text.len() == 1)
|| (last.kind == SyntaxKind::Identifier
Expand Down
1 change: 0 additions & 1 deletion examples/energy-monitor/src/controllers/weather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ fn display_forecast(window_weak: Weak<MainWindow>, forecast: Vec<(ForecastDay, S
absolute_min: min_temp.round() as i32,
unit: SharedString::from("°"),
icon: get_icon(&window, &forecast_day.day.condition),
..Default::default()
};

forecast_model.push(model);
Expand Down
6 changes: 4 additions & 2 deletions helper_crates/vtable/macro/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub fn vtable(_attr: TokenStream, item: TokenStream) -> TokenStream {

// Check if this is a constructor functions
if let ReturnType::Type(_, ret) = &f.output {
if match_generic_type(&**ret, "VBox", &vtable_name) {
if match_generic_type(ret, "VBox", &vtable_name) {
// Change VBox<VTable> to Self
sig.output = parse_str("-> Self").unwrap();
wrap_trait_call = Some(quote! {
Expand Down Expand Up @@ -561,7 +561,9 @@ pub fn vtable(_attr: TokenStream, item: TokenStream) -> TokenStream {
ReturnType::Default => quote!(),
// If the return type contains a implicit lifetime, it is safe to erase it while returning it
// because a sound implementation of the trait wouldn't allow unsound things here
ReturnType::Type(_, r) => quote!(core::mem::transmute::<#r, #r>),
ReturnType::Type(_, r) => {
quote!(#[allow(clippy::useless_transmute)] core::mem::transmute::<#r, #r>)
}
};
vtable_ctor.push(quote!(#ident: {
#sig_extern {
Expand Down
4 changes: 2 additions & 2 deletions helper_crates/vtable/src/vrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<VTable: VTableMetaDropInPlace, X> VRc<VTable, X> {
///
/// This is safe because we don't allow mutable reference to the inner
pub fn as_pin_ref(&self) -> Pin<&X> {
unsafe { Pin::new_unchecked(&*self) }
unsafe { Pin::new_unchecked(self) }
}

/// Gets a VRef pointing to this instance
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<VTable: VTableMetaDropInPlace + 'static, MappedType: ?Sized> VRcMapped<VTab
///
/// This is safe because the map function returns a pinned reference.
pub fn as_pin_ref(&self) -> Pin<&MappedType> {
unsafe { Pin::new_unchecked(&*self) }
unsafe { Pin::new_unchecked(self) }
}

/// This function allows safely holding a reference to a field inside the `VRcMapped`. In order to accomplish
Expand Down
3 changes: 2 additions & 1 deletion internal/backends/qt/qt_accessible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// cspell:ignore descendents qobject qwidget

use crate::accessible_generated::*;
use crate::qt_window::QtWindow;

use i_slint_core::accessibility::AccessibleStringProperty;
use i_slint_core::item_tree::{ItemRc, ItemWeak};
Expand Down Expand Up @@ -656,7 +657,7 @@ cpp! {{
~Slint_accessible_window()
{
rust!(Slint_accessible_window_dtor [m_rustWindow: *mut c_void as "void*"] {
alloc::rc::Weak::from_raw(m_rustWindow as _); // Consume the Weak we hold in our void*!
alloc::rc::Weak::from_raw(m_rustWindow as *const QtWindow); // Consume the Weak<QtWindow> we hold in our void*!
});
}

Expand Down
1 change: 1 addition & 0 deletions internal/backends/qt/qt_widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Item for NativeSlider {
InputEventFilterResult::ForwardEvent
}

#[allow(clippy::unnecessary_cast)] // MouseEvent uses Coord
fn input_event(
self: Pin<&Self>,
event: MouseEvent,
Expand Down
1 change: 0 additions & 1 deletion internal/backends/qt/qt_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ cpp! {{
text: preedit_string.to_string().into(),
preedit_selection_start: replacement_start as usize,
preedit_selection_end: replacement_start as usize + replacement_length as usize,
..Default::default()
};
runtime_window.process_key_input(event);

Expand Down
6 changes: 3 additions & 3 deletions internal/backends/testing/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl RendererSealed for TestingWindow {
/// Must be called before any call that would otherwise initialize the rendering backend.
/// Calling it when the rendering backend is already initialized will have no effects
pub fn init() {
i_slint_core::platform::set_platform(Box::new(TestingBackend::default()))
i_slint_core::platform::set_platform(Box::<TestingBackend>::default())
.expect("platform already initialized");
}

Expand Down Expand Up @@ -242,11 +242,11 @@ pub fn access_testing_window<R>(
window: &i_slint_core::api::Window,
callback: impl FnOnce(&TestingWindow) -> R,
) -> R {
i_slint_core::window::WindowInner::from_pub(&window)
i_slint_core::window::WindowInner::from_pub(window)
.window_adapter()
.internal(i_slint_core::InternalToken)
.and_then(|wa| wa.as_any().downcast_ref::<TestingWindow>())
.map(|adapter| callback(adapter))
.map(callback)
.expect("access_testing_window called without testing backend/adapter")
}

Expand Down
13 changes: 5 additions & 8 deletions internal/backends/winit/accesskit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,14 @@ impl AccessKitAdapter {

fn handle_request(&self, request: ActionRequest) {
let Some(window_adapter) = self.window_adapter_weak.upgrade() else { return };
match request.action {
Action::Focus => {
if let Some(item) = self.item_rc_for_node_id(request.target) {
WindowInner::from_pub(window_adapter.window()).set_focus_item(&item);
}
if request.action == Action::Focus {
if let Some(item) = self.item_rc_for_node_id(request.target) {
WindowInner::from_pub(window_adapter.window()).set_focus_item(&item);
}
_ => {}
}
}

pub fn register_component<'a>(&self) {
pub fn register_component(&self) {
let win = self.window_adapter_weak.clone();
i_slint_core::timers::Timer::single_shot(Default::default(), move || {
if let Some(window_adapter) = win.upgrade() {
Expand All @@ -138,7 +135,7 @@ impl AccessKitAdapter {
});
}

pub fn unregister_component<'a>(&self, component: ComponentRef) {
pub fn unregister_component(&self, component: ComponentRef) {
let component_ptr = ComponentRef::as_ptr(component);
if let Some(component_id) = self.component_ids.borrow_mut().remove(&component_ptr) {
self.components_by_id.borrow_mut().remove(&component_id);
Expand Down
1 change: 0 additions & 1 deletion internal/backends/winit/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ fn process_window_event(
text: string.into(),
preedit_selection_start: preedit_selection.0,
preedit_selection_end: preedit_selection.1,
..Default::default()
};
runtime_window.process_key_input(event);
}
Expand Down
1 change: 1 addition & 0 deletions internal/backends/winit/winitwindowadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl WindowAdapter for WinitWindowAdapter {
}

impl WindowAdapterInternal for WinitWindowAdapter {
#[allow(clippy::unnecessary_cast)] // Coord is used!
fn apply_window_properties(&self, window_item: Pin<&i_slint_core::items::WindowItem>) {
let winit_window = self.winit_window();

Expand Down
24 changes: 11 additions & 13 deletions internal/common/sharedfontdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,22 @@ impl FontDatabase {
query: fontdb::Query<'_>,
family: Option<&'_ str>,
) -> Option<fontdb::ID> {
let mut query = query.clone();
let mut query = query;
if let Some(specified_family) = family {
let single_family = [fontdb::Family::Name(specified_family)];
query.families = &single_family;
self.db.query(&query)
} else if self.default_font_family_ids.is_empty() {
query.families = &[fontdb::Family::SansSerif];
self.db.query(&query)
} else {
if self.default_font_family_ids.is_empty() {
query.families = &[fontdb::Family::SansSerif];
self.db.query(&query)
} else {
let family_storage = self
.default_font_family_names
.iter()
.map(|name| fontdb::Family::Name(name))
.collect::<Vec<_>>();
query.families = &family_storage;
self.db.query(&query)
}
let family_storage = self
.default_font_family_names
.iter()
.map(|name| fontdb::Family::Name(name))
.collect::<Vec<_>>();
query.families = &family_storage;
self.db.query(&query)
}
}
}
Expand Down
66 changes: 33 additions & 33 deletions internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,41 +766,41 @@ impl Expression {
Expression::FunctionParameterReference { .. } => {}
Expression::BuiltinFunctionReference { .. } => {}
Expression::MemberFunction { base, member, .. } => {
visitor(&**base);
visitor(&**member);
visitor(base);
visitor(member);
}
Expression::BuiltinMacroReference { .. } => {}
Expression::ElementReference(_) => {}
Expression::StructFieldAccess { base, .. } => visitor(&**base),
Expression::StructFieldAccess { base, .. } => visitor(base),
Expression::ArrayIndex { array, index } => {
visitor(&**array);
visitor(&**index);
visitor(array);
visitor(index);
}
Expression::RepeaterIndexReference { .. } => {}
Expression::RepeaterModelReference { .. } => {}
Expression::Cast { from, .. } => visitor(&**from),
Expression::Cast { from, .. } => visitor(from),
Expression::CodeBlock(sub) => {
sub.iter().for_each(visitor);
}
Expression::FunctionCall { function, arguments, source_location: _ } => {
visitor(&**function);
visitor(function);
arguments.iter().for_each(visitor);
}
Expression::SelfAssignment { lhs, rhs, .. } => {
visitor(&**lhs);
visitor(&**rhs);
visitor(lhs);
visitor(rhs);
}
Expression::ImageReference { .. } => {}
Expression::Condition { condition, true_expr, false_expr } => {
visitor(&**condition);
visitor(&**true_expr);
visitor(&**false_expr);
visitor(condition);
visitor(true_expr);
visitor(false_expr);
}
Expression::BinaryExpression { lhs, rhs, .. } => {
visitor(&**lhs);
visitor(&**rhs);
visitor(lhs);
visitor(rhs);
}
Expression::UnaryOp { sub, .. } => visitor(&**sub),
Expression::UnaryOp { sub, .. } => visitor(sub),
Expression::Array { values, .. } => {
for x in values {
visitor(x);
Expand All @@ -822,7 +822,7 @@ impl Expression {
}
Path::Commands(commands) => visitor(commands),
},
Expression::StoreLocalVariable { value, .. } => visitor(&**value),
Expression::StoreLocalVariable { value, .. } => visitor(value),
Expression::ReadLocalVariable { .. } => {}
Expression::EasingCurve(_) => {}
Expression::LinearGradient { angle, stops } => {
Expand Down Expand Up @@ -863,41 +863,41 @@ impl Expression {
Expression::FunctionParameterReference { .. } => {}
Expression::BuiltinFunctionReference { .. } => {}
Expression::MemberFunction { base, member, .. } => {
visitor(&mut **base);
visitor(&mut **member);
visitor(base);
visitor(member);
}
Expression::BuiltinMacroReference { .. } => {}
Expression::ElementReference(_) => {}
Expression::StructFieldAccess { base, .. } => visitor(&mut **base),
Expression::StructFieldAccess { base, .. } => visitor(base),
Expression::ArrayIndex { array, index } => {
visitor(&mut **array);
visitor(&mut **index);
visitor(array);
visitor(index);
}
Expression::RepeaterIndexReference { .. } => {}
Expression::RepeaterModelReference { .. } => {}
Expression::Cast { from, .. } => visitor(&mut **from),
Expression::Cast { from, .. } => visitor(from),
Expression::CodeBlock(sub) => {
sub.iter_mut().for_each(visitor);
}
Expression::FunctionCall { function, arguments, source_location: _ } => {
visitor(&mut **function);
visitor(function);
arguments.iter_mut().for_each(visitor);
}
Expression::SelfAssignment { lhs, rhs, .. } => {
visitor(&mut **lhs);
visitor(&mut **rhs);
visitor(lhs);
visitor(rhs);
}
Expression::ImageReference { .. } => {}
Expression::Condition { condition, true_expr, false_expr } => {
visitor(&mut **condition);
visitor(&mut **true_expr);
visitor(&mut **false_expr);
visitor(condition);
visitor(true_expr);
visitor(false_expr);
}
Expression::BinaryExpression { lhs, rhs, .. } => {
visitor(&mut **lhs);
visitor(&mut **rhs);
visitor(lhs);
visitor(rhs);
}
Expression::UnaryOp { sub, .. } => visitor(&mut **sub),
Expression::UnaryOp { sub, .. } => visitor(sub),
Expression::Array { values, .. } => {
for x in values {
visitor(x);
Expand All @@ -922,11 +922,11 @@ impl Expression {
}
Path::Commands(commands) => visitor(commands),
},
Expression::StoreLocalVariable { value, .. } => visitor(&mut **value),
Expression::StoreLocalVariable { value, .. } => visitor(value),
Expression::ReadLocalVariable { .. } => {}
Expression::EasingCurve(_) => {}
Expression::LinearGradient { angle, stops } => {
visitor(&mut *angle);
visitor(angle);
for (c, s) in stops {
visitor(c);
visitor(s);
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler/fileaccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct VirtualFile {
pub builtin_contents: Option<&'static [u8]>,
}

impl<'a> VirtualFile {
impl VirtualFile {
pub fn read(&self) -> Cow<'static, [u8]> {
match self.builtin_contents {
Some(static_data) => Cow::Borrowed(static_data),
Expand All @@ -26,7 +26,7 @@ pub fn styles() -> Vec<&'static str> {
builtin_library::styles()
}

pub fn load_file<'a>(path: &'a std::path::Path) -> Option<VirtualFile> {
pub fn load_file(path: &std::path::Path) -> Option<VirtualFile> {
match path.strip_prefix("builtin:/") {
Ok(builtin_path) => builtin_library::load_builtin_file(builtin_path),
Err(_) => path.exists().then(|| VirtualFile {
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pub fn build_item_tree<T: ItemTreeBuilder>(
fn visit_children<T: ItemTreeBuilder>(
state: &T::SubComponentState,
children: &[ElementRc],
component: &Rc<Component>,
_component: &Rc<Component>,
parent_item: &ElementRc,
parent_index: u32,
relative_parent_index: u32,
Expand Down Expand Up @@ -290,7 +290,7 @@ pub fn build_item_tree<T: ItemTreeBuilder>(
visit_children(
state,
&e.borrow().children,
component,
_component,
e,
index,
relative_index,
Expand Down

0 comments on commit e115d1e

Please sign in to comment.