-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc_span: Generate keyword classification functions automatically #75309
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,14 @@ symbols! { | |
Keywords { | ||
// Special reserved identifiers used internally for elided lifetimes, | ||
// unnamed method parameters, crate root module, error recovery etc. | ||
fn is_special: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This confuses code highlighting in my editor (vscode + rust-analyzer), but fn is_special {
Invalid: "",
PathRoot: "{{root}}",
DollarCrate: "$crate",
Underscore: "_",
} |
||
Invalid: "", | ||
PathRoot: "{{root}}", | ||
DollarCrate: "$crate", | ||
Underscore: "_", | ||
|
||
// Keywords that are used in stable Rust. | ||
// Keywords that are used in stable Rust on all editions. | ||
fn is_used_keyword_20xx: | ||
As: "as", | ||
Break: "break", | ||
Const: "const", | ||
|
@@ -67,7 +69,8 @@ symbols! { | |
Where: "where", | ||
While: "while", | ||
|
||
// Keywords that are used in unstable Rust or reserved for future use. | ||
// Keywords that are used in unstable Rust or reserved for future use on all editions. | ||
fn is_unused_keyword_20xx: | ||
Abstract: "abstract", | ||
Become: "become", | ||
Box: "box", | ||
|
@@ -82,18 +85,22 @@ symbols! { | |
Yield: "yield", | ||
|
||
// Edition-specific keywords that are used in stable Rust. | ||
fn is_used_keyword_2018: | ||
Async: "async", // >= 2018 Edition only | ||
Await: "await", // >= 2018 Edition only | ||
Dyn: "dyn", // >= 2018 Edition only | ||
|
||
// Edition-specific keywords that are used in unstable Rust or reserved for future use. | ||
fn is_unused_keyword_2018: | ||
Try: "try", // >= 2018 Edition only | ||
|
||
// Special lifetime names | ||
fn is_special_lifetime: | ||
UnderscoreLifetime: "'_", | ||
StaticLifetime: "'static", | ||
|
||
// Weak keywords, have special meaning only in specific contexts. | ||
fn is_weak_keyword: | ||
Auto: "auto", | ||
Catch: "catch", | ||
Default: "default", | ||
|
@@ -1546,19 +1553,6 @@ pub mod sym { | |
} | ||
|
||
impl Symbol { | ||
fn is_used_keyword_2018(self) -> bool { | ||
self >= kw::Async && self <= kw::Dyn | ||
} | ||
|
||
fn is_unused_keyword_2018(self) -> bool { | ||
self == kw::Try | ||
} | ||
|
||
/// Used for sanity checking rustdoc keyword sections. | ||
pub fn is_doc_keyword(self) -> bool { | ||
self <= kw::Union | ||
} | ||
|
||
/// A keyword or reserved identifier that can be used as a path segment. | ||
pub fn is_path_segment_keyword(self) -> bool { | ||
self == kw::Super | ||
|
@@ -1584,20 +1578,20 @@ impl Ident { | |
// Returns `true` for reserved identifiers used internally for elided lifetimes, | ||
// unnamed method parameters, crate root module, error recovery etc. | ||
pub fn is_special(self) -> bool { | ||
self.name <= kw::Underscore | ||
self.name.is_special() | ||
} | ||
|
||
/// Returns `true` if the token is a keyword used in the language. | ||
pub fn is_used_keyword(self) -> bool { | ||
// Note: `span.edition()` is relatively expensive, don't call it unless necessary. | ||
self.name >= kw::As && self.name <= kw::While | ||
self.name.is_used_keyword_20xx() | ||
|| self.name.is_used_keyword_2018() && self.span.rust_2018() | ||
} | ||
|
||
/// Returns `true` if the token is a keyword reserved for possible future use. | ||
pub fn is_unused_keyword(self) -> bool { | ||
// Note: `span.edition()` is relatively expensive, don't call it unless necessary. | ||
self.name >= kw::Abstract && self.name <= kw::Yield | ||
self.name.is_unused_keyword_20xx() | ||
|| self.name.is_unused_keyword_2018() && self.span.rust_2018() | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 wonder if there's any simpler way to skip a token with
syn
parser.