about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-12 16:32:07 +0100
committerGitHub <noreply@github.com>2020-03-12 16:32:07 +0100
commit703dcff081aa9f4aef2e94fb25d6743692c2dd47 (patch)
tree6bec5dae491e81e4ff4361a62459f48ce3c648c4
parent23de8275c9b5e5812dc54a12bdba6d80870d9dc8 (diff)
parent5099ab6e6b80c02f2b16e99c169d318cfd9252c1 (diff)
downloadrust-703dcff081aa9f4aef2e94fb25d6743692c2dd47.tar.gz
rust-703dcff081aa9f4aef2e94fb25d6743692c2dd47.zip
Rollup merge of #68899 - kinseytamsin:lexerror-error-impl, r=Centril
Add Display and Error impls for proc_macro::LexError

This should allow LexError to play much nicer with the `?` operator.

Fixes #68896.

(I'm not sure if I did the stability attributes right, so if I need to change them, please let me know!)
-rw-r--r--src/libproc_macro/lib.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs
index c51db695a5b..59ce14c97c0 100644
--- a/src/libproc_macro/lib.rs
+++ b/src/libproc_macro/lib.rs
@@ -41,7 +41,7 @@ pub use diagnostic::{Diagnostic, Level, MultiSpan};
 use std::ops::{Bound, RangeBounds};
 use std::path::PathBuf;
 use std::str::FromStr;
-use std::{fmt, iter, mem};
+use std::{error, fmt, iter, mem};
 
 /// The main type provided by this crate, representing an abstract stream of
 /// tokens, or, more specifically, a sequence of token trees.
@@ -66,6 +66,16 @@ pub struct LexError {
     _inner: (),
 }
 
+#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")]
+impl fmt::Display for LexError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.write_str("cannot parse string into token stream")
+    }
+}
+
+#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.0")]
+impl error::Error for LexError {}
+
 #[stable(feature = "proc_macro_lib", since = "1.15.0")]
 impl !Send for LexError {}
 #[stable(feature = "proc_macro_lib", since = "1.15.0")]