about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-12-12 13:57:46 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-12-17 13:56:10 +1100
commit121e87bf1490f0258bdb354eb8c4e891ebb7e7e7 (patch)
tree949a273bcd41aaceee9a86689e885effc5e0160a
parentf10169c4ec5cc7b059217db7471cb13448b1207e (diff)
downloadrust-121e87bf1490f0258bdb354eb8c4e891ebb7e7e7.tar.gz
rust-121e87bf1490f0258bdb354eb8c4e891ebb7e7e7.zip
Remove `rustc::existing_doc_keyword` lint.
`CheckAttrVisitor::check_doc_keyword` checks `#[doc(keyword = "..")]`
attributes to ensure they are on an empty module, and that the value is
a non-empty identifier.

The `rustc::existing_doc_keyword` lint checks these attributes to ensure
that the value is the name of a keyword.

It's silly to have two different checking mechanisms for these
attributes. This commit does the following.
- Changes `check_doc_keyword` to check that the value is the name of a
  keyword (avoiding the need for the identifier check, which removes a
  dependency on `rustc_lexer`).
- Removes the lint.
- Updates tests accordingly.

There is one hack: the `SelfTy` FIXME case used to used to be handled by
disabling the lint, but now is handled with a special case in
`is_doc_keyword`. That hack will go away if/when the FIXME is fixed.

Co-Authored-By: Guillaume Gomez <guillaume1.gomez@gmail.com>
-rw-r--r--Cargo.lock1
-rw-r--r--compiler/rustc_lint/messages.ftl3
-rw-r--r--compiler/rustc_lint/src/internal.rs44
-rw-r--r--compiler/rustc_lint/src/lib.rs3
-rw-r--r--compiler/rustc_lint/src/lints.rs7
-rw-r--r--compiler/rustc_passes/Cargo.toml1
-rw-r--r--compiler/rustc_passes/messages.ftl5
-rw-r--r--compiler/rustc_passes/src/check_attr.rs13
-rw-r--r--compiler/rustc_passes/src/errors.rs11
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--library/std/src/keyword_docs.rs6
-rw-r--r--library/std/src/lib.rs1
-rw-r--r--src/doc/rustdoc/src/unstable-features.md2
-rw-r--r--tests/rustdoc-gui/search-result-color.goml3
-rw-r--r--tests/rustdoc-gui/search-result-keyword.goml4
-rw-r--r--tests/rustdoc-gui/search-tab.goml2
-rw-r--r--tests/rustdoc-gui/src/test_docs/lib.rs2
-rw-r--r--tests/rustdoc-json/keyword.rs4
-rw-r--r--tests/rustdoc-json/keyword_private.rs6
-rw-r--r--tests/rustdoc-ui/invalid-keyword.stderr4
-rw-r--r--tests/rustdoc/keyword.rs4
-rw-r--r--tests/ui/internal-lints/existing_doc_keyword.rs10
-rw-r--r--tests/ui/internal-lints/existing_doc_keyword.stderr15
-rw-r--r--tests/ui/rustdoc/doc_keyword.rs11
-rw-r--r--tests/ui/rustdoc/doc_keyword.stderr10
25 files changed, 58 insertions, 115 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 923d4017c0c..6f073d06fae 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4273,7 +4273,6 @@ dependencies = [
  "rustc_fluent_macro",
  "rustc_hir",
  "rustc_index",
- "rustc_lexer",
  "rustc_macros",
  "rustc_middle",
  "rustc_privacy",
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index 01d9ac20fae..13937c78ed6 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -536,9 +536,6 @@ lint_non_camel_case_type = {$sort} `{$name}` should have an upper camel case nam
     .suggestion = convert the identifier to upper camel case
     .label = should have an UpperCamelCase name
 
-lint_non_existent_doc_keyword = found non-existing keyword `{$keyword}` used in `#[doc(keyword = "...")]`
-    .help = only existing keywords are allowed in core/std
-
 lint_non_fmt_panic = panic message is not a string literal
     .note = this usage of `{$name}!()` is deprecated; it will be a hard error in Rust 2021
     .more_info_note = for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs
index 482650e04e8..4dff512f9d6 100644
--- a/compiler/rustc_lint/src/internal.rs
+++ b/compiler/rustc_lint/src/internal.rs
@@ -12,11 +12,11 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty as MiddleTy};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::Span;
 use rustc_span::hygiene::{ExpnKind, MacroKind};
