diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 750dfb93b..b941960b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: override: true - uses: Swatinem/rust-cache@v1 - run: sudo apt-get update - - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev libappindicator3-dev + - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev - uses: actions-rs/cargo@v1 with: command: check @@ -32,7 +32,7 @@ jobs: override: true - uses: Swatinem/rust-cache@v1 - run: sudo apt-get update - - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev libappindicator3-dev + - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev - uses: actions-rs/cargo@v1 with: command: test @@ -55,21 +55,21 @@ jobs: command: fmt args: --all -- --check - # clippy: - # name: Clippy - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v2 - # - uses: actions-rs/toolchain@v1 - # with: - # profile: minimal - # toolchain: stable - # override: true - # - uses: Swatinem/rust-cache@v1 - # - run: rustup component add clippy - # - uses: actions-rs/cargo@v1 - # with: - # command: clippy - # args: -- -D warnings -# -# sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev libappindicator3-dev + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - uses: Swatinem/rust-cache@v1 + - run: sudo apt-get update + - run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev + - run: rustup component add clippy + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/packages/core-macro/src/ifmt.rs b/packages/core-macro/src/ifmt.rs index 71b8bdee6..912d78f7e 100644 --- a/packages/core-macro/src/ifmt.rs +++ b/packages/core-macro/src/ifmt.rs @@ -41,7 +41,7 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result { let mut out_format_literal = defer(&mut *out_format_literal, |it| { it.push(colon_or_closing_brace) }); - let out_format_literal: &mut String = &mut *out_format_literal; + let out_format_literal: &mut String = *out_format_literal; let mut arg = s[i + 1..end].trim(); if let Some("=") = arg.get(arg.len().saturating_sub(1)..) { assert_eq!( diff --git a/packages/core-macro/src/props/mod.rs b/packages/core-macro/src/props/mod.rs index c2b667524..8e922ea8a 100644 --- a/packages/core-macro/src/props/mod.rs +++ b/packages/core-macro/src/props/mod.rs @@ -270,7 +270,7 @@ mod field_info { pub setter: SetterSettings, } - #[derive(Debug, Clone)] + #[derive(Debug, Clone, Default)] pub struct SetterSettings { pub doc: Option, pub skip: bool, @@ -278,17 +278,6 @@ mod field_info { pub strip_option: bool, } - impl Default for SetterSettings { - fn default() -> Self { - Self { - doc: Default::default(), - skip: false, - auto_into: false, - strip_option: false, - } - } - } - impl FieldBuilderAttr { pub fn with(mut self, attrs: &[syn::Attribute]) -> Result { let mut skip_tokens = None; diff --git a/packages/core-macro/src/rsx/component.rs b/packages/core-macro/src/rsx/component.rs index 13bcd30d3..e8696504b 100644 --- a/packages/core-macro/src/rsx/component.rs +++ b/packages/core-macro/src/rsx/component.rs @@ -181,7 +181,7 @@ impl Parse for ComponentField { return Ok(Self { name, content }); } - if name.to_string() == "key" { + if name == "key" { let content = ContentField::ManExpr(input.parse()?); return Ok(Self { name, content }); } diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index bd4dc34ff..65511470e 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -745,6 +745,7 @@ impl ScopeState { /// use_hook(|| Rc::new(RefCell::new(initial_value()))) /// } /// ``` + #[allow(clippy::mut_from_ref)] pub fn use_hook<'src, State: 'static>( &'src self, initializer: impl FnOnce(usize) -> State, diff --git a/packages/desktop/src/cfg.rs b/packages/desktop/src/cfg.rs index 49d781465..60e3ff887 100644 --- a/packages/desktop/src/cfg.rs +++ b/packages/desktop/src/cfg.rs @@ -4,11 +4,13 @@ use wry::{ webview::WebView, }; +pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView); + pub struct DesktopConfig<'a> { pub window: WindowBuilder, pub(crate) manual_edits: Option>>, pub(crate) pre_rendered: Option, - pub(crate) event_handler: Option, &mut WebView)>>, + pub(crate) event_handler: Option>, } impl<'a> DesktopConfig<'a> { @@ -55,3 +57,9 @@ impl<'a> DesktopConfig<'a> { self } } + +impl<'a> Default for DesktopConfig<'a> { + fn default() -> Self { + Self::new() + } +} diff --git a/packages/hooks/src/use_shared_state.rs b/packages/hooks/src/use_shared_state.rs index 3d25a5ac3..9b59601b5 100644 --- a/packages/hooks/src/use_shared_state.rs +++ b/packages/hooks/src/use_shared_state.rs @@ -171,7 +171,7 @@ where /// /// /// -pub fn use_context_provider<'a, T: 'static>(cx: &'a ScopeState, f: impl FnOnce() -> T) { +pub fn use_context_provider(cx: &ScopeState, f: impl FnOnce() -> T) { cx.use_hook(|_| { let state: ProvidedState = RefCell::new(ProvidedStateInner { value: Rc::new(RefCell::new(f())), diff --git a/packages/hooks/src/usecoroutine.rs b/packages/hooks/src/usecoroutine.rs index 737f3c2a5..7faf507ed 100644 --- a/packages/hooks/src/usecoroutine.rs +++ b/packages/hooks/src/usecoroutine.rs @@ -15,10 +15,7 @@ let g = use_coroutine(&cx, || { */ -pub fn use_coroutine<'a, F>( - cx: &'a ScopeState, - create_future: impl FnOnce() -> F, -) -> CoroutineHandle<'a> +pub fn use_coroutine(cx: &ScopeState, create_future: impl FnOnce() -> F) -> CoroutineHandle<'_> where F: Future + 'static, { @@ -98,6 +95,7 @@ impl Clone for CoroutineHandle<'_> { impl Copy for CoroutineHandle<'_> {} impl<'a> CoroutineHandle<'a> { + #[allow(clippy::needless_return)] pub fn start(&self) { if self.is_running() { return; diff --git a/packages/hooks/src/useref.rs b/packages/hooks/src/useref.rs index 9a5d9ffb9..3ddf86e8c 100644 --- a/packages/hooks/src/useref.rs +++ b/packages/hooks/src/useref.rs @@ -6,12 +6,10 @@ use std::{ use dioxus_core::ScopeState; pub fn use_ref<'a, T: 'static>(cx: &'a ScopeState, f: impl FnOnce() -> T) -> &'a UseRef { - let inner = cx.use_hook(|_| UseRef { + cx.use_hook(|_| UseRef { update_callback: cx.schedule_update(), value: Rc::new(RefCell::new(f())), - }); - - inner + }) } pub struct UseRef { diff --git a/packages/hooks/src/usesuspense.rs b/packages/hooks/src/usesuspense.rs index dfd37ac7a..834871304 100644 --- a/packages/hooks/src/usesuspense.rs +++ b/packages/hooks/src/usesuspense.rs @@ -27,7 +27,7 @@ pub fn use_suspense + 'static>( }); if let Some(value) = sus.value.as_ref() { - render(&value) + render(value) } else { // generate a placeholder node if the future isnt ready None diff --git a/packages/router/src/components/link.rs b/packages/router/src/components/link.rs index 5a97c657c..417b77525 100644 --- a/packages/router/src/components/link.rs +++ b/packages/router/src/components/link.rs @@ -46,7 +46,7 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element { id: format_args!("{}", cx.props.id.unwrap_or("")), prevent_default: "onclick", - onclick: move |_| service.push_route(cx.props.to.clone()), + onclick: move |_| service.push_route(cx.props.to), &cx.props.children } diff --git a/packages/router/src/components/route.rs b/packages/router/src/components/route.rs index 2b687a868..2d9a270b8 100644 --- a/packages/router/src/components/route.rs +++ b/packages/router/src/components/route.rs @@ -27,8 +27,8 @@ pub fn Route<'a>(cx: Scope<'a, RouteProps<'a>>) -> Element { cx.use_hook(|_| { // create a bigger, better, longer route if one above us exists let total_route = match cx.consume_context::() { - Some(ctx) => format!("{}", ctx.total_route.clone()), - None => format!("{}", cx.props.to.clone()), + Some(ctx) => ctx.total_route.to_string(), + None => cx.props.to.to_string(), }; // provide our route context diff --git a/packages/router/src/lib.rs b/packages/router/src/lib.rs index 23d1c4a07..b6ffb5971 100644 --- a/packages/router/src/lib.rs +++ b/packages/router/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(warnings)] //! Dioxus-Router //! //! A simple match-based router and router service for most routing needs. diff --git a/packages/ssr/src/lib.rs b/packages/ssr/src/lib.rs index 67537195c..bda95cd40 100644 --- a/packages/ssr/src/lib.rs +++ b/packages/ssr/src/lib.rs @@ -24,7 +24,7 @@ impl SsrRenderer { pub fn render_lazy<'a>(&'a mut self, f: LazyNodes<'a, '_>) -> String { let scope = self.vdom.base_scope(); - let factory = NodeFactory::new(&scope); + let factory = NodeFactory::new(scope); let root = f.into_vnode(factory); format!( @@ -38,6 +38,7 @@ impl SsrRenderer { } } +#[allow(clippy::needless_lifetimes)] pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String { let vdom = VirtualDom::new(app); let scope: *const ScopeState = vdom.base_scope(); @@ -50,11 +51,11 @@ pub fn render_lazy<'a>(f: LazyNodes<'a, '_>) -> String { // When LazyNodes are provided, they are FnOnce, but do not come with a allocator selected to borrow from. The <'a> // lifetime is therefore longer than the lifetime of the allocator which doesn't exist... yet. // - // Therefore, we cast our local bump alloactor into right lifetime. This is okay because our usage of the bump arena - // is *definitely* shorter than the <'a> lifetime, and we return *owned* data - not borrowed data. + // Therefore, we cast our local bump allocator to the right lifetime. This is okay because our usage of the bump + // arena is *definitely* shorter than the <'a> lifetime, and we return *owned* data - not borrowed data. let scope = unsafe { &*scope }; - let root = f.into_vnode(NodeFactory::new(&scope)); + let root = f.into_vnode(NodeFactory::new(scope)); format!( "{:}",