Rollup merge of #86401 - FabianWolff:issue-83512, r=LeSeulArtichaut

Fix ICE when using `#[doc(keyword = "...")]` on non-items

This pull request fixes #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.
This commit is contained in:
Mara Bos 2021-06-17 23:41:02 +02:00 committed by GitHub
commit 0274401f93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View file

@ -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() {}
}

View file

@ -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