mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
clippy warnings
This commit is contained in:
parent
e4686f6c8d
commit
127af92541
@ -135,7 +135,7 @@ where
|
|||||||
/// instance for each thread, thus application state must be constructed
|
/// instance for each thread, thus application state must be constructed
|
||||||
/// multiple times. If you want to share state between different
|
/// multiple times. If you want to share state between different
|
||||||
/// threads, a shared object should be used, e.g. `Arc`. Application
|
/// threads, a shared object should be used, e.g. `Arc`. Application
|
||||||
/// state does not need to be `Send` and `Sync`.
|
/// state does not need to be `Send` or `Sync`.
|
||||||
pub fn with_state(state: S) -> App<S> {
|
pub fn with_state(state: S) -> App<S> {
|
||||||
App {
|
App {
|
||||||
parts: Some(ApplicationParts {
|
parts: Some(ApplicationParts {
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
|
#![cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::redundant_field_names)
|
||||||
|
)]
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::Write as FmtWrite;
|
use std::fmt::Write as FmtWrite;
|
||||||
|
@ -31,6 +31,7 @@ impl Hasher for IdHasher {
|
|||||||
|
|
||||||
type AnyMap = HashMap<TypeId, Box<Any>, BuildHasherDefault<IdHasher>>;
|
type AnyMap = HashMap<TypeId, Box<Any>, BuildHasherDefault<IdHasher>>;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
/// A type map of request extensions.
|
/// A type map of request extensions.
|
||||||
pub struct Extensions {
|
pub struct Extensions {
|
||||||
map: AnyMap,
|
map: AnyMap,
|
||||||
|
@ -530,8 +530,7 @@ where
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// /// extract path info using serde
|
/// /// extract path info using serde
|
||||||
/// fn index(data: (State<MyApp>, Path<Info>)) -> String {
|
/// fn index(state: State<MyApp>, path: Path<Info>)) -> String {
|
||||||
/// let (state, path) = data;
|
|
||||||
/// format!("{} {}!", state.msg, path.username)
|
/// format!("{} {}!", state.msg, path.username)
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
|
@ -694,7 +694,7 @@ impl HttpResponseBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::borrowed_box))]
|
||||||
fn parts<'a>(
|
fn parts<'a>(
|
||||||
parts: &'a mut Option<Box<InnerHttpResponse>>, err: &Option<HttpError>,
|
parts: &'a mut Option<Box<InnerHttpResponse>>, err: &Option<HttpError>,
|
||||||
) -> Option<&'a mut Box<InnerHttpResponse>> {
|
) -> Option<&'a mut Box<InnerHttpResponse>> {
|
||||||
|
@ -16,7 +16,10 @@ pub struct ConnectionInfo {
|
|||||||
|
|
||||||
impl ConnectionInfo {
|
impl ConnectionInfo {
|
||||||
/// Create *ConnectionInfo* instance for a request.
|
/// Create *ConnectionInfo* instance for a request.
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
|
#[cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::cyclomatic_complexity)
|
||||||
|
)]
|
||||||
pub fn update(&mut self, req: &Request) {
|
pub fn update(&mut self, req: &Request) {
|
||||||
let mut host = None;
|
let mut host = None;
|
||||||
let mut scheme = None;
|
let mut scheme = None;
|
||||||
|
@ -80,6 +80,7 @@
|
|||||||
#![cfg_attr(actix_nightly, feature(
|
#![cfg_attr(actix_nightly, feature(
|
||||||
specialization, // for impl ErrorResponse for std::error::Error
|
specialization, // for impl ErrorResponse for std::error::Error
|
||||||
extern_prelude,
|
extern_prelude,
|
||||||
|
tool_lints,
|
||||||
))]
|
))]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ impl DefaultHeaders {
|
|||||||
|
|
||||||
/// Set a header.
|
/// Set a header.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(match_wild_err_arm))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::match_wild_err_arm))]
|
||||||
pub fn header<K, V>(mut self, key: K, value: V) -> Self
|
pub fn header<K, V>(mut self, key: K, value: V) -> Self
|
||||||
where
|
where
|
||||||
HeaderName: HttpTryFrom<K>,
|
HeaderName: HttpTryFrom<K>,
|
||||||
|
@ -134,8 +134,7 @@ impl<S: 'static> Route<S> {
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// It is possible to use tuples for specifing multiple extractors for one
|
/// It is possible to use multiple extractors for one handler function.
|
||||||
/// handler function.
|
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # extern crate bytes;
|
/// # extern crate bytes;
|
||||||
@ -152,9 +151,9 @@ impl<S: 'static> Route<S> {
|
|||||||
///
|
///
|
||||||
/// /// extract path info using serde
|
/// /// extract path info using serde
|
||||||
/// fn index(
|
/// fn index(
|
||||||
/// info: (Path<Info>, Query<HashMap<String, String>>, Json<Info>),
|
/// path: Path<Info>, query: Query<HashMap<String, String>>, body: Json<Info>,
|
||||||
/// ) -> Result<String> {
|
/// ) -> Result<String> {
|
||||||
/// Ok(format!("Welcome {}!", info.0.username))
|
/// Ok(format!("Welcome {}!", path.username))
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
|
@ -59,7 +59,10 @@ pub struct Scope<S> {
|
|||||||
middlewares: Rc<Vec<Box<Middleware<S>>>>,
|
middlewares: Rc<Vec<Box<Middleware<S>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))]
|
#[cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::new_without_default_derive)
|
||||||
|
)]
|
||||||
impl<S: 'static> Scope<S> {
|
impl<S: 'static> Scope<S> {
|
||||||
/// Create a new scope
|
/// Create a new scope
|
||||||
pub fn new(path: &str) -> Scope<S> {
|
pub fn new(path: &str) -> Scope<S> {
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]
|
#![cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::redundant_field_names)
|
||||||
|
)]
|
||||||
|
|
||||||
use std::{cmp, io};
|
use std::{cmp, io};
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ pub fn write_content_length(mut n: usize, bytes: &mut BytesMut) {
|
|||||||
let d1 = n << 1;
|
let d1 = n << 1;
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::copy_nonoverlapping(
|
ptr::copy_nonoverlapping(
|
||||||
DEC_DIGITS_LUT.as_ptr().offset(d1 as isize),
|
DEC_DIGITS_LUT.as_ptr().add(d1),
|
||||||
buf.as_mut_ptr().offset(18),
|
buf.as_mut_ptr().offset(18),
|
||||||
2,
|
2,
|
||||||
);
|
);
|
||||||
@ -94,7 +94,7 @@ pub fn write_content_length(mut n: usize, bytes: &mut BytesMut) {
|
|||||||
n /= 100;
|
n /= 100;
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::copy_nonoverlapping(
|
ptr::copy_nonoverlapping(
|
||||||
DEC_DIGITS_LUT.as_ptr().offset(d1 as isize),
|
DEC_DIGITS_LUT.as_ptr().add(d1),
|
||||||
buf.as_mut_ptr().offset(19),
|
buf.as_mut_ptr().offset(19),
|
||||||
2,
|
2,
|
||||||
)
|
)
|
||||||
|
@ -329,7 +329,10 @@ where
|
|||||||
|
|
||||||
/// Start listening for incoming connections with supplied acceptor.
|
/// Start listening for incoming connections with supplied acceptor.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
#[cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::needless_pass_by_value)
|
||||||
|
)]
|
||||||
pub fn bind_with<S, A>(mut self, addr: S, acceptor: A) -> io::Result<Self>
|
pub fn bind_with<S, A>(mut self, addr: S, acceptor: A) -> io::Result<Self>
|
||||||
where
|
where
|
||||||
S: net::ToSocketAddrs,
|
S: net::ToSocketAddrs,
|
||||||
|
@ -151,10 +151,9 @@ impl Output {
|
|||||||
let version = resp.version().unwrap_or_else(|| req.version);
|
let version = resp.version().unwrap_or_else(|| req.version);
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(match_ref_pats))]
|
|
||||||
let has_body = match resp.body() {
|
let has_body = match resp.body() {
|
||||||
&Body::Empty => false,
|
Body::Empty => false,
|
||||||
&Body::Binary(ref bin) => {
|
Body::Binary(ref bin) => {
|
||||||
len = bin.len();
|
len = bin.len();
|
||||||
!(response_encoding == ContentEncoding::Auto && len < 96)
|
!(response_encoding == ContentEncoding::Auto && len < 96)
|
||||||
}
|
}
|
||||||
@ -190,16 +189,15 @@ impl Output {
|
|||||||
#[cfg(not(any(feature = "brotli", feature = "flate2")))]
|
#[cfg(not(any(feature = "brotli", feature = "flate2")))]
|
||||||
let mut encoding = ContentEncoding::Identity;
|
let mut encoding = ContentEncoding::Identity;
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(match_ref_pats))]
|
|
||||||
let transfer = match resp.body() {
|
let transfer = match resp.body() {
|
||||||
&Body::Empty => {
|
Body::Empty => {
|
||||||
if !info.head {
|
if !info.head {
|
||||||
info.length = ResponseLength::Zero;
|
info.length = ResponseLength::Zero;
|
||||||
}
|
}
|
||||||
*self = Output::Empty(buf);
|
*self = Output::Empty(buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
&Body::Binary(_) => {
|
Body::Binary(_) => {
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
||||||
{
|
{
|
||||||
if !(encoding == ContentEncoding::Identity
|
if !(encoding == ContentEncoding::Identity
|
||||||
@ -244,7 +242,7 @@ impl Output {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
&Body::Streaming(_) | &Body::Actor(_) => {
|
Body::Streaming(_) | Body::Actor(_) => {
|
||||||
if resp.upgrade() {
|
if resp.upgrade() {
|
||||||
if version == Version::HTTP_2 {
|
if version == Version::HTTP_2 {
|
||||||
error!("Connection upgrade is forbidden for HTTP/2");
|
error!("Connection upgrade is forbidden for HTTP/2");
|
||||||
@ -441,7 +439,7 @@ impl ContentEncoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(inline_always))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::inline_always))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn write_eof(&mut self) -> Result<bool, io::Error> {
|
pub fn write_eof(&mut self) -> Result<bool, io::Error> {
|
||||||
let encoder =
|
let encoder =
|
||||||
@ -483,7 +481,7 @@ impl ContentEncoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(inline_always))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::inline_always))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn write(&mut self, data: &[u8]) -> Result<(), io::Error> {
|
pub fn write(&mut self, data: &[u8]) -> Result<(), io::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -216,7 +216,7 @@ impl<H> WorkerSettings<H> {
|
|||||||
|
|
||||||
fn update_date(&self) {
|
fn update_date(&self) {
|
||||||
// Unsafe: WorkerSetting is !Sync and !Send
|
// Unsafe: WorkerSetting is !Sync and !Send
|
||||||
unsafe { (&mut *self.0.date.get()).0 = false };
|
unsafe { (*self.0.date.get()).0 = false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
src/with.rs
19
src/with.rs
@ -12,7 +12,6 @@ trait FnWith<T, R>: 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R, F: Fn(T) -> R + 'static> FnWith<T, R> for F {
|
impl<T, R, F: Fn(T) -> R + 'static> FnWith<T, R> for F {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(boxed_local))]
|
|
||||||
fn call_with(self: &Self, arg: T) -> R {
|
fn call_with(self: &Self, arg: T) -> R {
|
||||||
(*self)(arg)
|
(*self)(arg)
|
||||||
}
|
}
|
||||||
@ -42,24 +41,6 @@ where
|
|||||||
fn create_with_config(self, T::Config) -> WithAsync<T, S, R, I, E>;
|
fn create_with_config(self, T::Config) -> WithAsync<T, S, R, I, E>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// impl<T1, T2, T3, S, F, R> WithFactory<(T1, T2, T3), S, R> for F
|
|
||||||
// where F: Fn(T1, T2, T3) -> R + 'static,
|
|
||||||
// T1: FromRequest<S> + 'static,
|
|
||||||
// T2: FromRequest<S> + 'static,
|
|
||||||
// T3: FromRequest<S> + 'static,
|
|
||||||
// R: Responder + 'static,
|
|
||||||
// S: 'static,
|
|
||||||
// {
|
|
||||||
// fn create(self) -> With<(T1, T2, T3), S, R> {
|
|
||||||
// With::new(move |(t1, t2, t3)| (self)(t1, t2, t3), (
|
|
||||||
// T1::Config::default(), T2::Config::default(), T3::Config::default()))
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn create_with_config(self, cfg: (T1::Config, T2::Config, T3::Config,)) -> With<(T1, T2, T3), S, R> {
|
|
||||||
// With::new(move |(t1, t2, t3)| (self)(t1, t2, t3), cfg)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct With<T, S, R>
|
pub struct With<T, S, R>
|
||||||
where
|
where
|
||||||
|
@ -46,7 +46,7 @@ impl Frame {
|
|||||||
Frame::message(payload, OpCode::Close, true, genmask)
|
Frame::message(payload, OpCode::Close, true, genmask)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::type_complexity))]
|
||||||
fn read_copy_md<S>(
|
fn read_copy_md<S>(
|
||||||
pl: &mut PayloadBuffer<S>, server: bool, max_size: usize,
|
pl: &mut PayloadBuffer<S>, server: bool, max_size: usize,
|
||||||
) -> Poll<Option<(usize, bool, OpCode, usize, Option<u32>)>, ProtocolError>
|
) -> Poll<Option<(usize, bool, OpCode, usize, Option<u32>)>, ProtocolError>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//! This is code from [Tungstenite project](https://github.com/snapview/tungstenite-rs)
|
//! This is code from [Tungstenite project](https://github.com/snapview/tungstenite-rs)
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
|
#![cfg_attr(feature = "cargo-clippy", allow(clippy::cast_ptr_alignment))]
|
||||||
use std::ptr::copy_nonoverlapping;
|
use std::ptr::copy_nonoverlapping;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ impl<'a> ShortSlice<'a> {
|
|||||||
|
|
||||||
/// Faster version of `apply_mask()` which operates on 8-byte blocks.
|
/// Faster version of `apply_mask()` which operates on 8-byte blocks.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
|
#[cfg_attr(feature = "cargo-clippy", allow(clippy::cast_lossless))]
|
||||||
pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) {
|
pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) {
|
||||||
// Extend the mask to 64 bits
|
// Extend the mask to 64 bits
|
||||||
let mut mask_u64 = ((mask_u32 as u64) << 32) | (mask_u32 as u64);
|
let mut mask_u64 = ((mask_u32 as u64) << 32) | (mask_u32 as u64);
|
||||||
@ -50,7 +50,10 @@ pub(crate) fn apply_mask(buf: &mut [u8], mask_u32: u32) {
|
|||||||
// TODO: copy_nonoverlapping here compiles to call memcpy. While it is not so
|
// TODO: copy_nonoverlapping here compiles to call memcpy. While it is not so
|
||||||
// inefficient, it could be done better. The compiler does not understand that
|
// inefficient, it could be done better. The compiler does not understand that
|
||||||
// a `ShortSlice` must be smaller than a u64.
|
// a `ShortSlice` must be smaller than a u64.
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(needless_pass_by_value))]
|
#[cfg_attr(
|
||||||
|
feature = "cargo-clippy",
|
||||||
|
allow(clippy::needless_pass_by_value)
|
||||||
|
)]
|
||||||
fn xor_short(buf: ShortSlice, mask: u64) {
|
fn xor_short(buf: ShortSlice, mask: u64) {
|
||||||
// Unsafe: we know that a `ShortSlice` fits in a u64
|
// Unsafe: we know that a `ShortSlice` fits in a u64
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Loading…
Reference in New Issue
Block a user