Skip to content

Commit 2cedd86

Browse files
committed
Fix ICE when using #[doc(keyword = "...")] on non-items
1 parent b17d9c1 commit 2cedd86

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

compiler/rustc_passes/src/check_attr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,11 @@ impl CheckAttrVisitor<'tcx> {
525525
self.doc_attr_str_error(meta, "keyword");
526526
return false;
527527
}
528-
match self.tcx.hir().expect_item(hir_id).kind {
529-
ItemKind::Mod(ref module) => {
528+
match self.tcx.hir().find(hir_id).and_then(|node| match node {
529+
hir::Node::Item(item) => Some(&item.kind),
530+
_ => None,
531+
}) {
532+
Some(ItemKind::Mod(ref module)) => {
530533
if !module.item_ids.is_empty() {
531534
self.tcx
532535
.sess

src/test/ui/rustdoc/issue-83512.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for the ICE described in #83512.
2+
3+
#![feature(doc_keyword)]
4+
#![crate_type="lib"]
5+
6+
trait Foo {
7+
#[doc(keyword = "match")]
8+
//~^ ERROR: `#[doc(keyword = "...")]` can only be used on modules
9+
fn quux() {}
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `#[doc(keyword = "...")]` can only be used on modules
2+
--> $DIR/issue-83512.rs:7:11
3+
|
4+
LL | #[doc(keyword = "match")]
5+
| ^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)