Skip to content

Commit 34a741a

Browse files
jhprattSergioBenitez
authored andcommitted
Remove use of '!' type in favor of 'Infallible'.
This removes the use of and dependence on the 'never_type' feature.
1 parent 21b1017 commit 34a741a

File tree

11 files changed

+40
-43
lines changed

11 files changed

+40
-43
lines changed

contrib/lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(crate_visibility_modifier)]
2-
#![feature(never_type)]
32
#![feature(doc_cfg)]
43

54
#![doc(html_root_url = "https://api.rocket.rs/v0.5")]

core/http/src/cookies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ mod key {
7474
/// [private cookie]: Cookies::add_private()
7575
///
7676
/// ```rust
77-
/// # #![feature(proc_macro_hygiene, decl_macro, never_type)]
77+
/// # #![feature(proc_macro_hygiene, decl_macro)]
7878
/// # #[macro_use] extern crate rocket;
7979
/// #
8080
/// use rocket::http::Status;
@@ -85,9 +85,9 @@ mod key {
8585
/// struct User(usize);
8686
///
8787
/// impl FromRequest<'_, '_> for User {
88-
/// type Error = !;
88+
/// type Error = std::convert::Infallible;
8989
///
90-
/// fn from_request(request: &Request<'_>) -> request::Outcome<User, !> {
90+
/// fn from_request(request: &Request<'_>) -> request::Outcome<Self, Self::Error> {
9191
/// request.cookies()
9292
/// .get_private("user_id")
9393
/// .and_then(|cookie| cookie.value().parse().ok())

core/lib/src/data/from_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub trait FromData<'a>: Sized {
388388

389389
/// The identity implementation of `FromData`. Always returns `Success`.
390390
impl<'f> FromData<'f> for Data {
391-
type Error = !;
391+
type Error = std::convert::Infallible;
392392
type Owned = Data;
393393
type Borrowed = Data;
394394

core/lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(specialization)]
22
#![feature(decl_macro)]
33
#![feature(try_trait)]
4-
#![feature(never_type)]
54
#![feature(proc_macro_hygiene)]
65
#![feature(crate_visibility_modifier)]
76
#![feature(label_break_value)]

core/lib/src/request/form/from_form.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,19 @@ pub trait FromForm<'f>: Sized {
111111
}
112112

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

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

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

125125
#[inline]
126-
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Self, !> {
126+
fn from_form(items: &mut FormItems<'f>, strict: bool) -> Result<Self, Self::Error> {
127127
Ok(T::from_form(items, strict))
128128
}
129129
}

core/lib/src/request/form/from_form_value.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub trait FromFormValue<'v>: Sized {
191191
}
192192

193193
impl<'v> FromFormValue<'v> for &'v RawStr {
194-
type Error = !;
194+
type Error = std::convert::Infallible;
195195

196196
// This just gives the raw string.
197197
#[inline(always)]
@@ -248,7 +248,7 @@ impl_with_fromstr!(
248248
);
249249

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

