Skip to content

Commit

Permalink
Fix all deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Jul 8, 2019
1 parent 73002d2 commit cece1b8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl Error {
}

/// Return a reference to the lower level, inner error.
#[allow(warnings)]
pub fn get_ref(&self) -> &(error::Error + 'static) {
use self::ErrorKind::*;

Expand Down Expand Up @@ -83,7 +84,7 @@ impl error::Error for Error {

// Return any available cause from the inner error. Note the inner error is
// not itself the cause.
#[allow(deprecated)]
#[allow(warnings)]
fn cause(&self) -> Option<&error::Error> {
self.get_ref().cause()
}
Expand Down
26 changes: 20 additions & 6 deletions src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::collections::HashMap;
use std::hash::{BuildHasherDefault, Hasher};
use std::fmt;

// `Box<Any>` is now `Box<dyn Any>`, but we can't change yet (minimum Rust)
#[allow(warnings)]
type AnyMap = HashMap<TypeId, Box<Any + Send + Sync>, BuildHasherDefault<IdHasher>>;

// With TypeIds as keys, there's no need to hash them. They are already hashes
Expand Down Expand Up @@ -69,11 +71,13 @@ impl Extensions {
.get_or_insert_with(|| Box::new(HashMap::default()))
.insert(TypeId::of::<T>(), Box::new(val))
.and_then(|boxed| {
//TODO: we can use unsafe and remove double checking the type id
#[allow(warnings)]
{
(boxed as Box<Any + 'static>)
.downcast()
.ok()
.map(|boxed| *boxed)
}
})
}

Expand All @@ -94,8 +98,12 @@ impl Extensions {
.map
.as_ref()
.and_then(|map| map.get(&TypeId::of::<T>()))
//TODO: we can use unsafe and remove double checking the type id
.and_then(|boxed| (&**boxed as &(Any + 'static)).downcast_ref())
.and_then(|boxed| {
#[allow(warnings)]
{
(&**boxed as &(Any + 'static)).downcast_ref()
}
})
}

/// Get a mutable reference to a type previously inserted on this `Extensions`.
Expand All @@ -115,8 +123,12 @@ impl Extensions {
.map
.as_mut()
.and_then(|map| map.get_mut(&TypeId::of::<T>()))
//TODO: we can use unsafe and remove double checking the type id
.and_then(|boxed| (&mut **boxed as &mut (Any + 'static)).downcast_mut())
.and_then(|boxed| {
#[allow(warnings)]
{
(&mut **boxed as &mut (Any + 'static)).downcast_mut()
}
})
}


Expand All @@ -139,11 +151,13 @@ impl Extensions {
.as_mut()
.and_then(|map| map.remove(&TypeId::of::<T>()))
.and_then(|boxed| {
//TODO: we can use unsafe and remove double checking the type id
#[allow(warnings)]
{
(boxed as Box<Any + 'static>)
.downcast()
.ok()
.map(|boxed| *boxed)
}
})
}

Expand Down
5 changes: 5 additions & 0 deletions src/header/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,7 @@ impl HeaderName {
/// Converts a slice of bytes to an HTTP header name.
///
/// This function normalizes the input.
#[allow(deprecated)]
pub fn from_bytes(src: &[u8]) -> Result<HeaderName, InvalidHeaderName> {
let mut buf = unsafe { mem::uninitialized() };
match parse_hdr(src, &mut buf, &HEADER_CHARS)?.inner {
Expand Down Expand Up @@ -1578,6 +1579,7 @@ impl HeaderName {
/// // Parsing a header that contains uppercase characters
/// assert!(HeaderName::from_lowercase(b"Content-Length").is_err());
/// ```
#[allow(deprecated)]
pub fn from_lowercase(src: &[u8]) -> Result<HeaderName, InvalidHeaderName> {
let mut buf = unsafe { mem::uninitialized() };
match parse_hdr(src, &mut buf, &HEADER_CHARS_H2)?.inner {
Expand Down Expand Up @@ -1636,6 +1638,7 @@ impl HeaderName {
/// let a = HeaderName::from_static("foobar");
/// let b = HeaderName::from_static("FOOBAR"); // This line panics!
/// ```
#[allow(deprecated)]
pub fn from_static(src: &'static str) -> HeaderName {
let bytes = src.as_bytes();
let mut buf = unsafe { mem::uninitialized() };
Expand Down Expand Up @@ -1913,6 +1916,7 @@ impl<'a> HdrName<'a> {
}
}

#[allow(deprecated)]
pub fn from_bytes<F, U>(hdr: &[u8], f: F) -> Result<U, InvalidHeaderName>
where F: FnOnce(HdrName) -> U,
{
Expand All @@ -1921,6 +1925,7 @@ impl<'a> HdrName<'a> {
Ok(f(hdr))
}

#[allow(deprecated)]
pub fn from_static<F, U>(hdr: &'static str, f: F) -> U
where F: FnOnce(HdrName) -> U,
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
//!
//! let uri = "https://www.rust-lang.org/index.html".parse::<Uri>().unwrap();
//!
//! assert_eq!(uri.scheme(), Some("https"));
//! assert_eq!(uri.scheme_str(), Some("https"));
//! assert_eq!(uri.host(), Some("www.rust-lang.org"));
//! assert_eq!(uri.path(), "/index.html");
//! assert_eq!(uri.query(), None);
Expand Down
8 changes: 8 additions & 0 deletions src/uri/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ impl PathAndQuery {
let mut fragment = None;

// block for iterator borrow
//
// allow: `...` pattersn are now `..=`, but we cannot update yet
// because of minimum Rust version
#[allow(warnings)]
{
let mut iter = src.as_ref().iter().enumerate();

Expand Down Expand Up @@ -78,6 +82,10 @@ impl PathAndQuery {

// query ...
if query != NONE {

// allow: `...` pattersn are now `..=`, but we cannot update yet
// because of minimum Rust version
#[allow(warnings)]
for (i, &b) in iter {
match b {
// While queries *should* be percent-encoded, most
Expand Down
2 changes: 1 addition & 1 deletion tests/header_map_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl Action {
}
Action::Remove { name, val } => {
// Just to help track the state, load all associated values.
map.get_all(&name).iter().collect::<Vec<_>>();
let _ = map.get_all(&name).iter().collect::<Vec<_>>();

let actual = map.remove(&name);
assert_eq!(actual, val);
Expand Down

0 comments on commit cece1b8

Please sign in to comment.