Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See ([try_trait_v2](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html)) fo
## Requires

- nightly
- `#![feature(never_type)]`
- `#![feature(never_type)]` (stable from rust 1.100.0)
- `#![feature(try_trait_v2)]`
- `#![feature(try_trait_v2_residual)]`
- optionally: `#![feature(iterator_try_collect)]` (if using Try_Iterator)
Expand All @@ -30,6 +30,7 @@ See the [full documentation](https://docs.rs/try_v2/latest/try_v2/) for specific
## Example Usage

```rust
#![allow(stable_features)]
#![feature(never_type)]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
Expand Down Expand Up @@ -79,7 +80,7 @@ In order to use this crate you must enable the features which it exposes:

> 🔬 **Required Experimental Features**
>
> - [`#![feature(never_type)]`](https://github.com/rust-lang/rust/issues/35121)
> - [`#![feature(never_type)]`](https://github.com/rust-lang/rust/issues/35121) (stable from rust 1.100.0)
> - [`#![feature(try_trait_v2)]`](https://github.com/rust-lang/rust/issues/84277)
> - [`#![feature(try_trait_v2_residual)]`](https://github.com/rust-lang/rust/issues/91285)
> - optionally: [`#![feature(iterator_try_collect)]`](https://github.com/rust-lang/rust/issues/94047) (if using `Try_Iterator`)
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/BangMatching.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![allow(dead_code)]

enum ValidatedBox<T> {
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/Nested_Try.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
#![allow(dead_code, clippy::disallowed_names)]
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/TraitExt_Try.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
#![allow(clippy::disallowed_names)]
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/TryFrom2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
#![feature(associated_type_defaults)]
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/clear_ready.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![allow(unused, clippy::disallowed_names)]
use std::{
io,
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/doubleQ.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
#![feature(min_specialization)]
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2/examples/nested_residual.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
#![allow(dead_code, clippy::disallowed_names)]
Expand Down
6 changes: 3 additions & 3 deletions crates/try_v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! ## Requires
//!
//! - nightly
//! - `#![feature(never_type)]`
//! - `#![feature(never_type)]` (stable from rust 1.100.0)
//! - `#![feature(try_trait_v2)]`
//! - `#![feature(try_trait_v2_residual)]`
//!
Expand All @@ -28,7 +28,7 @@
//! ## Example Usage
//!
//! ```rust, ignore TODO update
//! #![feature(never_type)]
//! #![cfg_attr(unstable_never_type, feature(never_type))]
//! #![feature(try_trait_v2)]
//! #![feature(try_trait_v2_residual)]
//! use try_v2::Try;
Expand Down Expand Up @@ -77,7 +77,7 @@
//!
//! > 🔬 **Required Experimental Features**
//! >
//! > - [`#![feature(never_type)]`](https://github.com/rust-lang/rust/issues/35121)
//! > - [`#![cfg_attr(unstable_never_type, feature(never_type))]`](https://github.com/rust-lang/rust/issues/35121)
//! > - [`#![feature(try_trait_v2)]`](https://github.com/rust-lang/rust/issues/84277)
//! > - [`#![feature(try_trait_v2_residual)]`](https://github.com/rust-lang/rust/issues/91285)
//!
Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/FromResidualMulti.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/FromResidualNested.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/FromResidualNestedInfer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/FromResidualNestedMulti.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/Iterator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused)]
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/ReferenceMethods.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(unused)]
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/basic_usage.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/pass_GenericE.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/pass_MultipleFields.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/pass_MultipleGenerics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/pass_NoFieldResiduals.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/pass_NoUnitResidual.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
2 changes: 1 addition & 1 deletion crates/try_v2_derive/examples/pass_ResultMeBang.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(never_type)]
#![cfg_attr(unstable_never_type, feature(never_type))]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]

Expand Down
12 changes: 6 additions & 6 deletions crates/try_v2_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use parse::TryEnum;
///
/// ## Derived code
/// ```
/// # #![feature(never_type)]
/// # #![cfg_attr(unstable_never_type, feature(never_type))]
/// # #![feature(try_trait_v2)]
/// # #![feature(try_trait_v2_residual)]
/// # use try_v2_derive::Try;
Expand Down Expand Up @@ -101,7 +101,7 @@ use parse::TryEnum;
/// 2. provide relevant `From` implementations (see examples)
///
/// ```
/// # #![feature(never_type)]
/// # #![cfg_attr(unstable_never_type, feature(never_type))]
/// # #![feature(try_trait_v2)]
/// # #![feature(try_trait_v2_residual)]
/// # use try_v2_derive::Try;
Expand Down Expand Up @@ -136,7 +136,7 @@ use parse::TryEnum;
///
/// ### Residual
/// The `Residual` is generated by replacing the _first generic type_ with `!`. This means
/// - we rely on the unstable `#![feature(never_type)]` (on the assumption that it will be
/// - we rely on the unstable `#![cfg_attr(unstable_never_type, feature(never_type))]` (on the assumption that it will be
/// stabilised on a similar timeframe to `#![feature(try_trait_v2)]`
/// - any short-circuiting variants which also store this type will have a "hole"
/// - the **invariant** _first generic type is stored by first variant_ is **strictly** enforced.
Expand All @@ -157,7 +157,7 @@ use parse::TryEnum;
/// this valuable.
///
/// ```
/// # #![feature(never_type)]
/// # #![cfg_attr(unstable_never_type, feature(never_type))]
/// # #![feature(try_trait_v2)]
/// # #![feature(try_trait_v2_residual)]
/// # use try_v2_derive::Try;
Expand Down Expand Up @@ -463,7 +463,7 @@ fn derive_try_trait_v2(input: TokenStream2) -> DiagnosticStream {
/// ## Example
///
/// ```
/// # #![feature(never_type)]
/// # #![cfg_attr(unstable_never_type, feature(never_type))]
/// # #![feature(try_trait_v2)]
/// # #![feature(try_trait_v2_residual)]
///
Expand Down Expand Up @@ -571,7 +571,7 @@ fn derive_from_residual(input: TokenStream2) -> DiagnosticStream {
/// ## Example
///
/// ```
/// # #![feature(never_type)]
/// # #![cfg_attr(unstable_never_type, feature(never_type))]
/// # #![feature(try_trait_v2)]
/// # #![feature(try_trait_v2_residual)]
/// # use try_v2_derive::{IntoIterator, Try};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(stable_features)]
#![feature(never_type)]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
error: Try requires the first generic type to be used as the `Output` type
--> tests/compilation/fail_FirstGenericNotOutput.rs:7:17
--> tests/compilation/fail_FirstGenericNotOutput.rs:8:17
|
7 | #[derive(Debug, Try)]
8 | #[derive(Debug, Try)]
| ^^^
|
help: Output type defined here
--> tests/compilation/fail_FirstGenericNotOutput.rs:9:12
--> tests/compilation/fail_FirstGenericNotOutput.rs:10:12
|
9 | enum Owned<T, E> {
10 | enum Owned<T, E> {
| ^
help: change this to T
--> tests/compilation/fail_FirstGenericNotOutput.rs:10:8
--> tests/compilation/fail_FirstGenericNotOutput.rs:11:8
|
10 | Ok(E),
11 | Ok(E),
| ^
= note: this error originates in the derive macro `Try` (in Nightly builds, run with -Z macro-backtrace for more info)

error: Try requires the first generic type to be used as the `Output` type
--> tests/compilation/fail_FirstGenericNotOutput.rs:14:17
--> tests/compilation/fail_FirstGenericNotOutput.rs:15:17
|
14 | #[derive(Debug, Try)]
15 | #[derive(Debug, Try)]
| ^^^
|
help: Output type defined here
--> tests/compilation/fail_FirstGenericNotOutput.rs:17:23
--> tests/compilation/fail_FirstGenericNotOutput.rs:18:23
|
17 | enum Borrowed<'t, 'e, T, E> {
18 | enum Borrowed<'t, 'e, T, E> {
| ^
help: change this to &'e T
--> tests/compilation/fail_FirstGenericNotOutput.rs:18:8
--> tests/compilation/fail_FirstGenericNotOutput.rs:19:8
|
18 | Ok(&'e E),
19 | Ok(&'e E),
| ^^^^^
= note: this error originates in the derive macro `Try` (in Nightly builds, run with -Z macro-backtrace for more info)

error: Try requires a single generic type for `Output`
--> tests/compilation/fail_FirstGenericNotOutput.rs:22:17
--> tests/compilation/fail_FirstGenericNotOutput.rs:23:17
|
22 | #[derive(Debug, Try)]
23 | #[derive(Debug, Try)]
| ^^^
|
help: Output type defined here
--> tests/compilation/fail_FirstGenericNotOutput.rs:25:35
--> tests/compilation/fail_FirstGenericNotOutput.rs:26:35
|
25 | enum MultipleBorrowed<'t, 'e, 'f, T, E, F> {
26 | enum MultipleBorrowed<'t, 'e, 'f, T, E, F> {
| ^
help: change this to (T)
--> tests/compilation/fail_FirstGenericNotOutput.rs:26:7
--> tests/compilation/fail_FirstGenericNotOutput.rs:27:7
|
26 | Ok(&'e E, &'f F),
27 | Ok(&'e E, &'f F),
| ^^^^^^^^^^^^^^
= note: this error originates in the derive macro `Try` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 1 addition & 0 deletions crates/try_v2_derive/tests/compilation/fail_MustUse.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(stable_features)]
#![feature(never_type)]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
Expand Down
20 changes: 10 additions & 10 deletions crates/try_v2_derive/tests/compilation/fail_MustUse.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
warning: it is recommended to annotate try-types as `#[must_use]`
--> tests/compilation/fail_MustUse.rs:8:1
--> tests/compilation/fail_MustUse.rs:9:1
|
8 | / enum ExitE<E> {
9 | | Ok(E),
10 | | TestsFailed,
11 | | OtherError(String),
12 | | }
9 | / enum ExitE<E> {
10 | | Ok(E),
11 | | TestsFailed,
12 | | OtherError(String),
13 | | }
| |_^
|
note: this warning originates from the macro invocation here
--> tests/compilation/fail_MustUse.rs:7:17
--> tests/compilation/fail_MustUse.rs:8:17
|
7 | #[derive(Debug, Try)]
8 | #[derive(Debug, Try)]
| ^^^
= note: this warning originates in the derive macro `Try` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `fail` in this scope
--> tests/compilation/fail_MustUse.rs:15:5
--> tests/compilation/fail_MustUse.rs:16:5
|
15 | fail
16 | fail
| ^^^^ not found in this scope
1 change: 1 addition & 0 deletions crates/try_v2_derive/tests/compilation/fail_NoGenerics.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(stable_features)]
#![feature(never_type)]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
Expand Down
20 changes: 10 additions & 10 deletions crates/try_v2_derive/tests/compilation/fail_NoGenerics.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error: Try requires a generic type for `Output`
--> tests/compilation/fail_NoGenerics.rs:7:17
|
7 | #[derive(Debug, Try)]
| ^^^
|
--> tests/compilation/fail_NoGenerics.rs:8:17
|
8 | #[derive(Debug, Try)]
| ^^^
|
help: Add <T> after this...
--> tests/compilation/fail_NoGenerics.rs:9:6
|
9 | enum NoGenerics {
| ^^^^^^^^^^
= note: this error originates in the derive macro `Try` (in Nightly builds, run with -Z macro-backtrace for more info)
--> tests/compilation/fail_NoGenerics.rs:10:6
|
10 | enum NoGenerics {
| ^^^^^^^^^^
= note: this error originates in the derive macro `Try` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(stable_features)]
#![feature(never_type)]
#![feature(try_trait_v2)]
#![feature(try_trait_v2_residual)]
Expand Down
Loading