Skip to content

Find more invalid doc attributes #83098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 15, 2021
Merged
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/test/ui/attributes/doc-attr.rs
Original file line number Diff line number Diff line change
@@ -17,4 +17,9 @@ pub fn foo() {}
//~| WARN
//~| ERROR unknown `doc` attribute
//~| WARN
#[doc(foo::bar, crate::bar::baz = "bye")]
//~^ ERROR unknown `doc` attribute
//~| WARN
//~| ERROR unknown `doc` attribute
//~| WARN
fn bar() {}
20 changes: 19 additions & 1 deletion src/test/ui/attributes/doc-attr.stderr
Original file line number Diff line number Diff line change
@@ -40,6 +40,24 @@ LL | #[doc("hello", "bar")]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>

error: unknown `doc` attribute ``
--> $DIR/doc-attr.rs:20:7
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>

error: unknown `doc` attribute ``
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I display the Path? There doesn't seem to be a Display impl.

Note that this is not a regression; this test is just exposing the previous behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of name_or_empty, could use name_value_literal_span and then get the snippet for that Span? Or is path_to_string accessible here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think rustc_ast_pretty is accessible here, though I could add it as a dependency. I'm trying out the span_to_snippet approach now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both span_to_snippet and path_to_string worked. I'm leaning towards path_to_string because I think it will handle foo :: bar:: baz gracefully as foo::bar::baz, but which one would you prefer I use? You can see what the code looks like with span_to_snippet vs path_to_string here: 8f40e11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd normally want to lean against introducing more dependencies between our crates, but depending on rust_ast_pretty when we already depend on rust_ast is probably fine. Let's stick with path_to_string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like rustc_passes already depends transitively on rustc_ast_pretty anyway.

--> $DIR/doc-attr.rs:20:17
|
LL | #[doc(foo::bar, crate::bar::baz = "bye")]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>

error: unknown `doc` attribute `as_ptr`
--> $DIR/doc-attr.rs:3:8
|
@@ -49,5 +67,5 @@ LL | #![doc(as_ptr)]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>

error: aborting due to 5 previous errors
error: aborting due to 7 previous errors