Change NodeIdOneOf and similar to use "requires" and explicit UnsafeMake (#5084)

This doesn't change functionality, but I was seeing better diagnostics
in VS Code.

This also changes the NodeId constructors for related types (also
NodeCategory and NodeIdForKind) to use UnsafeMake for construction. That
originated from avoiding ambiguity coming from `requires`, but the
constructor mode is also one we should typically avoid (e.g., preferring
`Parse::Tree::As`).
This commit is contained in:
Jon Ross-Perkins authored and GitHub committed 2025-03-12 00:33:54 +00:00
1 parent ebaf62efb9
commit e6872f9499
8 files changed
+66 -38

No files matched your search

+3 -3
View File
@@ -155,7 +155,7 @@ struct Extractable<NodeIdForKind<Kind>> {
static auto Extract(NodeExtractor& extractor)
-> std::optional<NodeIdForKind<Kind>> {
if (extractor.MatchesNodeIdForKind(Kind)) {
return NodeIdForKind<Kind>(extractor.ExtractNode());
return NodeIdForKind<Kind>::UnsafeMake(extractor.ExtractNode());
} else {
return std::nullopt;
}
@@ -182,7 +182,7 @@ struct Extractable<NodeIdInCategory<Category>> {
static auto Extract(NodeExtractor& extractor)
-> std::optional<NodeIdInCategory<Category>> {
if (extractor.MatchesNodeIdInCategory(Category)) {
return NodeIdInCategory<Category>(extractor.ExtractNode());
return NodeIdInCategory<Category>::UnsafeMake(extractor.ExtractNode());
} else {
return std::nullopt;
}
@@ -227,7 +227,7 @@ struct Extractable<NodeIdOneOf<T...>> {
static auto Extract(NodeExtractor& extractor)
-> std::optional<NodeIdOneOf<T...>> {
if (extractor.MatchesNodeIdOneOf({T::Kind...})) {
return NodeIdOneOf<T...>(extractor.ExtractNode());
return NodeIdOneOf<T...>::UnsafeMake(extractor.ExtractNode());
} else {
return std::nullopt;
}