Skip to content

Commit 8df5ffa

Browse files
committed
Generalize from_str_checked error type
1 parent c1f996f commit 8df5ffa

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/fallback.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(wrap_proc_macro)]
2+
use crate::imp;
13
#[cfg(span_locations)]
24
use crate::location::LineColumn;
35
use crate::parse::{self, Cursor};
@@ -1221,8 +1223,8 @@ fn escape_utf8(string: &str, repr: &mut String) {
12211223
#[cfg(feature = "proc-macro")]
12221224
pub(crate) trait FromStr2: FromStr<Err = proc_macro::LexError> {
12231225
#[cfg(wrap_proc_macro)]
1224-
fn from_str_checked(src: &str) -> Result<Self, Self::Err> {
1225-
Self::from_str(src)
1226+
fn from_str_checked(src: &str) -> Result<Self, imp::LexError> {
1227+
Self::from_str(src).map_err(imp::LexError::Compiler)
12261228
}
12271229

12281230
fn from_str_unchecked(src: &str) -> Self {

src/wrapper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl TokenStream {
9191
// Catch panic to work around https://github.com/rust-lang/rust/issues/58736.
9292
match panic::catch_unwind(|| proc_macro::TokenStream::from_str_checked(src)) {
9393
Ok(Ok(tokens)) => Ok(TokenStream::Compiler(DeferredTokenStream::new(tokens))),
94-
Ok(Err(lex)) => Err(LexError::Compiler(lex)),
94+
Ok(Err(lex)) => Err(lex),
9595
Err(_panic) => Err(LexError::CompilerPanic),
9696
}
9797
} else {

0 commit comments

Comments
 (0)