Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unreachable_code)]
- fn main() {
- println!("{:?}", {
- use std::convert::{TryFrom, TryInto}; struct NewType<'a, T>(&'a Vec<T>); impl<'a, T> TryFrom<&'a Vec<T>> for NewType<'a, T> { type Error = (); fn try_from(vec: &'a Vec<T>) -> Result<NewType<'a, T>, ()> { Ok(NewType(vec)) } } fn check<T: TryInto<NewType<'_, T>>>(_: T) {} let vec: Vec<i32> = Vec::new(); check(&vec)
- });
- }
- /* ~~~~=== stderr ===~~~~
- Compiling playground v0.0.1 (/playground)
- error[E0637]: `'_` cannot be used here
- --> src/main.rs:6:262
- |
- 6 | use std::convert::{TryFrom, TryInto}; struct NewType<'a, T>(&'a Vec<T>); impl<'a, T> TryFrom<&'a Vec<T>> for NewType<'a, T> { type Error = (); fn try_from(vec: &'a Vec<T>) -> Result<NewType<'a, T>, ()> { Ok(NewType(vec)) } } fn check<T: TryInto<NewType<'_, T>>>(_: T) {} let vec: Vec<i32> = Vec::new(); check(&vec)
- | ^^ `'_` is a reserved lifetime name
- error[E0310]: the parameter type `T` may not live long enough
- --> src/main.rs:6:234
- |
- 6 | use std::convert::{TryFrom, TryInto}; struct NewType<'a, T>(&'a Vec<T>); impl<'a, T> TryFrom<&'a Vec<T>> for NewType<'a, T> { type Error = (); fn try_from(vec: &'a Vec<T>) -> Result<NewType<'a, T>, ()> { Ok(NewType(vec)) } } fn check<T: TryInto<NewType<'_, T>>>(_: T) {} let vec: Vec<i32> = Vec::new(); check(&vec)
- | ^^^^^^^^^--^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- | |
- | help: consider adding an explicit lifetime bound `T: 'static`...
- |
- note: ...so that the type `T` will meet its required lifetime bounds
- --> src/main.rs:6:234
- |
- 6 | use std::convert::{TryFrom, TryInto}; struct NewType<'a, T>(&'a Vec<T>); impl<'a, T> TryFrom<&'a Vec<T>> for NewType<'a, T> { type Error = (); fn try_from(vec: &'a Vec<T>) -> Result<NewType<'a, T>, ()> { Ok(NewType(vec)) } } fn check<T: TryInto<NewType<'_, T>>>(_: T) {} let vec: Vec<i32> = Vec::new(); check(&vec)
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- error: aborting due to 2 previous errors
- Some errors occurred: E0310, E0637.
- For more information about an error, try `rustc --explain E0310`.
- error: Could not compile `playground`.
- To learn more, run the command again with --verbose.
- */
- /* ~~~~=== stdout ===~~~~
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement