about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-09-01 02:53:28 -0700
committerGitHub <noreply@github.com>2016-09-01 02:53:28 -0700
commitb2799a56a1631ee351e4687ee649808e28cccda1 (patch)
treeee8fd765766cc38f38e8dd02782412c1d2ee189d /src/libstd
parent3135b7877a66e72ac4833588eb8654aa155876e8 (diff)
parentf040208d533e1d6d9ee0e0408ee74e26e14d1284 (diff)
downloadrust-b2799a56a1631ee351e4687ee649808e28cccda1.tar.gz
rust-b2799a56a1631ee351e4687ee649808e28cccda1.zip
Auto merge of #35755 - SimonSapin:char_convert, r=alexcrichton
Implement std::convert traits for char

This is motivated by avoiding the `as` operator, which sometimes silently truncates, and instead use conversions that are explicitly lossless and infallible.

I’m less certain that `From<u8> for char` should be implemented: while it matches an existing behavior of `as`, it’s not necessarily the right thing to use for non-ASCII bytes. It effectively decodes bytes as ISO/IEC 8859-1 (since Unicode designed its first 256 code points to be compatible with that encoding), but that is not apparent in the API name.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/error.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs
index ab537f39bf9..16290620010 100644
--- a/src/libstd/error.rs
+++ b/src/libstd/error.rs
@@ -302,6 +302,13 @@ impl<'a, T: ?Sized + Reflect> Error for cell::BorrowMutError<'a, T> {
     }
 }
 
+#[unstable(feature = "try_from", issue = "33417")]
+impl Error for char::CharTryFromError {
+    fn description(&self) -> &str {
+        "converted integer out of range for `char`"
+    }
+}
+
 // copied from any.rs
 impl Error + 'static {
     /// Returns true if the boxed type is the same as `T`