Improve is_doc_keyword
.
This is part of the implementation of `#[doc(keyword = "match")]` attributes used by `std` to provide documentation for keywords. `is_doc_keyword` currently does a crude keyword range test that's intended to catch all keywords but misses `kw::Yeet`. This commit changes it to use `Symbol` methods, including the new `is_weak` method (required for `union`). `Symbol` methods are much less prone to falling out of date if new keywords are added.
This commit is contained in:
parent
9fb0defa52
commit
929749d801
2 changed files with 7 additions and 3 deletions
|
@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
|
|||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
|
||||
};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, kw, sym};
|
||||
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, kw, sym};
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
|
@ -1038,7 +1038,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
|
||||
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
|
||||
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
|
||||
s <= kw::Union || s == sym::SelfTy
|
||||
s.is_reserved(|| edition::LATEST_STABLE_EDITION) || s.is_weak() || s == sym::SelfTy
|
||||
}
|
||||
|
||||
let doc_keyword = match meta.value_str() {
|
||||
|
|
|
@ -131,7 +131,7 @@ symbols! {
|
|||
// tidy-alphabetical-end
|
||||
|
||||
// Weak keywords, have special meaning only in specific contexts.
|
||||
// Matching predicates: none
|
||||
// Matching predicates: `is_weak`
|
||||
// tidy-alphabetical-start
|
||||
Auto: "auto",
|
||||
Builtin: "builtin",
|
||||
|
@ -2725,6 +2725,10 @@ impl Symbol {
|
|||
|| self.is_unused_keyword_conditional(edition)
|
||||
}
|
||||
|
||||
pub fn is_weak(self) -> bool {
|
||||
self >= kw::Auto && self <= kw::Yeet
|
||||
}
|
||||
|
||||
/// A keyword or reserved identifier that can be used as a path segment.
|
||||
pub fn is_path_segment_keyword(self) -> bool {
|
||||
self == kw::Super
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue