Skip to content

Commit 703dcff

Browse files
authored
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!)
2 parents 23de827 + 5099ab6 commit 703dcff

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libproc_macro/lib.rs

+11-1
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_lexerror_impls", since = "1.44.0")]
70+
impl fmt::Display for LexError {
71+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72+
f.write_str("cannot parse string into token stream")
73+
}
74+
}
75+
76+
#[stable(feature = "proc_macro_lexerror_impls", since = "1.44.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)