Skip to content

internal: tighten up parser API #11134

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 29 commits into from
Dec 28, 2021
Merged

internal: tighten up parser API #11134

merged 29 commits into from
Dec 28, 2021

Conversation

matklad
Copy link
Member

@matklad matklad commented Dec 28, 2021

It's tempting to expose things like Expr::parse,
but they'll necessary have somewhat ad-hoc semantics.

Instead, we narrow down the parser's interface strictly
to what's needed for MBE. For everything else (eg, parsing
imports), the proper way is enclose the input string into
some context, parse the whole as a file, and then verify
that the input was parsed as intended.

bors r+
🤖

|| seg.generic_arg_list().is_none()
});
if !valid_use_path {
let use_path = ast::SourceFile::parse(&format!("use {};", path))
Copy link
Member Author

Choose a reason for hiding this comment

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

cc @Veykril

This looks iffy at first, but I think that's actually the right way to check things like "is this a valid import path?" -- just construct a file with import and check this directly!

Also, looking at this, what || intended to be &&?

Copy link
Member

Choose a reason for hiding this comment

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

Ye that was supposed to be &&.

And I agree, this check is certainly nicer, it makes it more clear as well what is expected to be valid here.

@bors
Copy link
Contributor

bors bot commented Dec 28, 2021

@bors bors bot merged commit 355a4bd into rust-lang:master Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants