Skip to content

Commit b3b74a9

Browse files
committed
Refactor
1 parent d261176 commit b3b74a9

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

compiler/rustc_error_codes/src/error_codes/E0780.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
Cannot use `doc(inline)` with wildcard imports
1+
Cannot use `doc(inline)` with anonymous imports
22

33
Erroneous code example:
44

5-
```compile_fail,E0780
5+
```compile_fail,E0780,edition2018
66
extern crate foo;
77
88
#[doc(inline)] // error: invalid doc argument
99
pub use foo::Foo as _;
1010
```
1111

12-
When using a wildcard import the `doc` attribute currently only supports:
13-
14-
* hidden
15-
16-
To fix this error either change to one of the available arguments or remove the
17-
`doc` attribute.
12+
Anonymous imports are always rendered with `#[doc(no_inline)]`. To fix this
13+
error, remove the `#[doc(inline)]` attribute.
1814

1915
Example:
2016

21-
```
17+
```ignore (cannot-doctest-multicrate-project)
2218
extern crate foo;
2319
2420
pub use foo::Foo as _;

src/librustdoc/clean/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,17 +2157,17 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
21572157
return Vec::new();
21582158
}
21592159

2160-
let inlined = self.attrs.lists(sym::doc).has_word(sym::inline);
2160+
let (doc_meta_item, inlined) = self.attrs.lists(sym::doc).get_word_attr(sym::inline);
21612161
let pub_underscore = self.vis.node.is_pub() && self.name == kw::Underscore;
21622162

21632163
if pub_underscore && inlined {
21642164
rustc_errors::struct_span_err!(
21652165
cx.tcx.sess,
2166-
self.attrs.lists(sym::doc).next().unwrap().span(),
2166+
doc_meta_item.unwrap().span(),
21672167
E0780,
2168-
"inline with wildcard import"
2168+
"anonymous imports cannot be inlined"
21692169
)
2170-
.span_label(self.span, "wildcard import")
2170+
.span_label(self.span, "anonymous import")
21712171
.emit();
21722172
}
21732173

@@ -2189,7 +2189,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
21892189
});
21902190
// Also check whether imports were asked to be inlined, in case we're trying to re-export a
21912191
// crate in Rust 2018+
2192-
let please_inline = self.attrs.lists(sym::doc).has_word(sym::inline);
2192+
let please_inline = inlined;
21932193
let path = self.path.clean(cx);
21942194
let inner = if self.glob {
21952195
if !denied {

src/librustdoc/clean/types.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,22 @@ impl AttributesExt for [ast::Attribute] {
431431
crate trait NestedAttributesExt {
432432
/// Returns `true` if the attribute list contains a specific `Word`
433433
fn has_word(self, word: Symbol) -> bool;
434+
fn get_word_attr(self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool);
434435
}
435436

436-
impl<I: IntoIterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
437+
impl<I: Iterator<Item = ast::NestedMetaItem> + IntoIterator<Item = ast::NestedMetaItem>>
438+
NestedAttributesExt for I
439+
{
437440
fn has_word(self, word: Symbol) -> bool {
438441
self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
439442
}
443+
444+
fn get_word_attr(mut self, word: Symbol) -> (Option<ast::NestedMetaItem>, bool) {
445+
match self.find(|attr| attr.is_word() && attr.has_name(word)) {
446+
Some(a) => (Some(a), true),
447+
None => (None, false),
448+
}
449+
}
440450
}
441451

442452
/// A portion of documentation, extracted from a `#[doc]` attribute.

src/test/rustdoc-ui/issue-61592-2.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-build:issue-61592.rs
2+
3+
extern crate foo;
4+
5+
#[doc = "bar"]
6+
#[doc(inline)] //~ ERROR
7+
#[doc = "baz"]
8+
pub use foo::Foo as _;
9+
10+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0780]: anonymous imports cannot be inlined
2+
--> $DIR/issue-61592-2.rs:6:7
3+
|
4+
LL | #[doc(inline)]
5+
| ^^^^^^
6+
LL | #[doc = "baz"]
7+
LL | pub use foo::Foo as _;
8+
| ---------------------- anonymous import
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0780`.

0 commit comments

Comments
 (0)