From fee43a09c884b6401adc8f734c9cf66f6951d10f Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 27 Jun 2017 12:23:57 -0700 Subject: [PATCH] Fix warnings --- src/client.rs | 12 +++++++++--- src/error.rs | 1 + src/frame/head.rs | 2 -- src/frame/headers.rs | 5 ++++- src/frame/mod.rs | 6 ------ src/frame/reset.rs | 2 +- src/frame/settings.rs | 2 +- src/hpack/decoder.rs | 21 ++++++++++----------- src/hpack/encoder.rs | 10 ++++------ src/hpack/header.rs | 4 ++-- src/hpack/huffman/mod.rs | 2 +- src/hpack/table.rs | 25 +++++++++++++------------ src/lib.rs | 3 ++- src/proto/connection.rs | 6 ++++-- src/proto/framed_read.rs | 8 ++++---- src/proto/framed_write.rs | 8 ++++---- src/util/byte_str.rs | 3 +-- 17 files changed, 61 insertions(+), 59 deletions(-) diff --git a/src/client.rs b/src/client.rs index 85546f1..179a0b1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,11 +1,11 @@ -use {frame, proto, Frame, Peer, ConnectionError, StreamId}; +use {frame, proto, Peer, ConnectionError, StreamId}; use http; - use futures::{Future, Poll}; - use tokio_io::{AsyncRead, AsyncWrite}; +use std::fmt; + /// In progress H2 connection binding pub struct Handshake { // TODO: unbox @@ -108,3 +108,9 @@ impl Future for Handshake { self.inner.poll() } } + +impl fmt::Debug for Handshake { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + write!(fmt, "Handshake") + } +} diff --git a/src/error.rs b/src/error.rs index b6de333..3fc594b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,6 +9,7 @@ pub enum ConnectionError { Io(io::Error), } +#[derive(Debug)] pub struct StreamError(Reason); #[derive(Debug, PartialEq, Eq, Clone, Copy)] diff --git a/src/frame/head.rs b/src/frame/head.rs index b7b0c6a..a0d5dc7 100644 --- a/src/frame/head.rs +++ b/src/frame/head.rs @@ -1,5 +1,3 @@ -use super::Error; - use bytes::{BufMut, BigEndian}; #[derive(Debug, Copy, Clone, PartialEq, Eq)] diff --git a/src/frame/headers.rs b/src/frame/headers.rs index 35866cc..6646859 100644 --- a/src/frame/headers.rs +++ b/src/frame/headers.rs @@ -1,6 +1,5 @@ use super::StreamId; use hpack; -use error::Reason; use frame::{self, Frame, Head, Kind, Error}; use util::byte_str::ByteStr; @@ -201,6 +200,10 @@ impl Headers { response } + pub fn into_request(self) -> request::Head { + unimplemented!(); + } + pub fn encode(self, encoder: &mut hpack::Encoder, dst: &mut BytesMut) -> Option { diff --git a/src/frame/mod.rs b/src/frame/mod.rs index 4d128c0..b0d7f62 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -1,10 +1,6 @@ use hpack; use error::{ConnectionError, Reason}; -use bytes::{Bytes, BytesMut, BufMut}; - -use std::io; - /// A helper macro that unpacks a sequence of 4 bytes found in the buffer with /// the given identifier, starting at the given offset, into the given integer /// type. Obviously, the integer type should be able to support at least 4 @@ -113,8 +109,6 @@ impl Frame { impl From for ConnectionError { fn from(src: Error) -> ConnectionError { - use self::Error::*; - match src { // TODO: implement _ => ConnectionError::Proto(Reason::ProtocolError), diff --git a/src/frame/reset.rs b/src/frame/reset.rs index 36be347..2cd7d92 100644 --- a/src/frame/reset.rs +++ b/src/frame/reset.rs @@ -1,5 +1,5 @@ use frame::{Head, Error}; -use super::{head, StreamId}; +use super::{StreamId}; #[derive(Debug)] pub struct Reset { diff --git a/src/frame/settings.rs b/src/frame/settings.rs index 0d81d8f..e206529 100644 --- a/src/frame/settings.rs +++ b/src/frame/settings.rs @@ -1,5 +1,5 @@ use frame::{Frame, Error, Head, Kind}; -use bytes::{Bytes, BytesMut, BufMut, BigEndian}; +use bytes::{BytesMut, BufMut, BigEndian}; #[derive(Debug, Clone, Default, Eq, PartialEq)] pub struct Settings { diff --git a/src/hpack/decoder.rs b/src/hpack/decoder.rs index 4faf690..ecad3c9 100644 --- a/src/hpack/decoder.rs +++ b/src/hpack/decoder.rs @@ -1,8 +1,8 @@ -use super::{huffman, header as h2_header, Header}; +use super::{huffman, Header}; use frame; use util::byte_str::FromUtf8Error; -use http::{method, header, status, StatusCode, Method}; +use http::{method, header, status}; use bytes::{Buf, Bytes, BytesMut}; use std::cmp; @@ -409,10 +409,6 @@ impl Table { } } - fn max_size(&self) -> usize { - self.max_size - } - fn size(&self) -> usize { self.size } @@ -492,33 +488,36 @@ impl Table { // ===== impl DecoderError ===== impl From for DecoderError { - fn from(src: FromUtf8Error) -> DecoderError { + fn from(_: FromUtf8Error) -> DecoderError { + // TODO: Better error? DecoderError::InvalidUtf8 } } impl From for DecoderError { - fn from(src: header::InvalidValueError) -> DecoderError { + fn from(_: header::InvalidValueError) -> DecoderError { // TODO: Better error? DecoderError::InvalidUtf8 } } impl From for DecoderError { - fn from(src: method::FromBytesError) -> DecoderError { + fn from(_: method::FromBytesError) -> DecoderError { // TODO: Better error DecoderError::InvalidUtf8 } } impl From for DecoderError { - fn from(src: header::FromBytesError) -> DecoderError { + fn from(_: header::FromBytesError) -> DecoderError { + // TODO: Better error DecoderError::InvalidUtf8 } } impl From for DecoderError { - fn from(src: status::FromStrError) -> DecoderError { + fn from(_: status::FromStrError) -> DecoderError { + // TODO: Better error DecoderError::InvalidUtf8 } } diff --git a/src/hpack/encoder.rs b/src/hpack/encoder.rs index c496136..799b9ca 100644 --- a/src/hpack/encoder.rs +++ b/src/hpack/encoder.rs @@ -57,7 +57,7 @@ impl Encoder { self.size_update = Some(SizeUpdate::One(val)); } } - Some(SizeUpdate::Two(min, max)) => { + Some(SizeUpdate::Two(min, _)) => { if val < min { self.size_update = Some(SizeUpdate::One(val)); } else { @@ -179,7 +179,6 @@ impl Encoder { { match *index { Index::Indexed(idx, _) => { - let header = self.table.resolve(&index); try!(encode_int(idx, 7, 0x80, dst)); } Index::Name(idx, _) => { @@ -191,7 +190,7 @@ impl Encoder { header.is_sensitive(), dst)); } - Index::Inserted(idx) => { + Index::Inserted(_) => { let header = self.table.resolve(&index); assert!(!header.is_sensitive()); @@ -323,14 +322,14 @@ fn encode_str(val: &[u8], dst: &mut BytesMut) -> Result<(), EncoderError> { if encode_int_one_byte(huff_len, 7) { // Write the string head - dst[idx] = (0x80 | huff_len as u8); + dst[idx] = 0x80 | huff_len as u8; } else { // Write the head to a placeholer let mut buf = [0; 8]; let head_len = { let mut head_dst = Cursor::new(&mut buf); - encode_int(huff_len, 7, 0x80, &mut head_dst); + try!(encode_int(huff_len, 7, 0x80, &mut head_dst)); head_dst.position() as usize }; @@ -407,7 +406,6 @@ fn encode_int( } dst.put_u8(value as u8); - rem -= 1; Ok(()) } diff --git a/src/hpack/header.rs b/src/hpack/header.rs index c5b11b1..66bf08e 100644 --- a/src/hpack/header.rs +++ b/src/hpack/header.rs @@ -1,5 +1,5 @@ use super::DecoderError; -use util::byte_str::{ByteStr, FromUtf8Error}; +use util::byte_str::ByteStr; use http::{Method, StatusCode}; use http::header::{HeaderName, HeaderValue}; @@ -104,7 +104,7 @@ impl Header { Header::Path(ref v) => { 32 + 5 + v.len() } - Header::Status(ref v) => { + Header::Status(_) => { 32 + 7 + 3 } } diff --git a/src/hpack/huffman/mod.rs b/src/hpack/huffman/mod.rs index fee3163..81fa93c 100644 --- a/src/hpack/huffman/mod.rs +++ b/src/hpack/huffman/mod.rs @@ -52,7 +52,7 @@ pub fn encode(src: &[u8], dst: &mut B) -> Result<(), EncoderError> { bits |= code << (bits_left - nbits); bits_left -= nbits; - while (bits_left <= 32) { + while bits_left <= 32 { if rem == 0 { return Err(EncoderError::BufferOverflow); } diff --git a/src/hpack/table.rs b/src/hpack/table.rs index d57f0a1..bb64cc8 100644 --- a/src/hpack/table.rs +++ b/src/hpack/table.rs @@ -1,8 +1,7 @@ use super::Header; use fnv::FnvHasher; -use http::method; -use http::header::{self, HeaderName, HeaderValue}; +use http::{method, header}; use std::{cmp, mem, usize}; use std::collections::VecDeque; @@ -193,7 +192,7 @@ impl Table { return self.index_vacant(header, hash, dist, probe, statik); } else if pos.hash == hash && self.slots[slot_idx].header.name() == header.name() { // Matching name, check values - return self.index_occupied(header, hash, pos.index, statik); + return self.index_occupied(header, hash, pos.index); } } else { return self.index_vacant(header, hash, dist, probe, statik); @@ -206,8 +205,7 @@ impl Table { fn index_occupied(&mut self, header: Header, hash: HashValue, - mut index: usize, - statik: Option<(usize, bool)>) + mut index: usize) -> Index { debug_assert!(self.assert_valid_state("top")); @@ -255,8 +253,6 @@ impl Table { // it when inserting the new one... return Index::InsertedValue(real_idx + DYN_OFFSET, 0); } - - Index::NotIndexed(header) } fn index_vacant(&mut self, @@ -302,7 +298,7 @@ impl Table { let pos_idx = 0usize.wrapping_sub(self.inserted); - let mut prev = mem::replace(&mut self.indices[probe], Some(Pos { + let prev = mem::replace(&mut self.indices[probe], Some(Pos { index: pos_idx, hash: hash, })); @@ -513,9 +509,15 @@ impl Table { } } - /// Checks that the internal map state is correct + #[cfg(not(test))] + fn assert_valid_state(&self, _: &'static str) -> bool { + true + } + + #[cfg(test)] fn assert_valid_state(&self, msg: &'static str) -> bool { - /* + // Checks that the internal map structure is valid + // // Ensure all hash codes in indices match the associated slot for pos in &self.indices { if let Some(pos) = *pos { @@ -596,7 +598,6 @@ impl Table { } // TODO: Ensure linked lists are correct: no cycles, etc... - */ true } @@ -715,7 +716,7 @@ fn index_static(header: &Header) -> Option<(usize, bool)> { _ => None, } } - Header::Authority(ref v) => Some((1, false)), + Header::Authority(_) => Some((1, false)), Header::Method(ref v) => { match *v { method::GET => Some((2, true)), diff --git a/src/lib.rs b/src/lib.rs index 9accba8..25c6319 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ -#![allow(warnings)] +// #![allow(warnings)] +#![deny(missing_debug_implementations)] #[macro_use] extern crate futures; diff --git a/src/proto/connection.rs b/src/proto/connection.rs index 90f41e8..a7d216a 100644 --- a/src/proto/connection.rs +++ b/src/proto/connection.rs @@ -4,7 +4,7 @@ use proto::{self, ReadySink, State}; use tokio_io::{AsyncRead, AsyncWrite}; -use http::{self, request, response}; +use http::{request}; use futures::*; @@ -92,7 +92,6 @@ impl Stream for Connection } Some(frame) => panic!("unexpected frame; frame={:?}", frame), None => return Ok(Async::Ready(None)), - _ => unimplemented!(), }; Ok(Async::Ready(Some(frame))) @@ -144,6 +143,7 @@ impl Sink for Connection Ok(AsyncSink::Ready) } + /* Frame::Trailers { id, headers } => { unimplemented!(); } @@ -156,6 +156,8 @@ impl Sink for Connection Frame::Error { id, error } => { unimplemented!(); } + */ + _ => unimplemented!(), } } diff --git a/src/proto/framed_read.rs b/src/proto/framed_read.rs index 80bd254..8fd4d0e 100644 --- a/src/proto/framed_read.rs +++ b/src/proto/framed_read.rs @@ -5,12 +5,12 @@ use proto::ReadySink; use futures::*; -use bytes::{Bytes, BytesMut, Buf}; +use bytes::Bytes; use tokio_io::{AsyncRead}; use tokio_io::codec::length_delimited; -use std::io::{self, Write, Cursor}; +use std::io::{self, Cursor}; #[derive(Debug)] pub struct FramedRead { @@ -26,7 +26,7 @@ pub struct FramedRead { #[derive(Debug)] enum Partial { Headers(frame::Headers), - PushPromise(frame::PushPromise), + // PushPromise(frame::PushPromise), } impl FramedRead @@ -113,7 +113,7 @@ impl Stream for FramedRead fn poll(&mut self) -> Poll, ConnectionError> { loop { - let mut bytes = match try_ready!(self.inner.poll()) { + let bytes = match try_ready!(self.inner.poll()) { Some(bytes) => bytes.freeze(), None => return Ok(Async::Ready(None)), }; diff --git a/src/proto/framed_write.rs b/src/proto/framed_write.rs index eb48526..ae7e40f 100644 --- a/src/proto/framed_write.rs +++ b/src/proto/framed_write.rs @@ -1,11 +1,10 @@ -use {hpack, ConnectionError, Reason}; -use frame::{self, Frame, Error}; +use {hpack, ConnectionError}; +use frame::{self, Frame}; use proto::ReadySink; use futures::*; use tokio_io::{AsyncRead, AsyncWrite}; -use bytes::{Bytes, BytesMut, Buf, BufMut}; -use http::header::{self, HeaderValue}; +use bytes::{BytesMut, Buf, BufMut}; use std::cmp; use std::io::{self, Cursor}; @@ -110,6 +109,7 @@ impl Sink for FramedWrite { } } Frame::PushPromise(v) => { + debug!("unimplemented PUSH_PROMISE write; frame={:?}", v); unimplemented!(); } Frame::Settings(v) => { diff --git a/src/util/byte_str.rs b/src/util/byte_str.rs index fd6981e..6882941 100644 --- a/src/util/byte_str.rs +++ b/src/util/byte_str.rs @@ -8,9 +8,9 @@ pub struct ByteStr { bytes: Bytes, } +#[derive(Debug)] pub struct FromUtf8Error { err: Utf8Error, - val: Bytes, } impl ByteStr { @@ -28,7 +28,6 @@ impl ByteStr { if let Err(e) = str::from_utf8(&bytes[..]) { return Err(FromUtf8Error { err: e, - val: bytes, }); }