dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.82k stars 308 forks source link

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

Closed dtolnay closed 7 months ago

dtolnay commented 7 months ago

I noticed this in https://github.com/colin-kiegel/rust-derive-builder/pull/310. When using litstr.parse() on a string literal token whose contents are empty, there previously were not any tokens in which the span could be transferred to the inner parser. This is what the "scope" span is supposed to be for, which is also used for parsing the contents of empty delimiters, for the same reason.

Before:

error: unexpected end of input, expected expression
 --> tests/compile-fail/deny_empty_default.rs:6:10
  |
6 | #[derive(Builder)]
  |          ^^^^^^^
  |
  = note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)

After:

error: unexpected end of input, expected expression
 --> tests/compile-fail/deny_empty_default.rs:8:25
  |
8 |     #[builder(default = "")]
  |                         ^^