Skip to content

Commit 6af09cb

Browse files
committed
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.
1 parent e306244 commit 6af09cb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
3535
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
3636
};
3737
use rustc_session::parse::feature_err;
38-
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, kw, sym};
38+
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, kw, sym};
3939
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4040
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
4141
use rustc_trait_selection::traits::ObligationCtxt;
@@ -1021,7 +1021,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10211021
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
10221022
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
10231023
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
1024-
s <= kw::Union || s == sym::SelfTy
1024+
s.is_reserved(|| edition::LATEST_STABLE_EDITION) || s.is_weak() || s == sym::SelfTy
10251025
}
10261026

10271027
let doc_keyword = match meta.value_str() {

compiler/rustc_span/src/symbol.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ symbols! {
131131
// tidy-alphabetical-end
132132

133133
// Weak keywords, have special meaning only in specific contexts.
134-
// Matching predicates: none
134+
// Matching predicates: `is_weak`
135135
// tidy-alphabetical-start
136136
Auto: "auto",
137137
Builtin: "builtin",
@@ -2720,6 +2720,10 @@ impl Symbol {
27202720
|| self.is_unused_keyword_conditional(edition)
27212721
}
27222722

2723+
pub fn is_weak(self) -> bool {
2724+
self >= kw::Auto && self <= kw::Yeet
2725+
}
2726+
27232727
/// A keyword or reserved identifier that can be used as a path segment.
27242728
pub fn is_path_segment_keyword(self) -> bool {
27252729
self == kw::Super

0 commit comments

Comments
 (0)