Skip to content

Commit 0f5858f

Browse files
committed
fix(rustup): update to rust beta
1 parent b4aeeb3 commit 0f5858f

File tree

12 files changed

+79
-74
lines changed

12 files changed

+79
-74
lines changed

src/client/response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mod tests {
171171
None => panic!("Transfer-Encoding: chunked expected!"),
172172
};
173173
// The body is correct?
174-
assert_eq!(read_to_string(res), Ok("qwert".to_string()));
174+
assert_eq!(read_to_string(res).unwrap(), "qwert".to_string());
175175
}
176176

177177
/// Tests that when a chunk size is not a valid radix-16 number, an error
@@ -228,6 +228,6 @@ mod tests {
228228

229229
let res = Response::new(Box::new(stream)).unwrap();
230230

231-
assert_eq!(read_to_string(res), Ok("1".to_string()));
231+
assert_eq!(read_to_string(res).unwrap(), "1".to_string());
232232
}
233233
}

src/error.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! HttpError and HttpResult module.
2-
use std::error::{Error, FromError};
2+
use std::error::Error;
33
use std::fmt;
44
use std::io::Error as IoError;
55

@@ -15,7 +15,7 @@ use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError,
1515
pub type HttpResult<T> = Result<T, HttpError>;
1616

1717
/// A set of errors that can occur parsing HTTP streams.
18-
#[derive(Debug, PartialEq, Clone)]
18+
#[derive(Debug)]
1919
pub enum HttpError {
2020
/// An invalid `Method`, such as `GE,T`.
2121
HttpMethodError,
@@ -61,20 +61,20 @@ impl Error for HttpError {
6161
}
6262
}
6363

