Remove use of '!' type in favor of 'Infallible'.

This removes the use of and dependence on the 'never_type' feature.
This commit is contained in:
Jacob Pratt 2019-04-08 23:57:47 -04:00 committed by Sergio Benitez
parent 21b10176ee
commit 34a741a26e
11 changed files with 40 additions and 43 deletions

View File

@ -1,5 +1,4 @@
#![feature(crate_visibility_modifier)]
#![feature(never_type)]
#![feature(doc_cfg)]
#![doc(html_root_url = "https://api.rocket.rs/v0.5")]

View File

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

View File

@ -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;

View File

@ -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)]

View File

@ -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))
}
}

View File

@ -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<T> {
type Error = !;
type Error = std::convert::Infallible;
#[inline(always)]
fn from_form_value(v: &'v RawStr) -> Result<Self, Self::Error> {
@ -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> {

View File

@ -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};
@ -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(|| {
@ -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 {
@ -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<Self, Self::Error> {
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<Self, Self::Error> {
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<Self, Self::Error> {
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<Self, Self::Error> {
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<Self, Self::Error> {
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<Self, Self::Error> {
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<Self, Self::Error> {
match request.remote() {
@ -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) {
@ -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) {

View File

@ -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<T, T::Error> {
type Error = !;
type Error = std::convert::Infallible;
#[inline]
fn from_param(param: &'a RawStr) -> Result<Self, Self::Error> {
@ -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> {
@ -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> {
@ -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)),
@ -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)

View File

@ -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> {
@ -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> {

View File

@ -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<Self, !> {
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
Success(HeaderCount(request.headers().len()))
}
}

View File

@ -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<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())