about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKinsey Favre <kinseytamsin@tutanota.com>2020-02-06 12:25:18 -0600
committerKinsey Favre <kinseytamsin@tutanota.com>2020-03-11 11:28:59 -0500
commitc0c526951c87c79e0db5e6e32b95bbe0a01347d3 (patch)
tree3a520615ff0d3517567df3438a0f64e706c529bb
parent303d8aff6092709edd4dbd35b1c88e9aa40bf6d8 (diff)
downloadrust-c0c526951c87c79e0db5e6e32b95bbe0a01347d3.tar.gz
rust-c0c526951c87c79e0db5e6e32b95bbe0a01347d3.zip
Add Display and Error impls for proc_macro::LexError
This should allow LexError to play much nicer with the `?` operator.
-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..5ae7640d4b8 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.
@@ -67,6 +67,16 @@ pub struct LexError {
 }
 
 #[stable(feature = "proc_macro_lib", since = "1.15.0")]
+impl fmt::Display for LexError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        f.write_str("lex error")
+    }
+}
+
+#[stable(feature = "proc_macro_lib", since = "1.15.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")]
 impl !Sync for LexError {}