diff options
| author | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-06-17 16:45:26 +0200 |
|---|---|---|
| committer | Fabian Wolff <fabian.wolff@alumni.ethz.ch> | 2021-06-17 16:45:26 +0200 |
| commit | 2cedd86b1c25db321e7e023f6a429e23425a7e00 (patch) | |
| tree | 4b1ce63f4306558f9cdfcb9c7e1489f34828eb8b | |
| parent | b17d9c1332693fc386f5374f0d63aae0ce5abab5 (diff) | |
| download | rust-2cedd86b1c25db321e7e023f6a429e23425a7e00.tar.gz rust-2cedd86b1c25db321e7e023f6a429e23425a7e00.zip | |
Fix ICE when using `#[doc(keyword = "...")]` on non-items
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/rustdoc/issue-83512.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/rustdoc/issue-83512.stderr | 8 |
3 files changed, 23 insertions, 2 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index eca84c791fb..e85392cf0bd 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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 diff --git a/src/test/ui/rustdoc/issue-83512.rs b/src/test/ui/rustdoc/issue-83512.rs new file mode 100644 index 00000000000..378f685ed30 --- /dev/null +++ b/src/test/ui/rustdoc/issue-83512.rs @@ -0,0 +1,10 @@ +// Regression test for the ICE described in #83512. + +#![feature(doc_keyword)] +#![crate_type="lib"] + +trait Foo { + #[doc(keyword = "match")] + //~^ ERROR: `#[doc(keyword = "...")]` can only be used on modules + fn quux() {} +} diff --git a/src/test/ui/rustdoc/issue-83512.stderr b/src/test/ui/rustdoc/issue-83512.stderr new file mode 100644 index 00000000000..da7e480c63e --- /dev/null +++ b/src/test/ui/rustdoc/issue-83512.stderr @@ -0,0 +1,8 @@ +error: `#[doc(keyword = "...")]` can only be used on modules + --> $DIR/issue-83512.rs:7:11 + | +LL | #[doc(keyword = "match")] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + |
