]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/fallible_impl_from.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / fallible_impl_from.rs
index eb1cd4c5e9ada59413ed5b4302c0df870d585802..679f4a7dc357d4a182be13c9a292d43ac229ea5c 100644 (file)
@@ -1,4 +1,4 @@
-#![deny(fallible_impl_from)]
+#![deny(clippy::fallible_impl_from)]
 
 // docs example
 struct Foo(i32);
@@ -8,7 +8,6 @@ fn from(s: String) -> Self {
     }
 }
 
-
 struct Valid(Vec<u8>);
 
 impl<'a> From<&'a str> for Valid {
@@ -22,7 +21,6 @@ fn from(i: usize) -> Valid {
     }
 }
 
-
 struct Invalid;
 
 impl From<usize> for Invalid {
@@ -61,4 +59,18 @@ fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
     }
 }
 
+struct Unreachable;
+
+impl From<String> for Unreachable {
+    fn from(s: String) -> Unreachable {
+        if s.is_empty() {
+            return Unreachable;
+        }
+        match s.chars().next() {
+            Some(_) => Unreachable,
+            None => unreachable!(), // do not lint the unreachable macro
+        }
+    }
+}
+
 fn main() {}