diff --git a/examples/warp_subscriptions/src/main.rs b/examples/warp_subscriptions/src/main.rs index 4e4d4584..ded89062 100644 --- a/examples/warp_subscriptions/src/main.rs +++ b/examples/warp_subscriptions/src/main.rs @@ -46,7 +46,7 @@ impl User { async fn friends(&self) -> Vec { if self.id == 1 { - return vec![ + vec![ User { id: 11, kind: UserKind::User, @@ -62,15 +62,15 @@ impl User { kind: UserKind::Guest, name: "user13".into(), }, - ]; + ] } else if self.id == 2 { - return vec![User { + vec![User { id: 21, kind: UserKind::User, name: "user21".into(), - }]; + }] } else if self.id == 3 { - return vec![ + vec![ User { id: 31, kind: UserKind::User, @@ -81,9 +81,9 @@ impl User { kind: UserKind::Guest, name: "user32".into(), }, - ]; + ] } else { - return vec![]; + vec![] } } } diff --git a/juniper/Cargo.toml b/juniper/Cargo.toml index 6a1121aa..ca5e24c6 100644 --- a/juniper/Cargo.toml +++ b/juniper/Cargo.toml @@ -39,7 +39,7 @@ schema-language = ["graphql-parser"] anyhow = { version = "1.0.32", default-features = false, optional = true } async-trait = "0.1.39" bigdecimal = { version = "0.3", optional = true } -bson = { version = "2.3", features = ["chrono-0_4"], optional = true } +bson = { version = "2.4", features = ["chrono-0_4"], optional = true } chrono = { version = "0.4", features = ["alloc"], default-features = false, optional = true } chrono-tz = { version = "0.6", default-features = false, optional = true } fnv = "1.0.3" @@ -59,8 +59,6 @@ uuid = { version = "1.0", default-features = false, optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2", features = ["js"] } -# not used, to fix `bson` compilation only -uuid_08 = { version = "0.8", package = "uuid", default-features = false, features = ["wasm-bindgen"] } [dev-dependencies] bencher = "0.1.2" diff --git a/juniper/src/ast.rs b/juniper/src/ast.rs index 075e0e07..790df06c 100644 --- a/juniper/src/ast.rs +++ b/juniper/src/ast.rs @@ -114,7 +114,7 @@ pub struct Directive<'a, S> { } #[allow(missing_docs)] -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum OperationType { Query, Mutation, diff --git a/juniper/src/executor/look_ahead.rs b/juniper/src/executor/look_ahead.rs index b12231d6..20437082 100644 --- a/juniper/src/executor/look_ahead.rs +++ b/juniper/src/executor/look_ahead.rs @@ -10,7 +10,7 @@ use super::Variables; /// An enum that describes if a field is available in all types of the interface /// or only in a certain subtype -#[derive(Debug, Clone, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Applies<'a> { /// The field is available independent from the type All, diff --git a/juniper/src/executor/mod.rs b/juniper/src/executor/mod.rs index 558d5850..36076455 100644 --- a/juniper/src/executor/mod.rs +++ b/juniper/src/executor/mod.rs @@ -1302,21 +1302,20 @@ impl<'r, S: 'r> Registry<'r, S> { /// /// [`graphql::Type`]: resolve::Type /// [`TypeName`]: resolve::TypeName - pub fn register_scalar_with<'ti, T, TI, F>( + pub fn register_scalar_with<'ti, T, TI>( &mut self, type_info: &'ti TI, - customize: F, + customize: impl FnOnce(ScalarMeta<'r, S>) -> ScalarMeta<'r, S>, ) -> MetaType<'r, S> where T: resolve::TypeName + resolve::InputValueOwned + resolve::ScalarToken, TI: ?Sized, 'ti: 'r, - F: FnOnce(ScalarMeta<'r, S>) -> ScalarMeta<'r, S>, S: Clone, { self.entry_type::(type_info) .or_insert_with(move || { - customize(ScalarMeta::new_reworked::(T::type_name(type_info))).into_meta() + customize(ScalarMeta::new_reworked::(T::type_name(type_info))).into_meta() }) .clone() } @@ -1338,7 +1337,7 @@ impl<'r, S: 'r> Registry<'r, S> { 'ti: 'r, S: Clone, { - self.register_scalar_unsized_with::(type_info, convert::identity) + self.register_scalar_unsized_with::(type_info, convert::identity) } /// Builds a [`ScalarMeta`] information for the specified non-[`Sized`] @@ -1352,21 +1351,20 @@ impl<'r, S: 'r> Registry<'r, S> { /// /// [`graphql::Type`]: resolve::Type /// [`TypeName`]: resolve::TypeName - pub fn register_scalar_unsized_with<'ti, T, TI, F>( + pub fn register_scalar_unsized_with<'ti, T, TI>( &mut self, type_info: &'ti TI, - customize: F, + customize: impl FnOnce(ScalarMeta<'r, S>) -> ScalarMeta<'r, S>, ) -> MetaType<'r, S> where T: resolve::TypeName + resolve::InputValueAsRef + resolve::ScalarToken + ?Sized, TI: ?Sized, 'ti: 'r, - F: FnOnce(ScalarMeta<'r, S>) -> ScalarMeta<'r, S>, S: Clone, { self.entry_type::(type_info) .or_insert_with(move || { - customize(ScalarMeta::new_unsized::(T::type_name(type_info))).into_meta() + customize(ScalarMeta::new_unsized::(T::type_name(type_info))).into_meta() }) .clone() } @@ -1474,26 +1472,21 @@ impl<'r, S: 'r> Registry<'r, S> { /// /// [`graphql::Type`]: resolve::Type /// [`TypeName`]: resolve::TypeName - pub fn register_enum_with<'ti, T, TI, F>( + pub fn register_enum_with<'ti, T, TI>( &mut self, values: &[EnumValue], type_info: &'ti TI, - customize: F, + customize: impl FnOnce(EnumMeta<'r, S>) -> EnumMeta<'r, S>, ) -> MetaType<'r, S> where T: resolve::TypeName + resolve::InputValueOwned, TI: ?Sized, 'ti: 'r, - F: FnOnce(EnumMeta<'r, S>) -> EnumMeta<'r, S>, S: Clone, { self.entry_type::(type_info) .or_insert_with(move || { - customize(EnumMeta::new_reworked::( - T::type_name(type_info), - values, - )) - .into_meta() + customize(EnumMeta::new_reworked::(T::type_name(type_info), values)).into_meta() }) .clone() } @@ -1553,22 +1546,21 @@ impl<'r, S: 'r> Registry<'r, S> { /// /// [`graphql::Type`]: resolve::Type /// [`TypeName`]: resolve::TypeName - pub fn register_input_object_with<'ti, T, TI, F>( + pub fn register_input_object_with<'ti, T, TI>( &mut self, fields: &[Argument<'r, S>], type_info: &'ti TI, - customize: F, + customize: impl FnOnce(InputObjectMeta<'r, S>) -> InputObjectMeta<'r, S>, ) -> MetaType<'r, S> where T: resolve::TypeName + resolve::InputValueOwned, TI: ?Sized, 'ti: 'r, - F: FnOnce(InputObjectMeta<'r, S>) -> InputObjectMeta<'r, S>, S: Clone, { self.entry_type::(type_info) .or_insert_with(move || { - customize(InputObjectMeta::new_reworked::( + customize(InputObjectMeta::new_reworked::( T::type_name(type_info), fields, )) diff --git a/juniper/src/lib.rs b/juniper/src/lib.rs index d59f97cf..a40e1bf8 100644 --- a/juniper/src/lib.rs +++ b/juniper/src/lib.rs @@ -97,8 +97,8 @@ pub use crate::{ }; /// An error that prevented query execution -#[derive(Debug, PartialEq)] #[allow(missing_docs)] +#[derive(Debug, Eq, PartialEq)] pub enum GraphQLError { ParseError(Spanning), ValidationError(Vec), diff --git a/juniper/src/parser/lexer.rs b/juniper/src/parser/lexer.rs index 3dd4a0e5..3eb6a56a 100644 --- a/juniper/src/parser/lexer.rs +++ b/juniper/src/parser/lexer.rs @@ -20,8 +20,8 @@ pub struct Lexer<'a> { /// A single scalar value literal /// /// This is only used for tagging how the lexer has interpreted a value literal -#[derive(Debug, PartialEq, Clone, Copy)] #[allow(missing_docs)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ScalarToken<'a> { String(&'a str), Float(&'a str), @@ -29,8 +29,8 @@ pub enum ScalarToken<'a> { } /// A single token in the input source -#[derive(Debug, PartialEq, Clone, Copy)] #[allow(missing_docs)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Token<'a> { Name(&'a str), Scalar(ScalarToken<'a>), diff --git a/juniper/src/parser/parser.rs b/juniper/src/parser/parser.rs index 89ab697b..b0c27099 100644 --- a/juniper/src/parser/parser.rs +++ b/juniper/src/parser/parser.rs @@ -5,7 +5,7 @@ use smartstring::alias::String; use crate::parser::{Lexer, LexerError, Spanning, Token}; /// Error while parsing a GraphQL query -#[derive(Debug, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub enum ParseError { /// An unexpected token occurred in the source // TODO: Previously was `Token<'a>`. diff --git a/juniper/src/reflect/mod.rs b/juniper/src/reflect/mod.rs index ecaa6753..49fff168 100644 --- a/juniper/src/reflect/mod.rs +++ b/juniper/src/reflect/mod.rs @@ -754,11 +754,11 @@ mod macros { } const CON: [u8; LEN] = concat([$($s),*]); - // TODO: Use `str::from_utf8()` once it becomes `const`. - // SAFETY: This is safe, as we concatenate multiple UTF-8 strings - // one after another byte-by-byte. - #[allow(unsafe_code)] - unsafe { ::std::str::from_utf8_unchecked(&CON) } + // TODO: Use `.unwrap()` once it becomes `const`. + match ::std::str::from_utf8(&CON) { + ::std::result::Result::Ok(s) => s, + _ => unreachable!(), + } }}; } @@ -852,12 +852,11 @@ mod macros { const TYPE_ARR: [u8; RES_LEN] = format_type_arr(); - // TODO: Use `str::from_utf8()` once it becomes `const`. - // SAFETY: This is safe, as we concatenate multiple UTF-8 strings one - // after another byte-by-byte. - #[allow(unsafe_code)] - const TYPE_FORMATTED: &str = - unsafe { ::std::str::from_utf8_unchecked(TYPE_ARR.as_slice()) }; + // TODO: Use `.unwrap()` once it becomes `const`. + const TYPE_FORMATTED: &str = match ::std::str::from_utf8(TYPE_ARR.as_slice()) { + ::std::result::Result::Ok(s) => s, + _ => unreachable!(), + }; TYPE_FORMATTED }}; } diff --git a/juniper/src/schema/meta.rs b/juniper/src/schema/meta.rs index 13d526eb..870e2332 100644 --- a/juniper/src/schema/meta.rs +++ b/juniper/src/schema/meta.rs @@ -16,7 +16,7 @@ use crate::{ }; /// Whether an item is deprecated, with context. -#[derive(Debug, PartialEq, Hash, Clone)] +#[derive(Clone, Debug, Eq, Hash, PartialEq)] pub enum DeprecationStatus { /// The field/variant is not deprecated. Current, @@ -502,13 +502,9 @@ impl<'a, S> ScalarMeta<'a, S> { } /// Builds a new [`ScalarMeta`] information with the specified `name`. - // TODO: Use `impl Into>` argument once feature - // `explicit_generic_args_with_impl_trait` hits stable: - // https://github.com/rust-lang/rust/issues/83701 - pub fn new_reworked(name: N) -> Self + pub fn new_reworked(name: impl Into>) -> Self where T: resolve::InputValueOwned + resolve::ScalarToken, - Cow<'a, str>: From, { Self { name: name.into(), @@ -521,13 +517,9 @@ impl<'a, S> ScalarMeta<'a, S> { /// Builds a new [`ScalarMeta`] information with the specified `name` for /// the non-[`Sized`] `T`ype that may only be parsed as a reference. - // TODO: Use `impl Into>` argument once feature - // `explicit_generic_args_with_impl_trait` hits stable: - // https://github.com/rust-lang/rust/issues/83701 - pub fn new_unsized(name: N) -> Self + pub fn new_unsized(name: impl Into>) -> Self where T: resolve::InputValueAsRef + resolve::ScalarToken + ?Sized, - Cow<'a, str>: From, { Self { name: name.into(), @@ -653,13 +645,9 @@ impl<'a, S> EnumMeta<'a, S> { /// Builds a new [`EnumMeta`] information with the specified `name` and /// possible `values`. - // TODO: Use `impl Into>` argument once feature - // `explicit_generic_args_with_impl_trait` hits stable: - // https://github.com/rust-lang/rust/issues/83701 - pub fn new_reworked(name: N, values: &[EnumValue]) -> Self + pub fn new_reworked(name: impl Into>, values: &[EnumValue]) -> Self where T: resolve::InputValueOwned, - Cow<'a, str>: From, { Self { name: name.into(), @@ -771,13 +759,9 @@ impl<'a, S> InputObjectMeta<'a, S> { /// Builds a new [`InputObjectMeta`] information with the specified `name` /// and its `fields`. - // TODO: Use `impl Into>` argument once feature - // `explicit_generic_args_with_impl_trait` hits stable: - // https://github.com/rust-lang/rust/issues/83701 - pub fn new_reworked(name: N, fields: &[Argument<'a, S>]) -> Self + pub fn new_reworked(name: impl Into>, fields: &[Argument<'a, S>]) -> Self where T: resolve::InputValueOwned, - Cow<'a, str>: From, S: Clone, { Self { diff --git a/juniper/src/schema/schema.rs b/juniper/src/schema/schema.rs index bf48ea37..61822746 100644 --- a/juniper/src/schema/schema.rs +++ b/juniper/src/schema/schema.rs @@ -234,7 +234,7 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> { fn of_type(&self) -> Option<&TypeType> { match self { TypeType::Concrete(_) => None, - TypeType::List(l, _) | TypeType::NonNull(l) => Some(&*l), + TypeType::List(l, _) | TypeType::NonNull(l) => Some(&**l), } } diff --git a/juniper_codegen/src/common/field/arg.rs b/juniper_codegen/src/common/field/arg.rs index dd0e1013..06bedfa0 100644 --- a/juniper_codegen/src/common/field/arg.rs +++ b/juniper_codegen/src/common/field/arg.rs @@ -286,7 +286,7 @@ impl OnMethod { #[must_use] pub(crate) fn as_regular(&self) -> Option<&OnField> { if let Self::Regular(arg) = self { - Some(&*arg) + Some(&**arg) } else { None } @@ -297,7 +297,7 @@ impl OnMethod { #[must_use] pub(crate) fn context_ty(&self) -> Option<&syn::Type> { if let Self::Context(ty) = self { - Some(&*ty) + Some(&**ty) } else { None } diff --git a/juniper_codegen/src/common/parse/downcaster.rs b/juniper_codegen/src/common/parse/downcaster.rs index 2a4e1369..8c63de21 100644 --- a/juniper_codegen/src/common/parse/downcaster.rs +++ b/juniper_codegen/src/common/parse/downcaster.rs @@ -17,7 +17,7 @@ use crate::common::parse::TypeExt as _; /// corresponding error at. pub(crate) fn output_type(ret_ty: &syn::ReturnType) -> Result { let ret_ty = match &ret_ty { - syn::ReturnType::Type(_, ty) => &*ty, + syn::ReturnType::Type(_, ty) => &**ty, _ => return Err(ret_ty.span()), }; diff --git a/juniper_codegen/src/graphql_enum/mod.rs b/juniper_codegen/src/graphql_enum/mod.rs index 9f973edc..6fd00a1c 100644 --- a/juniper_codegen/src/graphql_enum/mod.rs +++ b/juniper_codegen/src/graphql_enum/mod.rs @@ -647,7 +647,7 @@ impl Definition { let values = [#( #values_meta ),*]; registry.register_enum_with::< - ::juniper::behavior::Coerce, _, _, + ::juniper::behavior::Coerce, _, >(&values, type_info, |meta| { meta #description }) diff --git a/juniper_codegen/src/graphql_input_object/mod.rs b/juniper_codegen/src/graphql_input_object/mod.rs index ec6ea64c..0d72a0dd 100644 --- a/juniper_codegen/src/graphql_input_object/mod.rs +++ b/juniper_codegen/src/graphql_input_object/mod.rs @@ -734,7 +734,7 @@ impl Definition { let fields = [#( #fields_meta ),*]; registry.register_input_object_with::< - ::juniper::behavior::Coerce, _, _, + ::juniper::behavior::Coerce, _, >(&fields, type_info, |meta| { meta #description }) diff --git a/juniper_codegen/src/graphql_object/mod.rs b/juniper_codegen/src/graphql_object/mod.rs index 6a25090a..125bc5e2 100644 --- a/juniper_codegen/src/graphql_object/mod.rs +++ b/juniper_codegen/src/graphql_object/mod.rs @@ -655,7 +655,7 @@ impl ToTokens for Definition { self.impl_async_field_tokens().to_tokens(into); //////////////////////////////////////////////////////////////////////// self.impl_reflect().to_tokens(into); - self.impl_reflect_field().to_tokens(into); + //self.impl_reflect_field().to_tokens(into); //self.impl_resolve_field_static().to_tokens(into); } } diff --git a/juniper_codegen/src/graphql_scalar/mod.rs b/juniper_codegen/src/graphql_scalar/mod.rs index 568d1dd2..3bde5e66 100644 --- a/juniper_codegen/src/graphql_scalar/mod.rs +++ b/juniper_codegen/src/graphql_scalar/mod.rs @@ -584,7 +584,7 @@ impl Definition { #sv: '__r, { registry.register_scalar_with::< - ::juniper::behavior::Coerce, _, _, + ::juniper::behavior::Coerce, _, >(type_info, |meta| { meta #description #specified_by_url }) diff --git a/juniper_codegen/src/graphql_union/mod.rs b/juniper_codegen/src/graphql_union/mod.rs index 14355511..df162fdd 100644 --- a/juniper_codegen/src/graphql_union/mod.rs +++ b/juniper_codegen/src/graphql_union/mod.rs @@ -316,7 +316,7 @@ impl ToTokens for Definition { self.impl_graphql_value_async_tokens().to_tokens(into); self.impl_reflection_traits_tokens().to_tokens(into); //////////////////////////////////////////////////////////////////////// - self.impl_reflect().to_tokens(into); + //self.impl_reflect().to_tokens(into); } } @@ -612,7 +612,7 @@ impl Definition { /// [`WrappedType`]: juniper::macros::reflect::WrappedType /// [1]: https://spec.graphql.org/October2021#sec-Unions #[must_use] - pub(crate)fn impl_reflection_traits_tokens(&self) -> TokenStream { + pub(crate) fn impl_reflection_traits_tokens(&self) -> TokenStream { let scalar = &self.scalar; let name = &self.name; let variants = self.variants.iter().map(|var| &var.ty); @@ -647,7 +647,7 @@ impl Definition { } } } - + /* /// Returns generated code implementing [`reflect::BaseType`], /// [`reflect::BaseSubTypes`] and [`reflect::WrappedType`] traits for this /// [GraphQL union][0]. @@ -687,7 +687,7 @@ impl Definition { ::juniper::reflect::wrap::SINGULAR; } } - } + }*/ } /// Definition of [GraphQL union][1] variant for code generation. diff --git a/juniper_graphql_ws/src/lib.rs b/juniper_graphql_ws/src/lib.rs index d1621a61..43f01f55 100644 --- a/juniper_graphql_ws/src/lib.rs +++ b/juniper_graphql_ws/src/lib.rs @@ -1,6 +1,5 @@ #![doc = include_str!("../README.md")] -#![deny(missing_docs)] -#![deny(warnings)] +#![deny(missing_docs, warnings)] mod client_message; pub use client_message::*; @@ -315,8 +314,7 @@ impl> ConnectionState { Err(e) => { return Reaction::ServerMessage(ServerMessage::Error { id: id.clone(), - // e only references data owned by params. The new ErrorPayload will continue to keep that data alive. - payload: unsafe { ErrorPayload::new_unchecked(Box::new(params.clone()), e) }, + payload: ErrorPayload::new(Box::new(params.clone()), e), }) .into_stream(); } @@ -434,10 +432,7 @@ impl Stream for SubscriptionStart { return Poll::Ready(Some(Reaction::ServerMessage( ServerMessage::Error { id: id.clone(), - // e only references data owned by params. The new ErrorPayload will continue to keep that data alive. - payload: unsafe { - ErrorPayload::new_unchecked(Box::new(params.clone()), e) - }, + payload: ErrorPayload::new(Box::new(params.clone()), e), }, ))); } diff --git a/juniper_graphql_ws/src/server_message.rs b/juniper_graphql_ws/src/server_message.rs index 232ef038..6e2fce9a 100644 --- a/juniper_graphql_ws/src/server_message.rs +++ b/juniper_graphql_ws/src/server_message.rs @@ -1,10 +1,10 @@ -use std::{any::Any, fmt, marker::PhantomPinned, mem}; +use std::{any::Any, fmt, marker::PhantomPinned}; use juniper::{ExecutionError, GraphQLError, Value}; use serde::{Serialize, Serializer}; /// The payload for errors that are not associated with a GraphQL operation. -#[derive(Debug, Serialize, PartialEq)] +#[derive(Debug, Eq, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct ConnectionErrorPayload { /// The error message. @@ -37,15 +37,12 @@ pub struct ErrorPayload { } impl ErrorPayload { - /// For this to be okay, the caller must guarantee that the error can only reference data from - /// execution_params and that execution_params has not been modified or moved. - pub(crate) unsafe fn new_unchecked( - execution_params: Box, - error: GraphQLError, - ) -> Self { + /// Creates a new [`ErrorPayload`] out of the provide `execution_params` and + /// [`GraphQLError`]. + pub(crate) fn new(execution_params: Box, error: GraphQLError) -> Self { Self { _execution_params: Some(execution_params), - error: mem::transmute(error), + error, _marker: PhantomPinned, } }