1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
13 #![deny(clippy::fallible_impl_from)]
17 impl From<String> for Foo {
18 fn from(s: String) -> Self {
19 Foo(s.parse().unwrap())
24 struct Valid(Vec<u8>);
26 impl<'a> From<&'a str> for Valid {
27 fn from(s: &'a str) -> Valid {
28 Valid(s.to_owned().into_bytes())
31 impl From<usize> for Valid {
32 fn from(i: usize) -> Valid {
33 Valid(Vec::with_capacity(i))
40 impl From<usize> for Invalid {
41 fn from(i: usize) -> Invalid {
49 impl From<Option<String>> for Invalid {
50 fn from(s: Option<String>) -> Invalid {
54 } else if s.parse::<u32>().unwrap() != 42 {
64 impl<T> ProjStrTrait for Box<T> {
65 type ProjString = String;
67 impl<'a> From<&'a mut <Box<u32> as ProjStrTrait>::ProjString> for Invalid {
68 fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
69 if s.parse::<u32>().ok().unwrap() != 42 {
78 impl From<String> for Unreachable {
79 fn from(s: String) -> Unreachable {
83 match s.chars().next() {
84 Some(_) => Unreachable,
85 None => unreachable!(), // do not lint the unreachable macro