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 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
14 changes: 5 additions & 9 deletions compiler/rustc_error_codes/src/error_codes/E0780.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
Cannot use `doc(inline)` with wildcard imports
Cannot use `doc(inline)` with anonymous imports

Erroneous code example:

```compile_fail,E0780
```compile_fail,E0780,edition2018
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.
Anonymous imports are always rendered with `#[doc(no_inline)]`. To fix this
error, remove the `#[doc(inline)]` attribute.

Example:

```
```ignore (cannot-doctest-multicrate-project)
extern crate foo;

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

let inlined = self.attrs.lists(sym::doc).has_word(sym::inline);
let (doc_meta_item, inlined) = self.attrs.lists(sym::doc).get_word_attr(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(),
doc_meta_item.unwrap().span(),
E0780,
"inline with wildcard import"
"anonymous imports cannot be inlined"
)
.span_label(self.span, "wildcard import")
.span_label(self.span, "anonymous import")
.emit();
}

Expand All @@ -2189,7 +2189,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
});
// Also check whether imports were asked to be inlined, in case we're trying to re-export a
// crate in Rust 2018+
let please_inline = self.attrs.lists(sym::doc).has_word(sym::inline);
let please_inline = inlined;
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
let path = self.path.clean(cx);
let inner = if self.glob {
if !denied {
Expand Down
12 changes: 11 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,22 @@ impl AttributesExt for [ast::Attribute] {
crate trait NestedAttributesExt {
/// Returns `true` if the attribute list contains a specific `Word`
fn has_word(self, word: Symbol) -> bool;
fn get_word_attr(self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool);
}

impl<I: IntoIterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMetaItem>>
NestedAttributesExt for I
{
fn has_word(self, word: Symbol) -> bool {
self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
}

fn get_word_attr(mut self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool) {
match self.find(|attr| attr.is_word() && attr.has_name(word)) {
Some(a) => (Some(a), true),
None => (None, false),
}
}
}

/// A portion of documentation, extracted from a `#[doc]` attribute.
Expand Down
10 changes: 10 additions & 0 deletions src/test/rustdoc-ui/issue-61592-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// aux-build:issue-61592.rs

extern crate foo;

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

fn main() {}
12 changes: 12 additions & 0 deletions src/test/rustdoc-ui/issue-61592-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0780]: anonymous imports cannot be inlined
--> $DIR/issue-61592-2.rs:6:7
|
LL | #[doc(inline)]
| ^^^^^^
LL | #[doc = "baz"]
LL | pub use foo::Foo as _;
| ---------------------- anonymous import

error: aborting due to previous error

For more information about this error, try `rustc --explain E0780`.