Skip to content

Commit

Permalink
Remove use of '!' type in favor of 'Infallible'.
Browse files Browse the repository at this point in the history
This removes the use of and dependence on the 'never_type' feature.
  • Loading branch information
jhpratt authored and SergioBenitez committed Jul 9, 2019
1 parent 21b1017 commit 34a741a
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 43 deletions.
1 change: 0 additions & 1 deletion contrib/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(crate_visibility_modifier)]
#![feature(never_type)]
#![feature(doc_cfg)]

#![doc(html_root_url = "https://api.rocket.rs/v0.5")]
Expand Down
6 changes: 3 additions & 3 deletions core/http/src/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<User, !> {
/// fn from_request(request: &Request<'_>) -> request::Outcome<Self, Self::Error> {
/// request.cookies()
/// .get_private("user_id")
/// .and_then(|cookie| cookie.value().parse().ok())
Expand Down
2 changes: 1 addition & 1 deletion core/lib/src/data/from_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion core/lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
8 changes: 4 additions & 4 deletions core/lib/src/request/form/from_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ pub trait FromForm<'f>: Sized {
}

impl<'f, T: FromForm<'f>> FromForm<'f> for Option<T> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Option<T>, !> {
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Option<T>, Self::Error> {
Ok(T::from_form(items, strict).ok())
}
}

impl<'f, T: FromForm<'f>> FromForm<'f> for Result<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Self, !> {
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Self, Self::Error> {
Ok(T::from_form(items, strict))
}
}
6 changes: 3 additions & 3 deletions core/lib/src/request/form/from_form_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -248,7 +248,7 @@ impl_with_fromstr!(
);

impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Option<T> {
type Error = !;
type Error = std::convert::Infallible;

#[inline(always)]
fn from_form_value(v: &'v RawStr) -> Result<Self, Self::Error> {
Expand All @@ -266,7 +266,7 @@ impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Option<T> {

// // TODO: Add more useful implementations (range, regex, etc.).
impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Result<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;

#[inline(always)]
fn from_form_value(v: &'v RawStr) -> Result<Self, Self::Error> {
Expand Down
27 changes: 13 additions & 14 deletions core/lib/src/request/from_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
///
/// ```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};
Expand All @@ -306,9 +305,9 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// # 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<Self, Self::Error> {
/// // 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(|| {
Expand All @@ -324,9 +323,9 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
/// }
///
/// impl<'a> FromRequest<'a, '_> for Admin<'a> {
/// type Error = !;
/// type Error = std::convert::Infallible;
///
/// fn from_request(request: &'a Request<'_>) -> request::Outcome<Admin<'a>, !> {
/// fn from_request(request: &'a Request<'_>) -> request::Outcome<Self, Self::Error> {
/// let user = request.guard::<&User>()?;
///
/// if user.is_admin {
Expand Down Expand Up @@ -358,23 +357,23 @@ pub trait FromRequest<'a, 'r>: Sized {
}

impl FromRequest<'_, '_> for Method {
type Error = !;
type Error = std::convert::Infallible;

fn from_request(request: &Request<'_>) -> Outcome<Self, Self::Error> {
Success(request.method())
}
}

impl<'a> FromRequest<'a, '_> for &'a Origin<'a> {
type Error = !;
type Error = std::convert::Infallible;

fn from_request(request: &'a Request<'_>) -> Outcome<Self, Self::Error> {
Success(request.uri())
}
}

impl<'r> FromRequest<'_, 'r> for &'r Route {
type Error = !;
type Error = std::convert::Infallible;

fn from_request(request: &Request<'r>) -> Outcome<Self, Self::Error> {
match request.route() {
Expand All @@ -385,15 +384,15 @@ 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<Self, Self::Error> {
Success(request.cookies())
}
}

impl<'a> FromRequest<'a, '_> for &'a Accept {
type Error = !;
type Error = std::convert::Infallible;

fn from_request(request: &'a Request<'_>) -> Outcome<Self, Self::Error> {
match request.accept() {
Expand All @@ -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<Self, Self::Error> {
match request.content_type() {
Expand All @@ -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<Self, Self::Error> {
match request.remote() {
Expand All @@ -426,7 +425,7 @@ impl FromRequest<'_, '_> for SocketAddr {
}

impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Result<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;

fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
match T::from_request(request) {
Expand All @@ -438,7 +437,7 @@ impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Result<T, T::Error>
}

impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Option<T> {
type Error = !;
type Error = std::convert::Infallible;

fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
match T::from_request(request) {
Expand Down
16 changes: 8 additions & 8 deletions core/lib/src/request/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -258,7 +258,7 @@ impl_with_fromstr! {
}

impl<'a, T: FromParam<'a>> FromParam<'a> for Result<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_param(param: &'a RawStr) -> Result<Self, Self::Error> {
Expand All @@ -270,7 +270,7 @@ impl<'a, T: FromParam<'a>> FromParam<'a> for Result<T, T::Error> {
}

impl<'a, T: FromParam<'a>> FromParam<'a> for Option<T> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_param(param: &'a RawStr) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -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<Segments<'a>, Self::Error> {
Expand Down Expand Up @@ -342,10 +342,10 @@ impl FromSegments<'_> for PathBuf {
}

impl<'a, T: FromSegments<'a>> FromSegments<'a> for Result<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_segments(segments: Segments<'a>) -> Result<Result<T, T::Error>, !> {
fn from_segments(segments: Segments<'a>) -> Result<Result<T, T::Error>, Self::Error> {
match T::from_segments(segments) {
Ok(val) => Ok(Ok(val)),
Err(e) => Ok(Err(e)),
Expand All @@ -354,10 +354,10 @@ impl<'a, T: FromSegments<'a>> FromSegments<'a> for Result<T, T::Error> {
}

impl<'a, T: FromSegments<'a>> FromSegments<'a> for Option<T> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_segments(segments: Segments<'a>) -> Result<Option<T>, !> {
fn from_segments(segments: Segments<'a>) -> Result<Option<T>, Self::Error> {
match T::from_segments(segments) {
Ok(val) => Ok(Some(val)),
Err(_) => Ok(None)
Expand Down
4 changes: 2 additions & 2 deletions core/lib/src/request/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<'q, T: FromForm<'q>> FromQuery<'q> for LenientForm<T> {
}

impl<'q, T: FromQuery<'q>> FromQuery<'q> for Option<T> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_query(q: Query<'q>) -> Result<Self, Self::Error> {
Expand All @@ -228,7 +228,7 @@ impl<'q, T: FromQuery<'q>> FromQuery<'q> for Option<T> {
}

impl<'q, T: FromQuery<'q>> FromQuery<'q> for Result<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;

#[inline]
fn from_query(q: Query<'q>) -> Result<Self, Self::Error> {
Expand Down
6 changes: 3 additions & 3 deletions examples/request_guard/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(proc_macro_hygiene, decl_macro, never_type)]
#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;

Expand All @@ -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<Self, !> {
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
Success(HeaderCount(request.headers().len()))
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/session/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(proc_macro_hygiene, decl_macro, never_type)]
#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] extern crate rocket;

Expand All @@ -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<User, !> {
fn from_request(request: &'a Request<'r>) -> request::Outcome<User, Self::Error> {
request.cookies()
.get_private("user_id")
.and_then(|cookie| cookie.value().parse().ok())
Expand Down

0 comments on commit 34a741a

Please sign in to comment.