-use rustc_span::symbol::{Symbol, kw, sym};
+use rustc_span::symbol::sym;
 use tracing::debug;
 
 use crate::lints::{
-    BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand, NonExistentDocKeyword,
+    BadOptAccessDiag, DefaultHashTypesDiag, DiagOutOfImpl, LintPassByHand,
     NonGlobImportTypeIrInherent, QueryInstability, QueryUntracked, SpanUseEqCtxtDiag,
     SymbolInternStringLiteralDiag, TyQualified, TykindDiag, TykindKind, TypeIrInherentUsage,
     UntranslatableDiag,
@@ -376,46 +376,6 @@ impl EarlyLintPass for LintPassImpl {
 }
 
 declare_tool_lint! {
-    /// The `existing_doc_keyword` lint detects use `#[doc()]` keywords
-    /// that don't exist, e.g. `#[doc(keyword = "..")]`.
-    pub rustc::EXISTING_DOC_KEYWORD,
-    Allow,
-    "Check that documented keywords in std and core actually exist",
-    report_in_external_macro: true
-}
-
-declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);
-
-fn is_doc_keyword(s: Symbol) -> bool {
-    s <= kw::Union
-}
-
-impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
-    fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
-        for attr in cx.tcx.hir().attrs(item.hir_id()) {
-            if !attr.has_name(sym::doc) {
-                continue;
-            }
-            if let Some(list) = attr.meta_item_list() {
-                for nested in list {
-                    if nested.has_name(sym::keyword) {
-                        let keyword = nested
-                            .value_str()
-                            .expect("#[doc(keyword = \"...\")] expected a value!");
-                        if is_doc_keyword(keyword) {
-                            return;
-                        }
-                        cx.emit_span_lint(EXISTING_DOC_KEYWORD, attr.span, NonExistentDocKeyword {
-                            keyword,
-                        });
-                    }
-                }
-            }
-        }
-    }
-}
-
-declare_tool_lint! {
     /// The `untranslatable_diagnostic` lint detects messages passed to functions with `impl
     /// Into<{D,Subd}iagMessage` parameters without using translatable Fluent strings.
     ///
diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs
index a99c94592b3..d7f0d2a6941 100644
--- a/compiler/rustc_lint/src/lib.rs
+++ b/compiler/rustc_lint/src/lib.rs
@@ -600,8 +600,6 @@ fn register_internals(store: &mut LintStore) {
     store.register_late_mod_pass(|_| Box::new(DefaultHashTypes));
     store.register_lints(&QueryStability::lint_vec());
     store.register_late_mod_pass(|_| Box::new(QueryStability));
-    store.register_lints(&ExistingDocKeyword::lint_vec());
-    store.register_late_mod_pass(|_| Box::new(ExistingDocKeyword));
     store.register_lints(&TyTyKind::lint_vec());
     store.register_late_mod_pass(|_| Box::new(TyTyKind));
     store.register_lints(&TypeIr::lint_vec());
@@ -629,7 +627,6 @@ fn register_internals(store: &mut LintStore) {
         LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
         LintId::of(USAGE_OF_QUALIFIED_TY),
         LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
-        LintId::of(EXISTING_DOC_KEYWORD),
         LintId::of(BAD_OPT_ACCESS),
         LintId::of(SPAN_USE_EQ_CTXT),
     ]);
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 5da9f6d2053..c3d3212b2e2 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -951,13 +951,6 @@ pub(crate) struct NonGlobImportTypeIrInherent {
 pub(crate) struct LintPassByHand;
 
 #[derive(LintDiagnostic)]
-#[diag(lint_non_existent_doc_keyword)]
-#[help]
-pub(crate) struct NonExistentDocKeyword {
-    pub keyword: Symbol,
-}
-
-#[derive(LintDiagnostic)]
 #[diag(lint_diag_out_of_impl)]
 pub(crate) struct DiagOutOfImpl;
 
diff --git a/compiler/rustc_passes/Cargo.toml b/compiler/rustc_passes/Cargo.toml
index ed5991459ac..e1cb6903839 100644
--- a/compiler/rustc_passes/Cargo.toml
+++ b/compiler/rustc_passes/Cargo.toml
@@ -16,7 +16,6 @@ rustc_feature = { path = "../rustc_feature" }
 rustc_fluent_macro = { path = "../rustc_fluent_macro" }
 rustc_hir = { path = "../rustc_hir" }
 rustc_index = { path = "../rustc_index" }
-rustc_lexer = { path = "../rustc_lexer" }
 rustc_macros = { path = "../rustc_macros" }
 rustc_middle = { path = "../rustc_middle" }
 rustc_privacy = { path = "../rustc_privacy" }
diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl
index 7a0a518bb51..fd133ba878e 100644
--- a/compiler/rustc_passes/messages.ftl
+++ b/compiler/rustc_passes/messages.ftl
@@ -211,8 +211,9 @@ passes_doc_invalid =
 passes_doc_keyword_empty_mod =
     `#[doc(keyword = "...")]` should be used on empty modules
 
-passes_doc_keyword_invalid_ident =
-    `{$doc_keyword}` is not a valid identifier
+passes_doc_keyword_not_keyword =
+    nonexistent keyword `{$keyword}` used in `#[doc(keyword = "...")]`
+    .help = only existing keywords are allowed in core/std
 
 passes_doc_keyword_not_mod =
     `#[doc(keyword = "...")]` should be used on modules
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index a400fa6752a..0cd47541717 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -914,6 +914,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
     }
 
     fn check_doc_keyword(&self, meta: &MetaItemInner, hir_id: HirId) {
+        fn is_doc_keyword(s: Symbol) -> bool {
+            // 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
+        }
+
         let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
         if doc_keyword == kw::Empty {
             self.doc_attr_str_error(meta, "keyword");
@@ -935,10 +942,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
                 return;
             }
         }
-        if !rustc_lexer::is_ident(doc_keyword.as_str()) {
-            self.dcx().emit_err(errors::DocKeywordInvalidIdent {
+        if !is_doc_keyword(doc_keyword) {
+            self.dcx().emit_err(errors::DocKeywordNotKeyword {
                 span: meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
-                doc_keyword,
+                keyword: doc_keyword,
             });
         }
     }
diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs
index fdc7e1bba2f..f71d5284052 100644
--- a/compiler/rustc_passes/src/errors.rs
+++ b/compiler/rustc_passes/src/errors.rs
@@ -216,18 +216,19 @@ pub(crate) struct DocKeywordEmptyMod {
 }
 
 #[derive(Diagnostic)]
-#[diag(passes_doc_keyword_not_mod)]
-pub(crate) struct DocKeywordNotMod {
+#[diag(passes_doc_keyword_not_keyword)]
+#[help]
+pub(crate) struct DocKeywordNotKeyword {
     #[primary_span]
     pub span: Span,
+    pub keyword: Symbol,
 }
 
 #[derive(Diagnostic)]
-#[diag(passes_doc_keyword_invalid_ident)]
-pub(crate) struct DocKeywordInvalidIdent {
+#[diag(passes_doc_keyword_not_mod)]
+pub(crate) struct DocKeywordNotMod {
     #[primary_span]
     pub span: Span,
-    pub doc_keyword: Symbol,
 }
 
 #[derive(Diagnostic)]
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index e51a05b313e..81c47880f15 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -306,6 +306,7 @@ symbols! {
         RwLockWriteGuard,
         Saturating,
         SeekFrom,
+        SelfTy,
         Send,
         SeqCst,
         Sized,
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs
index c8ff8bfaaef..0c526eafdf3 100644
--- a/library/std/src/keyword_docs.rs
+++ b/library/std/src/keyword_docs.rs
@@ -1263,10 +1263,10 @@ mod return_keyword {}
 /// [Reference]: ../reference/items/associated-items.html#methods
 mod self_keyword {}
 
-// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we can remove the
-// three next lines and put back: `#[doc(keyword = "Self")]`.
+// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we can replace
+// these two lines with `#[doc(keyword = "Self")]` and update `is_doc_keyword` in
+// `CheckAttrVisitor`.
 #[doc(alias = "Self")]
-#[allow(rustc::existing_doc_keyword)]
 #[doc(keyword = "SelfTy")]
 //
 /// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 2b97f73f79a..1c80694ca8f 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -251,7 +251,6 @@
 #![allow(explicit_outlives_requirements)]
 #![allow(unused_lifetimes)]
 #![allow(internal_features)]
-#![deny(rustc::existing_doc_keyword)]
 #![deny(fuzzy_provenance_casts)]
 #![deny(unsafe_op_in_unsafe_fn)]
 #![allow(rustdoc::redundant_explicit_links)]
diff --git a/src/doc/rustdoc/src/unstable-features.md b/src/doc/rustdoc/src/unstable-features.md
index db8426492ee..f19c3a51f61 100644
--- a/src/doc/rustdoc/src/unstable-features.md
+++ b/src/doc/rustdoc/src/unstable-features.md
@@ -207,7 +207,7 @@ To do so, the `#[doc(keyword = "...")]` attribute is used. Example:
 #![allow(internal_features)]
 
 /// Some documentation about the keyword.
-#[doc(keyword = "keyword")]
+#[doc(keyword = "break")]
 mod empty_mod {}
 ```
 
diff --git a/tests/rustdoc-gui/search-result-color.goml b/tests/rustdoc-gui/search-result-color.goml
index e8da43eb896..e6dd504d703 100644
--- a/tests/rustdoc-gui/search-result-color.goml
+++ b/tests/rustdoc-gui/search-result-color.goml
@@ -140,7 +140,8 @@ define-function: (
     },
 )
 
-go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=coo"
+// Searching for the `for` keyword
+go-to: "file://" + |DOC_PATH| + "/test_docs/index.html?search=fo"
 
 // This is needed so that the text color is computed.
 show-text: true
diff --git a/tests/rustdoc-gui/search-result-keyword.goml b/tests/rustdoc-gui/search-result-keyword.goml
index 370edce2ddd..02305f2587c 100644
--- a/tests/rustdoc-gui/search-result-keyword.goml
+++ b/tests/rustdoc-gui/search-result-keyword.goml
@@ -1,8 +1,8 @@
 // Checks that the "keyword" results have the expected text alongside them.
 go-to: "file://" + |DOC_PATH| + "/test_docs/index.html"
-write-into: (".search-input", "CookieMonster")
+write-into: (".search-input", "for")
 // To be SURE that the search will be run.
 press-key: 'Enter'
 // Waiting for the search results to appear...
 wait-for: "#search-tabs"
-assert-text: (".result-keyword .result-name", "keyword CookieMonster")
+assert-text: (".result-keyword .result-name", "keyword for")
diff --git a/tests/rustdoc-gui/search-tab.goml b/tests/rustdoc-gui/search-tab.goml
index 4329726398c..3879c127fd0 100644
--- a/tests/rustdoc-gui/search-tab.goml
+++ b/tests/rustdoc-gui/search-tab.goml
@@ -78,7 +78,7 @@ call-function: ("check-colors", {
 set-window-size: (851, 600)
 
 // Check the size and count in tabs
-assert-text: ("#search-tabs > button:nth-child(1) > .count", " (25) ")
+assert-text: ("#search-tabs > button:nth-child(1) > .count", " (26) ")
 assert-text: ("#search-tabs > button:nth-child(2) > .count", " (6)  ")
 assert-text: ("#search-tabs > button:nth-child(3) > .count", " (0)  ")
 store-property: ("#search-tabs > button:nth-child(1)", {"offsetWidth": buttonWidth})
diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs
index 91aa2c3fae5..dae13d9ac18 100644
--- a/tests/rustdoc-gui/src/test_docs/lib.rs
+++ b/tests/rustdoc-gui/src/test_docs/lib.rs
@@ -156,7 +156,7 @@ pub enum AnEnum {
     WithVariants { and: usize, sub: usize, variants: usize },
 }
 
-#[doc(keyword = "CookieMonster")]
+#[doc(keyword = "for")]
 /// Some keyword.
 pub mod keyword {}
 
diff --git a/tests/rustdoc-json/keyword.rs b/tests/rustdoc-json/keyword.rs
index 7a820cd1487..8a2130f1978 100644
--- a/tests/rustdoc-json/keyword.rs
+++ b/tests/rustdoc-json/keyword.rs
@@ -13,8 +13,8 @@
 /// this is a test!
 pub mod foo {}
 
-//@ !has "$.index[*][?(@.name=='hello')]"
+//@ !has "$.index[*][?(@.name=='break')]"
 //@ !has "$.index[*][?(@.name=='bar')]"
-#[doc(keyword = "hello")]
+#[doc(keyword = "break")]
 /// hello
 mod bar {}
diff --git a/tests/rustdoc-json/keyword_private.rs b/tests/rustdoc-json/keyword_private.rs
index 7a030041f7c..2a13bf10d5d 100644
--- a/tests/rustdoc-json/keyword_private.rs
+++ b/tests/rustdoc-json/keyword_private.rs
@@ -11,10 +11,10 @@
 /// this is a test!
 pub mod foo {}
 
-//@ !has "$.index[*][?(@.name=='hello')]"
+//@ !has "$.index[*][?(@.name=='break')]"
 //@ has "$.index[*][?(@.name=='bar')]"
-//@ is   "$.index[*][?(@.name=='bar')].attrs" '["#[doc(keyword = \"hello\")]"]'
+//@ is   "$.index[*][?(@.name=='bar')].attrs" '["#[doc(keyword = \"break\")]"]'
 //@ is   "$.index[*][?(@.name=='bar')].docs" '"hello"'
-#[doc(keyword = "hello")]
+#[doc(keyword = "break")]
 /// hello
 mod bar {}
diff --git a/tests/rustdoc-ui/invalid-keyword.stderr b/tests/rustdoc-ui/invalid-keyword.stderr
index 82faaaab47f..c1e41d3b0b3 100644
--- a/tests/rustdoc-ui/invalid-keyword.stderr
+++ b/tests/rustdoc-ui/invalid-keyword.stderr
@@ -1,8 +1,10 @@
-error: `foo df` is not a valid identifier
+error: nonexistent keyword `foo df` used in `#[doc(keyword = "...")]`
   --> $DIR/invalid-keyword.rs:3:17
    |
 LL | #[doc(keyword = "foo df")]
    |                 ^^^^^^^^
+   |
+   = help: only existing keywords are allowed in core/std
 
 error: aborting due to 1 previous error
 
diff --git a/tests/rustdoc/keyword.rs b/tests/rustdoc/keyword.rs
index 519e1944bc7..8f86c8ffd38 100644
--- a/tests/rustdoc/keyword.rs
+++ b/tests/rustdoc/keyword.rs
@@ -16,7 +16,7 @@
 /// this is a test!
 mod foo{}
 
-//@ has foo/keyword.foo.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello'
-#[doc(keyword = "foo")]
+//@ has foo/keyword.break.html '//section[@id="main-content"]//div[@class="docblock"]//p' 'hello'
+#[doc(keyword = "break")]
 /// hello
 mod bar {}
diff --git a/tests/ui/internal-lints/existing_doc_keyword.rs b/tests/ui/internal-lints/existing_doc_keyword.rs
deleted file mode 100644
index 8f60b931591..00000000000
--- a/tests/ui/internal-lints/existing_doc_keyword.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-//@ compile-flags: -Z unstable-options
-
-#![feature(rustdoc_internals)]
-
-#![crate_type = "lib"]
-
-#![deny(rustc::existing_doc_keyword)]
-
-#[doc(keyword = "tadam")] //~ ERROR
-mod tadam {}
diff --git a/tests/ui/internal-lints/existing_doc_keyword.stderr b/tests/ui/internal-lints/existing_doc_keyword.stderr
deleted file mode 100644
index 5573e7ce4d0..00000000000
--- a/tests/ui/internal-lints/existing_doc_keyword.stderr
+++ /dev/null
@@ -1,15 +0,0 @@
-error: found non-existing keyword `tadam` used in `#[doc(keyword = "...")]`
-  --> $DIR/existing_doc_keyword.rs:9:1
-   |
-LL | #[doc(keyword = "tadam")]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = help: only existing keywords are allowed in core/std
-note: the lint level is defined here
-  --> $DIR/existing_doc_keyword.rs:7:9
-   |
-LL | #![deny(rustc::existing_doc_keyword)]
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 1 previous error
-
diff --git a/tests/ui/rustdoc/doc_keyword.rs b/tests/ui/rustdoc/doc_keyword.rs
index 68a8802b2f6..e0995f336da 100644
--- a/tests/ui/rustdoc/doc_keyword.rs
+++ b/tests/ui/rustdoc/doc_keyword.rs
@@ -1,14 +1,14 @@
 #![crate_type = "lib"]
 #![feature(rustdoc_internals)]
 
-#![doc(keyword = "hello")] //~ ERROR
-
-#[doc(keyword = "hell")] //~ ERROR
+#![doc(keyword = "hello")]
+//~^ ERROR `#![doc(keyword = "...")]` isn't allowed as a crate-level attribute
+#[doc(keyword = "hell")] //~ ERROR `#[doc(keyword = "...")]` should be used on empty modules
 mod foo {
     fn hell() {}
 }
 
-#[doc(keyword = "hall")] //~ ERROR
+#[doc(keyword = "hall")] //~ ERROR `#[doc(keyword = "...")]` should be used on modules
 fn foo() {}
 
 
@@ -18,3 +18,6 @@ trait Foo {
     //~^ ERROR: `#[doc(keyword = "...")]` should be used on modules
     fn quux() {}
 }
+
+#[doc(keyword = "tadam")] //~ ERROR nonexistent keyword `tadam`
+mod tadam {}
diff --git a/tests/ui/rustdoc/doc_keyword.stderr b/tests/ui/rustdoc/doc_keyword.stderr
index a1d0e4ffc09..584daae2f1a 100644
--- a/tests/ui/rustdoc/doc_keyword.stderr
+++ b/tests/ui/rustdoc/doc_keyword.stderr
@@ -10,6 +10,14 @@ error: `#[doc(keyword = "...")]` should be used on modules
 LL | #[doc(keyword = "hall")]
    |       ^^^^^^^^^^^^^^^^
 
+error: nonexistent keyword `tadam` used in `#[doc(keyword = "...")]`
+  --> $DIR/doc_keyword.rs:22:17
+   |
+LL | #[doc(keyword = "tadam")]
+   |                 ^^^^^^^
+   |
+   = help: only existing keywords are allowed in core/std
+
 error: `#[doc(keyword = "...")]` should be used on modules
   --> $DIR/doc_keyword.rs:17:11
    |
@@ -22,5 +30,5 @@ error: `#![doc(keyword = "...")]` isn't allowed as a crate-level attribute
 LL | #![doc(keyword = "hello")]
    |        ^^^^^^^^^^^^^^^^^
 
-error: aborting due to 4 previous errors
+error: aborting due to 5 previous errors