Skip to content

Commit c0c5269

Browse files
committed
Add Display and Error impls for proc_macro::LexError
This should allow LexError to play much nicer with the `?` operator.
1 parent 303d8af commit c0c5269

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libproc_macro/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub use diagnostic::{Diagnostic, Level, MultiSpan};
4141
use std::ops::{Bound, RangeBounds};
4242
use std::path::PathBuf;
4343
use std::str::FromStr;
44-
use std::{fmt, iter, mem};
44+
use std::{error, fmt, iter, mem};
4545

4646
/// The main type provided by this crate, representing an abstract stream of
4747
/// tokens, or, more specifically, a sequence of token trees.
@@ -66,6 +66,16 @@ pub struct LexError {
6666
_inner: (),
6767
}
6868

69+
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
70+
impl fmt::Display for LexError {
71+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72+
f.write_str("lex error")
73+
}
74+
}
75+
76+
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
77+
impl error::Error for LexError {}
78+
6979
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
7080
impl !Send for LexError {}
7181
#[stable(feature = "proc_macro_lib", since = "1.15.0")]

0 commit comments

Comments
 (0)