64-
impl FromError<IoError> for HttpError {
65-
fn from_error(err: IoError) -> HttpError {
64+
impl From<IoError> for HttpError {
65+
fn from(err: IoError) -> HttpError {
6666
HttpIoError(err)
6767
}
6868
}
6969

70-
impl FromError<url::ParseError> for HttpError {
71-
fn from_error(err: url::ParseError) -> HttpError {
70+
impl From<url::ParseError> for HttpError {
71+
fn from(err: url::ParseError) -> HttpError {
7272
HttpUriError(err)
7373
}
7474
}
7575

76-
impl FromError<httparse::Error> for HttpError {
77-
fn from_error(err: httparse::Error) -> HttpError {
76+
impl From<httparse::Error> for HttpError {
77+
fn from(err: httparse::Error) -> HttpError {
7878
match err {
7979
httparse::Error::HeaderName => HttpHeaderError,
8080
httparse::Error::HeaderValue => HttpHeaderError,

src/header/common/expect.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use std::fmt;
2+
use std::str;
3+
4+
use unicase::UniCase;
25

36
use header::{Header, HeaderFormat};
47

@@ -16,14 +19,29 @@ pub enum Expect {
1619
Continue
1720
}
1821

22+
const EXPECT_CONTINUE: UniCase<&'static str> = UniCase("100-continue");
23+
1924
impl Header for Expect {
2025
fn header_name() -> &'static str {
2126
"Expect"
2227
}
2328

2429
fn parse_header(raw: &[Vec<u8>]) -> Option<Expect> {
25-
if &[b"100-continue"] == raw {
26-
Some(Expect::Continue)
30+
if raw.len() == 1 {
31+
let text = unsafe {
32+
// safe because:
33+
// 1. we just checked raw.len == 1
34+
// 2. we don't actually care if it's utf8, we just want to
35+
// compare the bytes with the "case" normalized. If it's not
36+
// utf8, then the byte comparison will fail, and we'll return
37+
// None. No big deal.
38+
str::from_utf8_unchecked(raw.get_unchecked(0))
39+
};
40+
if UniCase(text) == EXPECT_CONTINUE {
41+
Some(Expect::Continue)
42+
} else {
43+
None
44+
}
2745
} else {
2846
None
2947
}

src/header/shared/entity.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ mod tests {
141141
#[test]
142142
fn test_etag_parse_success() {
143143
// Expected success
144-
assert_eq!("\"foobar\"".parse().unwrap(), EntityTag::new(false, "foobar".to_string()));
145-
assert_eq!("\"\"".parse().unwrap(), EntityTag::new(false, "".to_string()));
146-
assert_eq!("W/\"weaktag\"".parse().unwrap(), EntityTag::new(true, "weaktag".to_string()));
147-
assert_eq!("W/\"\x65\x62\"".parse().unwrap(), EntityTag::new(true, "\x65\x62".to_string()));
148-
assert_eq!("W/\"\"".parse().unwrap(), EntityTag::new(true, "".to_string()));
144+
assert_eq!("\"foobar\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "foobar".to_string()));
145+
assert_eq!("\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "".to_string()));
146+
assert_eq!("W/\"weaktag\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "weaktag".to_string()));
147+
assert_eq!("W/\"\x65\x62\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "\x65\x62".to_string()));
148+
assert_eq!("W/\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "".to_string()));
149149
}
150150

151151
#[test]

src/header/shared/quality_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<T: str::FromStr> str::FromStr for QualityItem<T> {
114114
let mut raw_item = s;
115115
let mut quality = 1f32;
116116

117-
let parts: Vec<&str> = s.rsplitn(1, ';').map(|x| x.trim()).collect();
117+
let parts: Vec<&str> = s.rsplitn(2, ';').map(|x| x.trim()).collect();
118118
if parts.len() == 2 {
119119
let start = &parts[0][0..2];
120120
if start == "q=" || start == "Q=" {

src/http.rs

+23-27
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ fn eat<R: Read>(rdr: &mut R, bytes: &[u8]) -> io::Result<()> {
120120
match try!(rdr.read(&mut buf)) {
121121
1 if buf[0] == b => (),
122122
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
123-
"Invalid characters found",
124-
None))
123+
"Invalid characters found")),
125124
}
126125
}
127126
Ok(())
@@ -135,8 +134,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> {
135134
match try!($rdr.read(&mut buf)) {
136135
1 => buf[0],
137136
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
138-
"Invalid chunk size line",
139-
None)),
137+
"Invalid chunk size line")),
140138

141139
}
142140
})
@@ -163,8 +161,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> {
163161
match byte!(rdr) {
164162
LF => break,
165163
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
166-
"Invalid chunk size line",
167-
None))
164+
"Invalid chunk size line"))
168165

169166
}
170167
},
@@ -190,8 +187,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> {
190187
// other octet, the chunk size line is invalid!
191188
_ => {
192189
return Err(io::Error::new(io::ErrorKind::InvalidInput,
193-
"Invalid chunk size line",
194-
None))
190+
"Invalid chunk size line"));
195191
}
196192
}
197193
}
@@ -441,7 +437,7 @@ mod tests {
441437
use std::str::from_utf8;
442438
let mut w = super::HttpWriter::SizedWriter(Vec::new(), 8);
443439
w.write_all(b"foo bar").unwrap();
444-
assert_eq!(w.write(b"baz"), Ok(1));
440+
assert_eq!(w.write(b"baz").unwrap(), 1);
445441

446442
let buf = w.end().unwrap();
447443
let s = from_utf8(buf.as_ref()).unwrap();
@@ -450,22 +446,22 @@ mod tests {
450446

451447
#[test]
452448
fn test_read_chunk_size() {
453-
fn read(s: &str, result: io::Result<u64>) {
454-
assert_eq!(read_chunk_size(&mut s.as_bytes()), result);
449+
fn read(s: &str, result: u64) {
450+
assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap(), result);
455451
}
456452

457453
fn read_err(s: &str) {
458454
assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap_err().kind(), io::ErrorKind::InvalidInput);
459455
}
460456

461-
read("1\r\n", Ok(1));
462-
read("01\r\n", Ok(1));
463-
read("0\r\n", Ok(0));
464-
read("00\r\n", Ok(0));
465-
read("A\r\n", Ok(10));
466-
read("a\r\n", Ok(10));
467-
read("Ff\r\n", Ok(255));
468-
read("Ff \r\n", Ok(255));
457+
read("1\r\n", 1);
458+
read("01\r\n", 1);
459+
read("0\r\n", 0);
460+
read("00\r\n", 0);
461+
read("A\r\n", 10);
462+
read("a\r\n", 10);
463+
read("Ff\r\n", 255);
464+
read("Ff \r\n", 255);
469465
// Missing LF or CRLF
470466
read_err("F\rF");
471467
read_err("F");
@@ -475,14 +471,14 @@ mod tests {
475471
read_err("-\r\n");
476472
read_err("-1\r\n");
477473
// Acceptable (if not fully valid) extensions do not influence the size
478-
read("1;extension\r\n", Ok(1));
479-
read("a;ext name=value\r\n", Ok(10));
480-
read("1;extension;extension2\r\n", Ok(1));
481-
read("1;;; ;\r\n", Ok(1));
482-
read("2; extension...\r\n", Ok(2));
483-
read("3 ; extension=123\r\n", Ok(3));
484-
read("3 ;\r\n", Ok(3));
485-
read("3 ; \r\n", Ok(3));
474+
read("1;extension\r\n", 1);
475+
read("a;ext name=value\r\n", 10);
476+
read("1;extension;extension2\r\n", 1);
477+
read("1;;; ;\r\n", 1);
478+
read("2; extension...\r\n", 2);
479+
read("3 ; extension=123\r\n", 3);
480+
read("3 ;\r\n", 3);
481+
read("3 ; \r\n", 3);
486482
// Invalid extensions cause an error
487483
read_err("1 invalid extension\r\n");
488484
read_err("1 A\r\n");

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![doc(html_root_url = "https://hyperium.github.io/hyper/hyper/index.html")]
2-
#![feature(core, io, unsafe_destructor, into_cow, convert)]
2+
#![feature(core, into_cow)]
33
#![deny(missing_docs)]
44
#![cfg_attr(test, deny(warnings))]
55
#![cfg_attr(test, feature(test))]

src/method.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ mod tests {
129129

130130
#[test]
131131
fn test_from_str() {
132-
assert_eq!(Ok(Get), FromStr::from_str("GET"));
133-
assert_eq!(Ok(Extension("MOVE".to_string())),
134-
FromStr::from_str("MOVE"));
132+
assert_eq!(Get, FromStr::from_str("GET").unwrap());
133+
assert_eq!(Extension("MOVE".to_string()),
134+
FromStr::from_str("MOVE").unwrap());
135135
}
136136

137137
#[test]

src/net.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,9 @@ impl NetworkListener for HttpListener {
202202
let stream = CloneTcpStream(try!(tcp.accept()).0);
203203
match SslStream::new_server(&**ssl_context, stream) {
204204
Ok(ssl_stream) => HttpStream::Https(ssl_stream),
205-
Err(StreamError(ref e)) => {
205+
Err(StreamError(e)) => {
206206
return Err(io::Error::new(io::ErrorKind::ConnectionAborted,
207-
"SSL Handshake Interrupted",
208-
Some(e.to_string())));
207+
e));
209208
},
210209
Err(e) => return Err(lift_ssl_error(e))
211210
}
@@ -326,8 +325,7 @@ impl<'v> NetworkConnector for HttpConnector<'v> {
326325
},
327326
_ => {
328327
Err(io::Error::new(io::ErrorKind::InvalidInput,
329-
"Invalid scheme for Http",
330-
None))
328+
"Invalid scheme for Http"))
331329
}
332330
}
333331
}
@@ -338,13 +336,8 @@ fn lift_ssl_error(ssl: SslError) -> io::Error {
338336
match ssl {
339337
StreamError(err) => err,
340338
SslSessionClosed => io::Error::new(io::ErrorKind::ConnectionAborted,
341-
"SSL Connection Closed",
342-
None),
343-
// Unfortunately throw this away. No way to support this
344-
// detail without a better Error abstraction.
345-
OpenSslErrors(errs) => io::Error::new(io::ErrorKind::Other,
346-
"Error in OpenSSL",
347-
Some(format!("{:?}", errs)))
339+
"SSL Connection Closed"),
340+
e@OpenSslErrors(..) => io::Error::new(io::ErrorKind::Other, e)
348341
}
349342
}
350343

src/server/listener.rs

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ impl<T: Send + 'static> Sentinel<T> {
7373
//fn cancel(mut self) { self.active = false; }
7474
}
7575

76-
#[unsafe_destructor]
7776
impl<T: Send + 'static> Drop for Sentinel<T> {
7877
fn drop(&mut self) {
7978
// If we were cancelled, get out of here.

src/server/request.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ mod tests {
115115
let mut stream = BufReader::new(mock);
116116

117117
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
118-
assert_eq!(read_to_string(req), Ok("".to_string()));
118+
assert_eq!(read_to_string(req).unwrap(), "".to_string());
119119
}
120120

121121
#[test]
@@ -132,7 +132,7 @@ mod tests {
132132
let mut stream = BufReader::new(mock);
133133

134134
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
135-
assert_eq!(read_to_string(req), Ok("".to_string()));
135+
assert_eq!(read_to_string(req).unwrap(), "".to_string());
136136
}
137137

138138
#[test]
@@ -149,7 +149,7 @@ mod tests {
149149
let mut stream = BufReader::new(mock);
150150

151151
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
152-
assert_eq!(read_to_string(req), Ok("".to_string()));
152+
assert_eq!(read_to_string(req).unwrap(), "".to_string());
153153
}
154154

155155
#[test]
@@ -190,7 +190,7 @@ mod tests {
190190
None => panic!("Transfer-Encoding: chunked expected!"),
191191
};
192192
// The content is correctly read?
193-
assert_eq!(read_to_string(req), Ok("qwert".to_string()));
193+
assert_eq!(read_to_string(req).unwrap(), "qwert".to_string());
194194
}
195195

196196
/// Tests that when a chunk size is not a valid radix-16 number, an error
@@ -262,7 +262,7 @@ mod tests {
262262

263263
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
264264

265-
assert_eq!(read_to_string(req), Ok("1".to_string()));
265+
assert_eq!(read_to_string(req).unwrap(), "1".to_string());
266266
}
267267

268268
}

src/uri.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,14 @@ impl FromStr for RequestUri {
7474

7575
#[test]
7676
fn test_uri_fromstr() {
77-
use error::HttpResult;
78-
fn read(s: &str, result: HttpResult<RequestUri>) {
79-
assert_eq!(s.parse(), result);
77+
fn read(s: &str, result: RequestUri) {
78+
assert_eq!(s.parse::<RequestUri>().unwrap(), result);
8079
}
8180

82-
read("*", Ok(RequestUri::Star));
83-
read("http://hyper.rs/", Ok(RequestUri::AbsoluteUri(Url::parse("http://hyper.rs/").unwrap())));
84-
read("hyper.rs", Ok(RequestUri::Authority("hyper.rs".to_string())));
85-
read("/", Ok(RequestUri::AbsolutePath("/".to_string())));
81+
read("*", RequestUri::Star);
82+
read("http://hyper.rs/", RequestUri::AbsoluteUri(Url::parse("http://hyper.rs/").unwrap()));
83+
read("hyper.rs", RequestUri::Authority("hyper.rs".to_string()));
84+
read("/", RequestUri::AbsolutePath("/".to_string()));
8685
}
8786

8887

0 commit comments

Comments
 (0)