Skip to content

Commit

Permalink
Improve error location at eof in LitStr::parse
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 16, 2024
1 parent 270c633 commit 51298d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
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

0 comments on commit 51298d4

Please sign in to comment.