Replace infallible name_or_empty
methods with fallible name
methods.
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
This commit is contained in:
parent
7e1f2f9c54
commit
2fef0a30ae
40 changed files with 217 additions and 203 deletions
|
@ -1237,7 +1237,7 @@ impl AttributeExt for Attribute {
|
|||
Attribute::Parsed(AttributeKind::DocComment { kind, comment, .. }) => {
|
||||
Some((*comment, *kind))
|
||||
}
|
||||
Attribute::Unparsed(_) if self.name_or_empty() == sym::doc => {
|
||||
Attribute::Unparsed(_) if self.has_name(sym::doc) => {
|
||||
self.value_str().map(|s| (s, CommentKind::Line))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -1262,8 +1262,8 @@ impl Attribute {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn name_or_empty(&self) -> Symbol {
|
||||
AttributeExt::name_or_empty(self)
|
||||
pub fn name(&self) -> Option<Symbol> {
|
||||
AttributeExt::name(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1301,6 +1301,11 @@ impl Attribute {
|
|||
AttributeExt::has_name(self, name)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn has_any_name(&self, names: &[Symbol]) -> bool {
|
||||
AttributeExt::has_any_name(self, names)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn span(&self) -> Span {
|
||||
AttributeExt::span(self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue