]> git.lizzy.rs Git - rust.git/commitdiff
Add partialeq implementation for TryFromIntError type
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 18 Aug 2018 21:24:25 +0000 (23:24 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 28 Aug 2018 18:40:14 +0000 (20:40 +0200)
src/libcore/num/mod.rs
src/test/run-pass/try-from-int-error-partial-eq.rs [new file with mode: 0644]

index eb63966354b8644f86a8dcc373403b0d566d7d87..cfcdbc5a76a9d216ff88cb6bb9e8c6f73e868a97 100644 (file)
@@ -4248,7 +4248,7 @@ fn from_str(src: &str) -> Result<Self, ParseIntError> {
 
 /// The error type returned when a checked integral type conversion fails.
 #[unstable(feature = "try_from", issue = "33417")]
-#[derive(Debug, Copy, Clone)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
 pub struct TryFromIntError(());
 
 impl TryFromIntError {
diff --git a/src/test/run-pass/try-from-int-error-partial-eq.rs b/src/test/run-pass/try-from-int-error-partial-eq.rs
new file mode 100644 (file)
index 0000000..1122f5a
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(try_from)]
+#![allow(unused_must_use)]
+
+use std::convert::TryFrom;
+use std::num::TryFromIntError;
+
+fn main() {
+    let x: u32 = 125;
+    let y: Result<u8, TryFromIntError> = u8::try_from(x);
+    y == Ok(125);
+}