253253
#[inline(always)]
254254
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> {
266266

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

271271
#[inline(always)]
272272
fn from_form_value(v: &'v RawStr) -> Result<Self, Self::Error> {

core/lib/src/request/from_request.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
284284
///
285285
/// ```rust
286286
/// # #![feature(proc_macro_hygiene, decl_macro)]
287-
/// # #![feature(never_type)]
288287
/// # #[macro_use] extern crate rocket;
289288
/// # #[cfg(feature = "private-cookies")] mod inner {
290289
/// # use rocket::outcome::{IntoOutcome, Outcome};
@@ -306,9 +305,9 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
306305
/// # struct Admin<'a> { user: &'a User }
307306
/// #
308307
/// impl<'a> FromRequest<'a, '_> for &'a User {
309-
/// type Error = !;
308+
/// type Error = std::convert::Infallible;
310309
///
311-
/// fn from_request(request: &'a Request<'_>) -> request::Outcome<&'a User, !> {
310+
/// fn from_request(request: &'a Request<'_>) -> request::Outcome<Self, Self::Error> {
312311
/// // This closure will execute at most once per request, regardless of
313312
/// // the number of times the `User` guard is executed.
314313
/// let user_result = request.local_cache(|| {
@@ -324,9 +323,9 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
324323
/// }
325324
///
326325
/// impl<'a> FromRequest<'a, '_> for Admin<'a> {
327-
/// type Error = !;
326+
/// type Error = std::convert::Infallible;
328327
///
329-
/// fn from_request(request: &'a Request<'_>) -> request::Outcome<Admin<'a>, !> {
328+
/// fn from_request(request: &'a Request<'_>) -> request::Outcome<Self, Self::Error> {
330329
/// let user = request.guard::<&User>()?;
331330
///
332331
/// if user.is_admin {
@@ -358,23 +357,23 @@ pub trait FromRequest<'a, 'r>: Sized {
358357
}
359358

360359
impl FromRequest<'_, '_> for Method {
361-
type Error = !;
360+
type Error = std::convert::Infallible;
362361

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

368367
impl<'a> FromRequest<'a, '_> for &'a Origin<'a> {
369-
type Error = !;
368+
type Error = std::convert::Infallible;
370369

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

376375
impl<'r> FromRequest<'_, 'r> for &'r Route {
377-
type Error = !;
376+
type Error = std::convert::Infallible;
378377

379378
fn from_request(request: &Request<'r>) -> Outcome<Self, Self::Error> {
380379
match request.route() {
@@ -385,15 +384,15 @@ impl<'r> FromRequest<'_, 'r> for &'r Route {
385384
}
386385

387386
impl<'a> FromRequest<'a, '_> for Cookies<'a> {
388-
type Error = !;
387+
type Error = std::convert::Infallible;
389388

390389
fn from_request(request: &'a Request<'_>) -> Outcome<Self, Self::Error> {
391390
Success(request.cookies())
392391
}
393392
}
394393

395394
impl<'a> FromRequest<'a, '_> for &'a Accept {
396-
type Error = !;
395+
type Error = std::convert::Infallible;
397396

398397
fn from_request(request: &'a Request<'_>) -> Outcome<Self, Self::Error> {
399398
match request.accept() {
@@ -404,7 +403,7 @@ impl<'a> FromRequest<'a, '_> for &'a Accept {
404403
}
405404

406405
impl<'a> FromRequest<'a, '_> for &'a ContentType {
407-
type Error = !;
406+
type Error = std::convert::Infallible;
408407

409408
fn from_request(request: &'a Request<'_>) -> Outcome<Self, Self::Error> {
410409
match request.content_type() {
@@ -415,7 +414,7 @@ impl<'a> FromRequest<'a, '_> for &'a ContentType {
415414
}
416415

417416
impl FromRequest<'_, '_> for SocketAddr {
418-
type Error = !;
417+
type Error = std::convert::Infallible;
419418

420419
fn from_request(request: &Request<'_>) -> Outcome<Self, Self::Error> {
421420
match request.remote() {
@@ -426,7 +425,7 @@ impl FromRequest<'_, '_> for SocketAddr {
426425
}
427426

428427
impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Result<T, T::Error> {
429-
type Error = !;
428+
type Error = std::convert::Infallible;
430429

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

440439
impl<'a, 'r, T: FromRequest<'a, 'r>> FromRequest<'a, 'r> for Option<T> {
441-
type Error = !;
440+
type Error = std::convert::Infallible;
442441

443442
fn from_request(request: &'a Request<'r>) -> Outcome<Self, Self::Error> {
444443
match T::from_request(request) {

core/lib/src/request/param.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub trait FromParam<'a>: Sized {
205205
}
206206

207207
impl<'a> FromParam<'a> for &'a RawStr {
208-
type Error = !;
208+
type Error = std::convert::Infallible;
209209

210210
#[inline(always)]
211211
fn from_param(param: &'a RawStr) -> Result<&'a RawStr, Self::Error> {
@@ -258,7 +258,7 @@ impl_with_fromstr! {
258258
}
259259

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

263263
#[inline]
264264
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> {
270270
}
271271

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

275275
#[inline]
276276
fn from_param(param: &'a RawStr) -> Result<Self, Self::Error> {
@@ -309,7 +309,7 @@ pub trait FromSegments<'a>: Sized {
309309
}
310310

311311
impl<'a> FromSegments<'a> for Segments<'a> {
312-
type Error = !;
312+
type Error = std::convert::Infallible;
313313

314314
#[inline(always)]
315315
fn from_segments(segments: Segments<'a>) -> Result<Segments<'a>, Self::Error> {
@@ -342,10 +342,10 @@ impl FromSegments<'_> for PathBuf {
342342
}
343343

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

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

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

359359
#[inline]
360-
fn from_segments(segments: Segments<'a>) -> Result<Option<T>, !> {
360+
fn from_segments(segments: Segments<'a>) -> Result<Option<T>, Self::Error> {
361361
match T::from_segments(segments) {
362362
Ok(val) => Ok(Some(val)),
363363
Err(_) => Ok(None)

core/lib/src/request/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'q, T: FromForm<'q>> FromQuery<'q> for LenientForm<T> {
219219
}
220220

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

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

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

233233
#[inline]
234234
fn from_query(q: Query<'q>) -> Result<Self, Self::Error> {

examples/request_guard/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(proc_macro_hygiene, decl_macro, never_type)]
1+
#![feature(proc_macro_hygiene, decl_macro)]
22

33
#[macro_use] extern crate rocket;
44

@@ -9,9 +9,9 @@ use rocket::outcome::Outcome::*;
99
struct HeaderCount(usize);
1010

1111
impl<'a, 'r> FromRequest<'a, 'r> for HeaderCount {
12-
type Error = !;
12+
type Error = std::convert::Infallible;
1313

14-
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, !> {
14+
fn from_request(request: &'a Request<'r>) -> request::Outcome<Self, Self::Error> {
1515
Success(HeaderCount(request.headers().len()))
1616
}
1717
}

0 commit comments

Comments
 (0)