Auto merge of #58302 - SimonSapin:tryfrom, r=alexcrichton
Stabilize TryFrom and TryInto with a convert::Infallible empty enum This is the plan proposed in https://github.com/rust-lang/rust/issues/33417#issuecomment-423073898
This commit is contained in:
commit
00aae71f50
16 changed files with 163 additions and 79 deletions
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(try_from)]
|
||||
#![allow(unused_must_use)]
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
// This test was added to show the motivation for doing this
|
||||
// over `TryFrom` being blanket impl for all `T: From`
|
||||
|
||||
#![feature(try_from, never_type)]
|
||||
#![feature(never_type)]
|
||||
|
||||
use std::convert::TryInto;
|
||||
use std::convert::{TryInto, Infallible};
|
||||
|
||||
struct Foo<T> {
|
||||
t: T,
|
||||
|
|
@ -32,6 +32,6 @@ impl<T> Into<Vec<T>> for Foo<T> {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let _: Result<Vec<i32>, !> = Foo { t: 10 }.try_into();
|
||||
let _: Result<Vec<i32>, Infallible> = Foo { t: 10 }.try_into();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#![feature(try_from)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::convert::{TryFrom, AsRef};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0119]: conflicting implementations of trait `std::convert::AsRef<Q>` for type `std::boxed::Box<Q>`:
|
||||
--> $DIR/conflict-with-std.rs:7:1
|
||||
--> $DIR/conflict-with-std.rs:6:1
|
||||
|
|
||||
LL | impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -9,7 +9,7 @@ LL | impl AsRef<Q> for Box<Q> { //~ ERROR conflicting implementations
|
|||
where T: ?Sized;
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S`:
|
||||
--> $DIR/conflict-with-std.rs:14:1
|
||||
--> $DIR/conflict-with-std.rs:13:1
|
||||
|
|
||||
LL | impl From<S> for S { //~ ERROR conflicting implementations
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
@ -18,7 +18,7 @@ LL | impl From<S> for S { //~ ERROR conflicting implementations
|
|||
- impl<T> std::convert::From<T> for T;
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::convert::TryFrom<X>` for type `X`:
|
||||
--> $DIR/conflict-with-std.rs:21:1
|
||||
--> $DIR/conflict-with-std.rs:20:1
|
||||
|
|
||||
LL | impl TryFrom<X> for X { //~ ERROR conflicting implementations
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue