Skip to content

Commit 0274401

Browse files
authored
Rollup merge of rust-lang#86401 - FabianWolff:issue-83512, r=LeSeulArtichaut
Fix ICE when using `#[doc(keyword = "...")]` on non-items This pull request fixes rust-lang#83512. The code for checking attributes calls `expect_item()` when it shouldn't, thus causing an ICE. I have implemented a proper check for the node kind, so that an error is reported instead of the ICE.
2 parents 3d7437f + e9e844f commit 0274401

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
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/doc_keyword.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ mod foo {
1010

1111
#[doc(keyword = "hall")] //~ ERROR
1212
fn foo() {}
13+
14+
15+
// Regression test for the ICE described in #83512.
16+
trait Foo {
17+
#[doc(keyword = "match")]
18+
//~^ ERROR: `#[doc(keyword = "...")]` can only be used on modules
19+
fn quux() {}
20+
}

src/test/ui/rustdoc/doc_keyword.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ error: `#[doc(keyword = "...")]` can only be used on modules
1010
LL | #[doc(keyword = "hall")]
1111
| ^^^^^^^^^^^^^^^^
1212

13+
error: `#[doc(keyword = "...")]` can only be used on modules
14+
--> $DIR/doc_keyword.rs:17:11
15+
|
16+
LL | #[doc(keyword = "match")]
17+
| ^^^^^^^^^^^^^^^^^
18+
1319
error: `#![doc(keyword = "...")]` isn't allowed as a crate-level attribute
1420
--> $DIR/doc_keyword.rs:4:8
1521
|
1622
LL | #![doc(keyword = "hello")]
1723
| ^^^^^^^^^^^^^^^^^
1824

19-
error: aborting due to 3 previous errors
25+
error: aborting due to 4 previous errors
2026

0 commit comments

Comments
 (0)