Merge branch 'fix-new-clippy-lints' into fix-new-signals-in-effects

This commit is contained in:
Evan Almloff committed 2023-08-28 15:47:45 -05:00
commit c32875337c
11 files changed
+125 -108

No files matched your search

+22 -24
View File
@@ -85,52 +85,56 @@ jobs:
matrix_test: matrix_test:
runs-on: ${{ matrix.platform.os }} runs-on: ${{ matrix.platform.os }}
env:
RUST_CARGO_COMMAND: ${{ matrix.platform.cross == true && 'cross' || 'cargo' }}
strategy: strategy:
matrix: matrix:
platform: platform:
- { - {
target: x86_64-pc-windows-msvc, target: x86_64-pc-windows-msvc,
os: windows-latest, os: windows-latest,
toolchain: '1.70.0', toolchain: "1.70.0",
cross: false, cross: false,
command: 'test', command: "test",
args: '--all --tests' args: "--all --tests",
} }
- { - {
target: x86_64-apple-darwin, target: x86_64-apple-darwin,
os: macos-latest, os: macos-latest,
toolchain: '1.70.0', toolchain: "1.70.0",
cross: false, cross: false,
command: 'test', command: "test",
args: '--all --tests' args: "--all --tests",
} }
- { - {
target: aarch64-apple-ios, target: aarch64-apple-ios,
os: macos-latest, os: macos-latest,
toolchain: '1.70.0', toolchain: "1.70.0",
cross: false, cross: false,
command: 'build', command: "build",
args: '--package dioxus-mobile' args: "--package dioxus-mobile",
} }
- { - {
target: aarch64-linux-android, target: aarch64-linux-android,
os: ubuntu-latest, os: ubuntu-latest,
toolchain: '1.70.0', toolchain: "1.70.0",
cross: true, cross: true,
command: 'build', command: "build",
args: '--package dioxus-mobile' args: "--package dioxus-mobile",
} }
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: install stable - name: install stable
uses: actions-rs/toolchain@v1 uses: dtolnay/rust-toolchain@master
with: with:
toolchain: ${{ matrix.platform.toolchain }} toolchain: ${{ matrix.platform.toolchain }}
target: ${{ matrix.platform.target }} targets: ${{ matrix.platform.target }}
override: true
default: true - name: Install cross
if: ${{ matrix.platform.cross == true }}
uses: taiki-e/install-action@cross
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
@@ -138,13 +142,8 @@ jobs:
save-if: ${{ matrix.features.key == 'all' }} save-if: ${{ matrix.features.key == 'all' }}
- name: test - name: test
uses: actions-rs/cargo@v1 run: |
with: ${{ env.RUST_CARGO_COMMAND }} ${{ matrix.platform.command }} ${{ matrix.platform.args }} --target ${{ matrix.platform.target }}
use-cross: ${{ matrix.platform.cross }}
command: ${{ matrix.platform.command }}
args: --target ${{ matrix.platform.target }} ${{ matrix.platform.args }}
# Coverage is disabled until we can fix it # Coverage is disabled until we can fix it
# coverage: # coverage:
@@ -166,4 +165,3 @@ jobs:
# uses: codecov/codecov-action@v2 # uses: codecov/codecov-action@v2
# with: # with:
# fail_ci_if_error: false # fail_ci_if_error: false
+34 -37
View File
@@ -1,9 +1,9 @@
name: Playwright Tests name: Playwright Tests
on: on:
push: push:
branches: [ main, master ] branches: [main, master]
pull_request: pull_request:
branches: [ main, master ] branches: [main, master]
defaults: defaults:
run: run:
working-directory: ./playwright-tests working-directory: ./playwright-tests
@@ -16,39 +16,36 @@ jobs:
test: test:
if: github.event.pull_request.draft == false if: github.event.pull_request.draft == false
timeout-minutes: 60 timeout-minutes: 60
runs-on: ubuntu-20.04 runs-on: ubuntu-latest
steps: steps:
# Do our best to cache the toolchain and node install steps # Do our best to cache the toolchain and node install steps
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-node@v3 - uses: actions/setup-node@v3
with: with:
node-version: 16 node-version: 16
- name: Install Rust - name: Install Rust
uses: actions-rs/toolchain@v1 uses: dtolnay/rust-toolchain@master
with: with:
profile: minimal toolchain: stable
toolchain: stable targets: x86_64-unknown-linux-gnu,wasm32-unknown-unknown
override: true - uses: Swatinem/rust-cache@v2
- uses: Swatinem/rust-cache@v2 - name: Install dependencies
- name: Install WASM toolchain run: npm ci
run: rustup target add wasm32-unknown-unknown - name: Install Playwright
- name: Install dependencies run: npm install -D @playwright/test
run: npm ci - name: Install Playwright Browsers
- name: Install Playwright run: npx playwright install --with-deps
run: npm install -D @playwright/test # Cache the CLI by using cargo run internally
- name: Install Playwright Browsers # - name: Install Dioxus CLI
run: npx playwright install --with-deps # uses: actions-rs/cargo@v1
# Cache the CLI by using cargo run internally # with:
# - name: Install Dioxus CLI # command: install
# uses: actions-rs/cargo@v1 # args: --path packages/cli
# with: - name: Run Playwright tests
# command: install run: npx playwright test
# args: --path packages/cli - uses: actions/upload-artifact@v3
- name: Run Playwright tests if: always()
run: npx playwright test with:
- uses: actions/upload-artifact@v3 name: playwright-report
if: always() path: playwright-report/
with: retention-days: 30
name: playwright-report
path: playwright-report/
retention-days: 30
+2 -2
View File
@@ -50,12 +50,12 @@ members = [
exclude = ["examples/mobile_demo"] exclude = ["examples/mobile_demo"]
[workspace.package] [workspace.package]
version = "0.4.1" version = "0.4.2"
# dependencies that are shared across packages # dependencies that are shared across packages
[workspace.dependencies] [workspace.dependencies]
dioxus = { path = "packages/dioxus", version = "0.4.0" } dioxus = { path = "packages/dioxus", version = "0.4.0" }
dioxus-core = { path = "packages/core", version = "0.4.1" } dioxus-core = { path = "packages/core", version = "0.4.2" }
dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" } dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }
dioxus-router = { path = "packages/router", version = "0.4.1" } dioxus-router = { path = "packages/router", version = "0.4.1" }
dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" } dioxus-router-macro = { path = "packages/router-macro", version = "0.4.1" }
+1 -1
View File
@@ -40,7 +40,7 @@
<span> | </span> <span> | </span>
<a href="https://github.com/DioxusLabs/example-projects"> 代码示例 </a> <a href="https://github.com/DioxusLabs/example-projects"> 代码示例 </a>
<span> | </span> <span> | </span>
<a href="https://dioxuslabs.com/guide/en"> 开发指南 </a> <a href="https://dioxuslabs.com/learn/0.4/guide"> 开发指南 </a>
<span> | </span> <span> | </span>
<a href="https://github.com/DioxusLabs/dioxus/blob/master/README.md"> English </a> <a href="https://github.com/DioxusLabs/dioxus/blob/master/README.md"> English </a>
<span> | </span> <span> | </span>
+9 -25
View File
@@ -8,47 +8,31 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1 - name: Install Rust
with: uses: dtolnay/rust-toolchain@stable
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1 - run: cargo check
with:
command: check
test: test:
name: Test Suite name: Test Suite
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1 - name: Install Rust
with: uses: dtolnay/rust-toolchain@stable
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1 - run: cargo test
with:
command: test
fmt: fmt:
name: Rustfmt name: Rustfmt
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1 - name: Install Rust
with: uses: dtolnay/rust-toolchain@stable
profile: minimal
toolchain: stable
override: true
- uses: Swatinem/rust-cache@v1 - uses: Swatinem/rust-cache@v1
- run: rustup component add rustfmt - run: rustup component add rustfmt
- uses: actions-rs/cargo@v1 - run: cargo fmt --all -- --check
with:
command: fmt
args: --all -- --check
# clippy: # clippy:
# name: Clippy # name: Clippy
@@ -0,0 +1,24 @@
use dioxus::prelude::*;
fn main() {}
fn app(cx: Scope) -> Element {
let count = vec![1, 2, 3];
render! {
unsafe_child_component {
borrowed: &count
}
}
}
#[derive(Props)]
struct Testing<'a> {
borrowed: &'a Vec<u32>,
}
fn unsafe_child_component<'a>(cx: Scope<'a, Testing<'a>>) -> Element<'a> {
cx.render(rsx! {
div { "{cx.props.borrowed:?}" }
})
}
@@ -0,0 +1,12 @@
error[E0515]: cannot return value referencing local variable `count`
--> compile_tests/props_safety_temporary_values.rs:8:5
|
8 | / render! {
9 | | unsafe_child_component {
10 | | borrowed: &count
| | ------ `count` is borrowed here
11 | | }
12 | | }
| |_____^ returns a value referencing data owned by the current function
|
= note: this error originates in the macro `render` (in Nightly builds, run with -Z macro-backtrace for more info)
+1
View File
@@ -79,4 +79,5 @@ pub fn fc_to_builder<'a, T: Properties + 'a>(_: fn(Scope<'a, T>) -> Element<'a>)
fn unsafe_props_fail() { fn unsafe_props_fail() {
let t = trybuild::TestCases::new(); let t = trybuild::TestCases::new();
t.compile_fail("compile_tests/props_safety.rs"); t.compile_fail("compile_tests/props_safety.rs");
t.compile_fail("compile_tests/props_safety_temporary_values.rs");
} }
+3 -1
View File
@@ -424,7 +424,9 @@ impl<'src> ScopeState {
fn_name: &'static str, fn_name: &'static str,
) -> DynamicNode<'src> ) -> DynamicNode<'src>
where where
P: Properties + 'child, // The properties must be valid until the next bump frame
P: Properties + 'src,
// The current bump allocator frame must outlive the child's borrowed props
'src: 'child, 'src: 'child,
{ {
let vcomp = VProps::new(component, P::memoize, props); let vcomp = VProps::new(component, P::memoize, props);
+16 -18
View File
@@ -2,7 +2,7 @@ use std::{
any::Any, any::Any,
collections::HashSet, collections::HashSet,
rc::Rc, rc::Rc,
sync::{Arc, RwLock, RwLockWriteGuard}, sync::{Arc, RwLock},
}; };
use dioxus::prelude::*; use dioxus::prelude::*;
@@ -36,7 +36,7 @@ struct MutableRouterState {
/// A collection of router data that manages all routing functionality. /// A collection of router data that manages all routing functionality.
#[derive(Clone)] #[derive(Clone)]
pub struct RouterContext { pub struct RouterContext {
state: Arc<RwLock<MutableRouterState>>, state: Rc<RefCell<MutableRouterState>>,
subscribers: Arc<RwLock<HashSet<ScopeId>>>, subscribers: Arc<RwLock<HashSet<ScopeId>>>,
subscriber_update: Arc<dyn Fn(ScopeId)>, subscriber_update: Arc<dyn Fn(ScopeId)>,
@@ -56,7 +56,7 @@ impl RouterContext {
R: Clone, R: Clone,
<R as std::str::FromStr>::Err: std::fmt::Display, <R as std::str::FromStr>::Err: std::fmt::Display,
{ {
let state = Arc::new(RwLock::new(MutableRouterState { let state = Rc::new(RefCell::new(MutableRouterState {
prefix: Default::default(), prefix: Default::default(),
history: cfg.take_history(), history: cfg.take_history(),
unresolved_error: None, unresolved_error: None,
@@ -105,7 +105,7 @@ impl RouterContext {
// set the updater // set the updater
{ {
let mut state = myself.state.write().unwrap(); let mut state = myself.state.borrow_mut();
state.history.updater(Arc::new(move || { state.history.updater(Arc::new(move || {
for &id in subscribers.read().unwrap().iter() { for &id in subscribers.read().unwrap().iter() {
(mark_dirty)(id); (mark_dirty)(id);
@@ -117,20 +117,20 @@ impl RouterContext {
} }
pub(crate) fn route_from_str(&self, route: &str) -> Result<Rc<dyn Any>, String> { pub(crate) fn route_from_str(&self, route: &str) -> Result<Rc<dyn Any>, String> {
let state = self.state.read().unwrap(); let state = self.state.borrow();
state.history.parse_route(route) state.history.parse_route(route)
} }
/// Check whether there is a previous page to navigate back to. /// Check whether there is a previous page to navigate back to.
#[must_use] #[must_use]
pub fn can_go_back(&self) -> bool { pub fn can_go_back(&self) -> bool {
self.state.read().unwrap().history.can_go_back() self.state.borrow().history.can_go_back()
} }
/// Check whether there is a future page to navigate forward to. /// Check whether there is a future page to navigate forward to.
#[must_use] #[must_use]
pub fn can_go_forward(&self) -> bool { pub fn can_go_forward(&self) -> bool {
self.state.read().unwrap().history.can_go_forward() self.state.borrow().history.can_go_forward()
} }
/// Go back to the previous location. /// Go back to the previous location.
@@ -138,7 +138,7 @@ impl RouterContext {
/// Will fail silently if there is no previous location to go to. /// Will fail silently if there is no previous location to go to.
pub fn go_back(&self) { pub fn go_back(&self) {
{ {
self.state.write().unwrap().history.go_back(); self.state.borrow_mut().history.go_back();
} }
self.change_route(); self.change_route();
@@ -149,7 +149,7 @@ impl RouterContext {
/// Will fail silently if there is no next location to go to. /// Will fail silently if there is no next location to go to.
pub fn go_forward(&self) { pub fn go_forward(&self) {
{ {
self.state.write().unwrap().history.go_forward(); self.state.borrow_mut().history.go_forward();
} }
self.change_route(); self.change_route();
@@ -206,8 +206,7 @@ impl RouterContext {
/// The route that is currently active. /// The route that is currently active.
pub fn current<R: Routable>(&self) -> R { pub fn current<R: Routable>(&self) -> R {
self.state self.state
.read() .borrow()
.unwrap()
.history .history
.current_route() .current_route()
.downcast::<R>() .downcast::<R>()
@@ -218,7 +217,7 @@ impl RouterContext {
/// The route that is currently active. /// The route that is currently active.
pub fn current_route_string(&self) -> String { pub fn current_route_string(&self) -> String {
self.any_route_to_string(&*self.state.read().unwrap().history.current_route()) self.any_route_to_string(&*self.state.borrow().history.current_route())
} }
pub(crate) fn any_route_to_string(&self, route: &dyn Any) -> String { pub(crate) fn any_route_to_string(&self, route: &dyn Any) -> String {
@@ -243,7 +242,7 @@ impl RouterContext {
/// The prefix that is currently active. /// The prefix that is currently active.
pub fn prefix(&self) -> Option<String> { pub fn prefix(&self) -> Option<String> {
self.state.read().unwrap().prefix.clone() self.state.borrow().prefix.clone()
} }
fn external(&self, external: String) -> Option<ExternalNavigationFailure> { fn external(&self, external: String) -> Option<ExternalNavigationFailure> {
@@ -261,8 +260,8 @@ impl RouterContext {
} }
} }
fn state_mut(&self) -> RwLockWriteGuard<MutableRouterState> { fn state_mut(&self) -> RefMut<MutableRouterState> {
self.state.write().unwrap() self.state.borrow_mut()
} }
/// Manually subscribe to the current route /// Manually subscribe to the current route
@@ -283,15 +282,14 @@ impl RouterContext {
/// Clear any unresolved errors /// Clear any unresolved errors
pub fn clear_error(&self) { pub fn clear_error(&self) {
self.state.write().unwrap().unresolved_error = None; self.state.borrow_mut().unresolved_error = None;
self.update_subscribers(); self.update_subscribers();
} }
pub(crate) fn render_error<'a>(&self, cx: Scope<'a>) -> Element<'a> { pub(crate) fn render_error<'a>(&self, cx: Scope<'a>) -> Element<'a> {
self.state self.state
.read() .borrow()
.unwrap()
.unresolved_error .unresolved_error
.as_ref() .as_ref()
.and_then(|_| (self.failure_external_navigation)(cx)) .and_then(|_| (self.failure_external_navigation)(cx))
+1
View File
@@ -392,6 +392,7 @@ fn read_input_to_data(target: Element) -> Rc<FormData> {
.dyn_ref() .dyn_ref()
.and_then(|input: &web_sys::HtmlInputElement| { .and_then(|input: &web_sys::HtmlInputElement| {
input.files().and_then(|files| { input.files().and_then(|files| {
#[allow(clippy::arc_with_non_send_sync)]
crate::file_engine::WebFileEngine::new(files) crate::file_engine::WebFileEngine::new(files)
.map(|f| std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>) .map(|f| std::sync::Arc::new(f) as std::sync::Arc<dyn dioxus_html::FileEngine>)
}) })