Add Display and Error impls for proc_macro::LexError

This should allow LexError to play much nicer with the `?` operator.
This commit is contained in:
Kinsey Favre 2020-02-06 12:25:18 -06:00
parent 303d8aff60
commit c0c526951c
No known key found for this signature in database
GPG Key ID: F42A38FAF496F4BE

View File

@ -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_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")]