Tune up for 1.63 Rust
This commit is contained in:
parent
faf1f57200
commit
0df1e448e8
14 changed files with 38 additions and 49 deletions
|
@ -46,7 +46,7 @@ impl User {
|
|||
|
||||
async fn friends(&self) -> Vec<User> {
|
||||
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![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -94,8 +94,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<ParseError>),
|
||||
ValidationError(Vec<RuleError>),
|
||||
|
|
|
@ -883,11 +883,11 @@ macro_rules! const_concat {
|
|||
}
|
||||
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!(),
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -1005,12 +1005,11 @@ macro_rules! format_type {
|
|||
|
||||
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
|
||||
}};
|
||||
|
|
|
@ -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>),
|
||||
|
|
|
@ -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>`.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -234,7 +234,7 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
|
|||
fn of_type(&self) -> Option<&TypeType<S>> {
|
||||
match self {
|
||||
TypeType::Concrete(_) => None,
|
||||
TypeType::List(l, _) | TypeType::NonNull(l) => Some(&*l),
|
||||
TypeType::List(l, _) | TypeType::NonNull(l) => Some(&**l),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,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
|
||||
}
|
||||
|
@ -268,7 +268,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
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::common::parse::TypeExt as _;
|
|||
/// corresponding error at.
|
||||
pub(crate) fn output_type(ret_ty: &syn::ReturnType) -> Result<syn::Type, Span> {
|
||||
let ret_ty = match &ret_ty {
|
||||
syn::ReturnType::Type(_, ty) => &*ty,
|
||||
syn::ReturnType::Type(_, ty) => &**ty,
|
||||
_ => return Err(ret_ty.span()),
|
||||
};
|
||||
|
||||
|
|
|
@ -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<S: Schema, I: Init<S::ScalarValue, S::Context>> ConnectionState<S, I> {
|
|||
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<S: Schema> Stream for SubscriptionStart<S> {
|
|||
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),
|
||||
},
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -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<dyn Any + Send>,
|
||||
error: GraphQLError,
|
||||
) -> Self {
|
||||
/// Creates a new [`ErrorPayload`] out of the provide `execution_params` and
|
||||
/// [`GraphQLError`].
|
||||
pub(crate) fn new(execution_params: Box<dyn Any + Send>, error: GraphQLError) -> Self {
|
||||
Self {
|
||||
_execution_params: Some(execution_params),
|
||||
error: mem::transmute(error),
|
||||
error,
|
||||
_marker: PhantomPinned,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue