Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,11 @@ impl CheckAttrVisitor<'tcx> {
self.doc_attr_str_error(meta, "keyword");
return false;
}
match self.tcx.hir().expect_item(hir_id).kind {
ItemKind::Mod(ref module) => {
match self.tcx.hir().find(hir_id).and_then(|node| match node {
hir::Node::Item(item) => Some(&item.kind),
_ => None,
}) {
Some(ItemKind::Mod(ref module)) => {
if !module.item_ids.is_empty() {
self.tcx
.sess
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/rustdoc/doc_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ mod foo {

#[doc(keyword = "hall")] //~ ERROR
fn foo() {}


// Regression test for the ICE described in #83512.
trait Foo {
#[doc(keyword = "match")]
//~^ ERROR: `#[doc(keyword = "...")]` can only be used on modules
fn quux() {}
}
8 changes: 7 additions & 1 deletion src/test/ui/rustdoc/doc_keyword.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ error: `#[doc(keyword = "...")]` can only be used on modules
LL | #[doc(keyword = "hall")]
| ^^^^^^^^^^^^^^^^

error: `#[doc(keyword = "...")]` can only be used on modules
--> $DIR/doc_keyword.rs:17:11
|
LL | #[doc(keyword = "match")]
| ^^^^^^^^^^^^^^^^^

error: `#![doc(keyword = "...")]` isn't allowed as a crate-level attribute
--> $DIR/doc_keyword.rs:4:8
|
LL | #![doc(keyword = "hello")]
| ^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 4 previous errors