Merge pull request #289 from gbj/forbid-unsafe

Forbid `unsafe` code in all packages
This commit is contained in:
Greg Johnston 2023-01-09 20:45:28 -05:00 committed by GitHub
commit b8cafeb650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 63 additions and 27 deletions

View File

@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
use actix_web::{
dev::{ServiceFactory, ServiceRequest},
http::header,

View File

@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
use axum::{
body::{Body, Bytes, Full, StreamBody},
extract::Path,

View File

@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! # About Leptos
//!

View File

@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
pub mod errors;
use crate::errors::LeptosConfigError;

View File

@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "stable"), feature(fn_traits))]
#![cfg_attr(not(feature = "stable"), feature(unboxed_closures))]

View File

@ -1,4 +1,5 @@
#![cfg_attr(not(feature = "stable"), feature(proc_macro_span))]
#![forbid(unsafe_code)]
#[macro_use]
extern crate proc_macro_error;

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use std::{
any::{Any, TypeId},
collections::HashMap,

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::runtime::{with_runtime, RuntimeId};
use crate::{debug_warn, Runtime, Scope, ScopeProperty};
use cfg_if::cfg_if;

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{runtime::PinnedFuture, ResourceId};
use cfg_if::cfg_if;
use std::collections::{HashMap, HashSet};

View File

@ -82,6 +82,7 @@ mod signal;
mod signal_wrappers_read;
mod signal_wrappers_write;
mod spawn;
mod spawn_microtask;
mod stored_value;
mod suspense;
@ -98,6 +99,7 @@ pub use signal::*;
pub use signal_wrappers_read::*;
pub use signal_wrappers_write::*;
pub use spawn::*;
pub use spawn_microtask::*;
pub use stored_value::*;
pub use suspense::*;

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{ReadSignal, Scope, SignalError, UntrackedGettableSignal};
use std::fmt::Debug;

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{
create_effect, create_isomorphic_effect, create_memo, create_signal, queue_microtask,
runtime::{with_runtime, RuntimeId},

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{
hydration::SharedContext, serialization::Serializable, AnyEffect, AnyResource, Effect,
EffectId, Memo, ReadSignal, ResourceId, ResourceState, RwSignal, Scope, ScopeDisposer, ScopeId,

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{
runtime::{with_runtime, RuntimeId},
EffectId, PinnedFuture, ResourceId, SignalId, SuspenseContext,

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, rc::Rc};
use crate::{create_isomorphic_effect, create_signal, ReadSignal, Scope, WriteSignal};

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use cfg_if::cfg_if;
use std::rc::Rc;
use thiserror::Error;

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{
debug_warn,
runtime::{with_runtime, RuntimeId},

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{store_value, Memo, ReadSignal, RwSignal, Scope, StoredValue, UntrackedGettableSignal};
/// Helper trait for converting `Fn() -> T` closures into

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{store_value, RwSignal, Scope, StoredValue, WriteSignal};
/// Helper trait for converting `Fn(T)` into [`SignalSetter<T>`].

View File

@ -1,31 +1,7 @@
#![forbid(unsafe_code)]
use cfg_if::cfg_if;
use std::future::Future;
cfg_if! {
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
/// Exposes the [queueMicrotask](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) method
/// in the browser, and simply runs the given function when on the server.
pub fn queue_microtask(task: impl FnOnce() + 'static) {
microtask(wasm_bindgen::closure::Closure::once_into_js(task));
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
#[wasm_bindgen::prelude::wasm_bindgen(
inline_js = "export function microtask(f) { queueMicrotask(f); }"
)]
extern "C" {
fn microtask(task: wasm_bindgen::JsValue);
}
} else {
/// Exposes the [queueMicrotask](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) method
/// in the browser, and simply runs the given function when on the server.
#[cfg(not(any(feature = "csr", feature = "hydrate")))]
pub fn queue_microtask(task: impl FnOnce()) {
task();
}
}
}
/// Spawns and runs a thread-local [std::future::Future] in a platform-independent way.
///
/// This can be used to interface with any `async` code.
@ -33,7 +9,7 @@ pub fn spawn_local<F>(fut: F)
where
F: Future<Output = ()> + 'static,
{
cfg_if::cfg_if! {
cfg_if! {
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
wasm_bindgen_futures::spawn_local(fut)
}

View File

@ -0,0 +1,31 @@
// `queue_microtask` needs to be in its own module, which is the only thing
// in this entire framework that requires "unsafe" code (because Rust seems to
// that a `wasm_bindgen` imported function like this is unsafe)
// this is stupid, and one day hopefully web_sys will add queue_microtask itself
use cfg_if::cfg_if;
cfg_if! {
if #[cfg(any(feature = "csr", feature = "hydrate"))] {
/// Exposes the [queueMicrotask](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) method
/// in the browser, and simply runs the given function when on the server.
pub fn queue_microtask(task: impl FnOnce() + 'static) {
microtask(wasm_bindgen::closure::Closure::once_into_js(task));
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
#[wasm_bindgen::prelude::wasm_bindgen(
inline_js = "export function microtask(f) { queueMicrotask(f); }"
)]
extern "C" {
fn microtask(task: wasm_bindgen::JsValue);
}
} else {
/// Exposes the [queueMicrotask](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask) method
/// in the browser, and simply runs the given function when on the server.
#[cfg(not(any(feature = "csr", feature = "hydrate")))]
pub fn queue_microtask(task: impl FnOnce()) {
task();
}
}
}

View File

@ -1,3 +1,4 @@
#![forbid(unsafe_code)]
use crate::{create_rw_signal, RwSignal, Scope, UntrackedGettableSignal, UntrackedSettableSignal};
/// A **non-reactive** wrapper for any value, which can be created with [store_value].

View File

@ -1,4 +1,5 @@
use crate::{create_signal, spawn::queue_microtask, ReadSignal, Scope, WriteSignal};
#![forbid(unsafe_code)]
use crate::{create_signal, queue_microtask, ReadSignal, Scope, WriteSignal};
/// Tracks [Resource](crate::Resource)s that are read under a suspense context,
/// i.e., within a [`Suspense`](https://docs.rs/leptos_core/latest/leptos_core/fn.Suspense.html) component.

View File

@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! # Leptos Server Functions
//!

View File

@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![forbid(unsafe_code)]
//! # Leptos Meta
//!

View File

@ -1,3 +1,5 @@
#![forbid(unsafe_code)]
//! # Leptos Router
//!
//! Leptos Router is a router and state management tool for web applications