Skip to content
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

Rustdoc render public underscore_imports as Re-exports #80267

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ E0776: include_str!("./error_codes/E0776.md"),
E0777: include_str!("./error_codes/E0777.md"),
E0778: include_str!("./error_codes/E0778.md"),
E0779: include_str!("./error_codes/E0779.md"),
E0780: include_str!("./error_codes/E0780.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0780.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Cannot use `doc(inline)` with wildcard imports
jyn514 marked this conversation as resolved.
Show resolved Hide resolved

Erroneous code example:

```compile_fail,E0780
extern crate foo;

jyn514 marked this conversation as resolved.
Show resolved Hide resolved
#[doc(inline)] // error: invalid doc argument
pub use foo::Foo as _;
```

When using a wildcard import the `doc` attribute currently only supports:

* hidden

To fix this error either change to one of the available arguments or remove the
`doc` attribute.
jyn514 marked this conversation as resolved.
Show resolved Hide resolved

Example:

```
extern crate foo;

jyn514 marked this conversation as resolved.
Show resolved Hide resolved
pub use foo::Foo as _;
```
15 changes: 15 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2157,11 +2157,26 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
return Vec::new();
}

let inlined = self.attrs.lists(sym::doc).has_word(sym::inline);
let pub_underscore = self.vis.node.is_pub() && self.name == kw::Underscore;

if pub_underscore && inlined {
rustc_errors::struct_span_err!(
cx.tcx.sess,
self.attrs.lists(sym::doc).next().unwrap().span(),
Copy link
Member

Choose a reason for hiding this comment

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

This might be wrong if there are multiple doc attributes. Can you add a test case for

#[doc = "xxx"]
#[doc(inline)]
pub use foo::Foo as _;

Copy link
Author

Choose a reason for hiding this comment

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

This was working as is, maybe because of https://github.com/rust-lang/rust/blob/master/compiler/rustc_ast/src/ast.rs#L496.
Just to be safe it was changed and made some other refactoring to use the previous calculated values.

E0780,
"inline with wildcard import"
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
)
.span_label(self.span, "wildcard import")
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
.emit();
}

// We consider inlining the documentation of `pub use` statements, but we
// forcefully don't inline if this is not public or if the
// #[doc(no_inline)] attribute is present.
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
let mut denied = !self.vis.node.is_pub()
|| pub_underscore
|| self.attrs.iter().any(|a| {
a.has_name(sym::doc)
&& match a.meta_item_list() {
Expand Down
3 changes: 3 additions & 0 deletions src/test/rustdoc-ui/auxiliary/issue-61592.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![crate_name = "foo"]

pub trait Foo {}
8 changes: 8 additions & 0 deletions src/test/rustdoc-ui/issue-61592.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// aux-build:issue-61592.rs

extern crate foo;

#[doc(inline)] //~ ERROR
pub use foo::Foo as _;

fn main() {}
11 changes: 11 additions & 0 deletions src/test/rustdoc-ui/issue-61592.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0780]: inline with wildcard import
--> $DIR/issue-61592.rs:5:7
|
LL | #[doc(inline)]
| ^^^^^^
LL | pub use foo::Foo as _;
| ---------------------- wildcard import

error: aborting due to previous error

For more information about this error, try `rustc --explain E0780`.
4 changes: 4 additions & 0 deletions src/test/rustdoc/auxiliary/issue-61592.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![crate_name = "foo"]

pub trait FooTrait {}
pub struct FooStruct;
15 changes: 15 additions & 0 deletions src/test/rustdoc/issue-61592.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// aux-build:issue-61592.rs

extern crate foo;

// @has issue_61592/index.html
// @has - '//a[@href="#reexports"]' 'Re-exports'
// @has - '//code' 'pub use foo::FooTrait as _;'
// @!has - '//a[@href="trait._.html"]'
pub use foo::FooTrait as _;

// @has issue_61592/index.html
// @has - '//a[@href="#reexports"]' 'Re-exports'
// @has - '//code' 'pub use foo::FooStruct as _;'
// @!has - '//a[@href="struct._.html"]'
pub use foo::FooStruct as _;