-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: master
Are you sure you want to change the base?
Conversation
I left out those dealing with proc-macros or `include`
We could say that we delegate this to rustc but if they add support for multiple frontmatters, we need to update to be able to know which we should read, so its better to error on our side.
r? @weihanglo rustbot has assigned @weihanglo. Use |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@@ -514,6 +514,7 @@ fn main() {} | |||
|
|||
#[test] | |||
fn rustc_multifrontmatter_2() { | |||
// This should be valid, bug on rustc's side |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an issue link so we won't forget it?
rust-lang/rust#141367
@@ -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 |
There was a problem hiding this comment.
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?
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