From 34a741a26ecdfd443e79bb4c0c3880ce15a767b0 Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Mon, 8 Apr 2019 23:57:47 -0400 Subject: [PATCH] Remove use of '!' type in favor of 'Infallible'. This removes the use of and dependence on the 'never_type' feature. --- contrib/lib/src/lib.rs | 1 - core/http/src/cookies.rs | 6 ++--- core/lib/src/data/from_data.rs | 2 +- core/lib/src/lib.rs | 1 - core/lib/src/request/form/from_form.rs | 8 +++--- core/lib/src/request/form/from_form_value.rs | 6 ++--- core/lib/src/request/from_request.rs | 27 ++++++++++---------- core/lib/src/request/param.rs | 16 ++++++------ core/lib/src/request/query.rs | 4 +-- examples/request_guard/src/main.rs | 6 ++--- examples/session/src/main.rs | 6 ++--- 11 files changed, 40 insertions(+), 43 deletions(-) diff --git a/contrib/lib/src/lib.rs b/contrib/lib/src/lib.rs index 44872cb8..a30cda83 100644 --- a/contrib/lib/src/lib.rs +++ b/contrib/lib/src/lib.rs @@ -1,5 +1,4 @@ #![feature(crate_visibility_modifier)] -#![feature(never_type)] #![feature(doc_cfg)] #![doc(html_root_url = "https://api.rocket.rs/v0.5")] diff --git a/core/http/src/cookies.rs b/core/http/src/cookies.rs index a66acce8..caf7f3ba 100644 --- a/core/http/src/cookies.rs +++ b/core/http/src/cookies.rs @@ -74,7 +74,7 @@ mod key { /// [private cookie]: Cookies::add_private() /// /// ```rust -/// # #![feature(proc_macro_hygiene, decl_macro, never_type)] +/// # #![feature(proc_macro_hygiene, decl_macro)] /// # #[macro_use] extern crate rocket; /// # /// use rocket::http::Status; @@ -85,9 +85,9 @@ mod key { /// struct User(usize); /// /// impl FromRequest<'_, '_> for User { -/// type Error = !; +/// type Error = std::convert::Infallible; /// -/// fn from_request(request: &Request<'_>) -> request::Outcome { +/// fn from_request(request: &Request<'_>) -> request::Outcome { /// request.cookies() /// .get_private("user_id") /// .and_then(|cookie| cookie.value().parse().ok()) diff --git a/core/lib/src/data/from_data.rs b/core/lib/src/data/from_data.rs index 41a1fa74..03d63576 100644 --- a/core/lib/src/data/from_data.rs +++ b/core/lib/src/data/from_data.rs @@ -388,7 +388,7 @@ pub trait FromData<'a>: Sized { /// The identity implementation of `FromData`. Always returns `Success`. impl<'f> FromData<'f> for Data { - type Error = !; + type Error = std::convert::Infallible; type Owned = Data; type Borrowed = Data; diff --git a/core/lib/src/lib.rs b/core/lib/src/lib.rs index c20afa19..7e1afa7a 100644 --- a/core/lib/src/lib.rs +++ b/core/lib/src/lib.rs @@ -1,7 +1,6 @@ #![feature(specialization)] #![feature(decl_macro)] #![feature(try_trait)] -#![feature(never_type)] #![feature(proc_macro_hygiene)] #![feature(crate_visibility_modifier)] #![feature(label_break_value)] diff --git a/core/lib/src/request/form/from_form.rs b/core/lib/src/request/form/from_form.rs index c57a5a06..45b5d788 100644 --- a/core/lib/src/request/form/from_form.rs +++ b/core/lib/src/request/form/from_form.rs @@ -111,19 +111,19 @@ pub trait FromForm<'f>: Sized { } impl<'f, T: FromForm<'f>> FromForm<'f> for Option { - type Error = !; + type Error = std::convert::Infallible; #[inline] - fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result, !> { + fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result, Self::Error> { Ok(T::from_form(items, strict).ok()) } } impl<'f, T: FromForm<'f>> FromForm<'f> for Result { - type Error = !; + type Error = std::convert::Infallible; #[inline] - fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result { + fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result { Ok(T::from_form(items, strict)) } } diff --git a/core/lib/src/request/form/from_form_value.rs b/core/lib/src/request/form/from_form_value.rs index 5c6e1d89..534f00c3 100644 --- a/core/lib/src/request/form/from_form_value.rs +++ b/core/lib/src/request/form/from_form_value.rs @@ -191,7 +191,7 @@ pub trait FromFormValue<'v>: Sized { } impl<'v> FromFormValue<'v> for &'v RawStr { - type Error = !; + type Error = std::convert::Infallible; // This just gives the raw string. #[inline(always)] @@ -248,7 +248,7 @@ impl_with_fromstr!( ); impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Option { - type Error = !; + type Error = std::convert::Infallible; #[inline(always)] fn from_form_value(v: &'v RawStr) -> Result { @@ -266,7 +266,7 @@ impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Option { // // TODO: Add more useful implementations (range, regex, etc.). impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Result { - type Error = !; + type Error = std::convert::Infallible; #[inline(always)] fn from_form_value(v: &'v RawStr) -> Result { diff --git a/core/lib/src/request/from_request.rs b/core/lib/src/request/from_request.rs index 60110499..9202f838 100644 --- a/core/lib/src/request/from_request.rs +++ b/core/lib/src/request/from_request.rs @@ -284,7 +284,6 @@ impl IntoOutcome for Result { /// /// ```rust /// # #![feature(proc_macro_hygiene, decl_macro)] -/// # #![feature(never_type)] /// # #[macro_use] extern crate rocket; /// # #[cfg(feature = "private-cookies")] mod inner { /// # use rocket::outcome::{IntoOutcome, Outcome}; @@ -306,9 +305,9 @@ impl IntoOutcome for Result { /// # struct Admin<'a> { user: &'a User } /// # /// impl<'a> FromRequest<'a, '_> for &'a User { -/// type Error = !; +/// type Error = std::convert::Infallible; /// -/// fn from_request(request: &'a Request<'_>) -> request::Outcome<&'a User, !> { +/// fn from_request(request: &'a Request<'_>) -> request::Outcome { /// // This closure will execute at most once per request, regardless of /// // the number of times the `User` guard is executed. /// let user_result = request.local_cache(|| { @@ -324,9 +323,9 @@ impl IntoOutcome for Result { /// } /// /// impl<'a> FromRequest<'a, '_> for Admin<'a> { -/// type Error = !; +/// type Error = std::convert::Infallible; /// -/// fn from_request(request: &'a Request<'_>) -> request::Outcome, !> { +/// fn from_request(request: &'a Request<'_>) -> request::Outcome { /// let user = request.guard::<&User>()?; /// /// if user.is_admin { @@ -358,7 +357,7 @@ pub trait FromRequest<'a, 'r>: Sized { } impl FromRequest<'_, '_> for Method { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &Request<'_>) -> Outcome { Success(request.method()) @@ -366,7 +365,7 @@ impl FromRequest<'_, '_> for Method { } impl<'a> FromRequest<'a, '_> for &'a Origin<'a> { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &'a Request<'_>) -> Outcome { Success(request.uri()) @@ -374,7 +373,7 @@ impl<'a> FromRequest<'a, '_> for &'a Origin<'a> { } impl<'r> FromRequest<'_, 'r> for &'r Route { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &Request<'r>) -> Outcome { match request.route() { @@ -385,7 +384,7 @@ impl<'r> FromRequest<'_, 'r> for &'r Route { } impl<'a> FromRequest<'a, '_> for Cookies<'a> { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &'a Request<'_>) -> Outcome { Success(request.cookies()) @@ -393,7 +392,7 @@ impl<'a> FromRequest<'a, '_> for Cookies<'a> { } impl<'a> FromRequest<'a, '_> for &'a Accept { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &'a Request<'_>) -> Outcome { match request.accept() { @@ -404,7 +403,7 @@ impl<'a> FromRequest<'a, '_> for &'a Accept { } impl<'a> FromRequest<'a, '_> for &'a ContentType { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &'a Request<'_>) -> Outcome { match request.content_type() { @@ -415,7 +414,7 @@ impl<'a> FromRequest<'a, '_> for &'a ContentType { } impl FromRequest<'_, '_> for SocketAddr { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &Request<'_>) -> Outcome { match request.remote() { @@ -426,7 +425,7 @@ impl FromRequest<'_, '_> for SocketAddr { } impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Result { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &'a Request<'r>) -> Outcome { match T::from_request(request) { @@ -438,7 +437,7 @@ impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Result } impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Option { - type Error = !; + type Error = std::convert::Infallible; fn from_request(request: &'a Request<'r>) -> Outcome { match T::from_request(request) { diff --git a/core/lib/src/request/param.rs b/core/lib/src/request/param.rs index 9f773bc2..9a1643b4 100644 --- a/core/lib/src/request/param.rs +++ b/core/lib/src/request/param.rs @@ -205,7 +205,7 @@ pub trait FromParam<'a>: Sized { } impl<'a> FromParam<'a> for &'a RawStr { - type Error = !; + type Error = std::convert::Infallible; #[inline(always)] fn from_param(param: &'a RawStr) -> Result<&'a RawStr, Self::Error> { @@ -258,7 +258,7 @@ impl_with_fromstr! { } impl<'a, T: FromParam<'a>> FromParam<'a> for Result { - type Error = !; + type Error = std::convert::Infallible; #[inline] fn from_param(param: &'a RawStr) -> Result { @@ -270,7 +270,7 @@ impl<'a, T: FromParam<'a>> FromParam<'a> for Result { } impl<'a, T: FromParam<'a>> FromParam<'a> for Option { - type Error = !; + type Error = std::convert::Infallible; #[inline] fn from_param(param: &'a RawStr) -> Result { @@ -309,7 +309,7 @@ pub trait FromSegments<'a>: Sized { } impl<'a> FromSegments<'a> for Segments<'a> { - type Error = !; + type Error = std::convert::Infallible; #[inline(always)] fn from_segments(segments: Segments<'a>) -> Result, Self::Error> { @@ -342,10 +342,10 @@ impl FromSegments<'_> for PathBuf { } impl<'a, T: FromSegments<'a>> FromSegments<'a> for Result { - type Error = !; + type Error = std::convert::Infallible; #[inline] - fn from_segments(segments: Segments<'a>) -> Result, !> { + fn from_segments(segments: Segments<'a>) -> Result, Self::Error> { match T::from_segments(segments) { Ok(val) => Ok(Ok(val)), Err(e) => Ok(Err(e)), @@ -354,10 +354,10 @@ impl<'a, T: FromSegments<'a>> FromSegments<'a> for Result { } impl<'a, T: FromSegments<'a>> FromSegments<'a> for Option { - type Error = !; + type Error = std::convert::Infallible; #[inline] - fn from_segments(segments: Segments<'a>) -> Result, !> { + fn from_segments(segments: Segments<'a>) -> Result, Self::Error> { match T::from_segments(segments) { Ok(val) => Ok(Some(val)), Err(_) => Ok(None) diff --git a/core/lib/src/request/query.rs b/core/lib/src/request/query.rs index 450d4c5b..3fc4191b 100644 --- a/core/lib/src/request/query.rs +++ b/core/lib/src/request/query.rs @@ -219,7 +219,7 @@ impl<'q, T: FromForm<'q>> FromQuery<'q> for LenientForm { } impl<'q, T: FromQuery<'q>> FromQuery<'q> for Option { - type Error = !; + type Error = std::convert::Infallible; #[inline] fn from_query(q: Query<'q>) -> Result { @@ -228,7 +228,7 @@ impl<'q, T: FromQuery<'q>> FromQuery<'q> for Option { } impl<'q, T: FromQuery<'q>> FromQuery<'q> for Result { - type Error = !; + type Error = std::convert::Infallible; #[inline] fn from_query(q: Query<'q>) -> Result { diff --git a/examples/request_guard/src/main.rs b/examples/request_guard/src/main.rs index fe84ce20..0008fbba 100644 --- a/examples/request_guard/src/main.rs +++ b/examples/request_guard/src/main.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene, decl_macro, never_type)] +#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; @@ -9,9 +9,9 @@ use rocket::outcome::Outcome::*; struct HeaderCount(usize); impl<'a, 'r> FromRequest<'a, 'r> for HeaderCount { - type Error = !; + type Error = std::convert::Infallible; - fn from_request(request: &'a Request<'r>) -> request::Outcome { + fn from_request(request: &'a Request<'r>) -> request::Outcome { Success(HeaderCount(request.headers().len())) } } diff --git a/examples/session/src/main.rs b/examples/session/src/main.rs index c4197c6b..6ac2e987 100644 --- a/examples/session/src/main.rs +++ b/examples/session/src/main.rs @@ -1,4 +1,4 @@ -#![feature(proc_macro_hygiene, decl_macro, never_type)] +#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; @@ -22,9 +22,9 @@ struct Login { struct User(usize); impl<'a, 'r> FromRequest<'a, 'r> for User { - type Error = !; + type Error = std::convert::Infallible; - fn from_request(request: &'a Request<'r>) -> request::Outcome { + fn from_request(request: &'a Request<'r>) -> request::Outcome { request.cookies() .get_private("user_id") .and_then(|cookie| cookie.value().parse().ok())