Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error location at eof in LitStr::parse #1590

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ impl LitStr {

// Parse string literal into a token stream with every span equal to the
// original literal's span.
let span = self.span();
let mut tokens = TokenStream::from_str(&self.value())?;
tokens = respan_token_stream(tokens, self.span());
tokens = respan_token_stream(tokens, span);

let result = parser.parse2(tokens)?;
let result = crate::parse::parse_scoped(parser, span, tokens)?;

let suffix = self.suffix();
if !suffix.is_empty() {
Expand Down
3 changes: 0 additions & 3 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,6 @@ pub trait Parser: Sized {

// Not public API.
#[doc(hidden)]
#[cfg(any(feature = "full", feature = "derive"))]
fn __parse_scoped(self, scope: Span, tokens: TokenStream) -> Result<Self::Output> {
let _ = scope;
self.parse2(tokens)
Expand Down Expand Up @@ -1300,7 +1299,6 @@ where
}
}

#[cfg(any(feature = "full", feature = "derive"))]
fn __parse_scoped(self, scope: Span, tokens: TokenStream) -> Result<Self::Output> {
let buf = TokenBuffer::new2(tokens);
let cursor = buf.begin();
Expand All @@ -1316,7 +1314,6 @@ where
}
}

#[cfg(any(feature = "full", feature = "derive"))]
pub(crate) fn parse_scoped<F: Parser>(f: F, scope: Span, tokens: TokenStream) -> Result<F::Output> {
f.__parse_scoped(scope, tokens)
}
Expand Down
Loading