Skip to content

fix(embedded): Resolve multiple bugs in frontmatter parser #15573

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

Merged
merged 8 commits into from
May 27, 2025

Conversation

epage
Copy link
Contributor

@epage epage commented May 21, 2025

What does this PR try to resolve?

This pulls in the tests from rust-lang/rust#140035 and ensures we pass them, including switching our parser to be more like the one from rust-lang/rust#137193.

I've added comments specifying why our test results differ from rustcs.

This is part of #12207

How should we test and review this PR?

Additional information

We still have work to do to improve the quality of our error messages

epage added 7 commits May 21, 2025 13:32
@rustbot
Copy link
Collaborator

rustbot commented May 21, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 21, 2025
@epage epage marked this pull request as draft May 21, 2025 20:19
@epage epage marked this pull request as ready for review May 21, 2025 20:21
@epage epage force-pushed the frontmatter-parser branch from 7a73174 to 485c128 Compare May 22, 2025 01:31
Copy link
Member

@weihanglo weihanglo May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow the conversion in rust-lang/rust#137193 or the other merged PR. How much effort should Cargo provide to parse the frontmatter? Do we still want to delgate to rustc for some diagnostics? Or I just need to make sure this parser look correct on its own, without looking at rustc part?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any error we produce will fire before rustc ever gets a chance to report one, so we should aim for rustc-like error messages (yes, we are not there yet). However, we can't catch all cases and have to defer to rustc for those.

Alternatively, we could be really sloppy and ignore, rather than error. The downside is an error will only be produced if rustc is invoked. I'd prefer to not go this route.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Left some tiny comments.

@@ -362,6 +367,7 @@ content: "\n//@ check-pass\n\n// check that frontmatter blocks can have tokens t

#[test]
fn rustc_frontmatter_whitespace_1() {
// Deferred to rustc since this requires knowledge of Rust grammar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why this requires Rust grammar. Can we just match the behavior of “invalid preceding whitespace for frontmatter opening” here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the frontmatter specification does not say we can detect this kind of error case and would require changing that or us having more knowledge of rustc grammar in case this could be part of something valid in rustc one day. This is theoretical right now and I doubt we would design ourselves into a hole like this. We also ship with rustc and can change with them. However, if we want our parser to serve as an example or even pull it out, then that puts more weight on this.

@epage epage force-pushed the frontmatter-parser branch from 485c128 to 58c2256 Compare May 27, 2025 19:42
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@weihanglo weihanglo enabled auto-merge May 27, 2025 20:00
@weihanglo weihanglo added this pull request to the merge queue May 27, 2025
Merged via the queue into rust-lang:master with commit c8d15a3 May 27, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants