Skip to content

Commit 929749d

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 9fb0def commit 929749d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_passes/src/check_attr.rs

+2-2
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;
@@ -1038,7 +1038,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10381038
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
10391039
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
10401040
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
1041-
s <= kw::Union || s == sym::SelfTy
1041+
s.is_reserved(|| edition::LATEST_STABLE_EDITION) || s.is_weak() || s == sym::SelfTy
10421042
}
10431043

10441044
let doc_keyword = match meta.value_str() {

compiler/rustc_span/src/symbol.rs

+5-1
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",
@@ -2725,6 +2725,10 @@ impl Symbol {
27252725
|| self.is_unused_keyword_conditional(edition)
27262726
}
27272727

2728+
pub fn is_weak(self) -> bool {
2729+
self >= kw::Auto && self <= kw::Yeet
2730+
}
2731+
27282732
/// A keyword or reserved identifier that can be used as a path segment.
27292733
pub fn is_path_segment_keyword(self) -> bool {
27302734
self == kw::Super

0 commit comments

Comments
 (0)