Skip to content

Commit 0c217a6

Browse files
committed
Add error code
1 parent f502263 commit 0c217a6

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ E0776: include_str!("./error_codes/E0776.md"),
464464
E0777: include_str!("./error_codes/E0777.md"),
465465
E0778: include_str!("./error_codes/E0778.md"),
466466
E0779: include_str!("./error_codes/E0779.md"),
467+
E0780: include_str!("./error_codes/E0780.md"),
467468
;
468469
// E0006, // merged with E0005
469470
// E0008, // cannot bind by-move into a pattern guard
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Cannot use `doc(inline)` with wildcard imports
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0780
6+
extern crate foo;
7+
8+
#[doc(inline)] // error: invalid doc argument
9+
pub use foo::Foo as _;
10+
```
11+
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.
18+
19+
Example:
20+
21+
```
22+
extern crate foo;
23+
24+
pub use foo::Foo as _;
25+
```

src/librustdoc/clean/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,12 +2157,26 @@ 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);
2161+
let pub_underscore = self.vis.node.is_pub() && self.name == kw::Underscore;
2162+
2163+
if pub_underscore && inlined {
2164+
rustc_errors::struct_span_err!(
2165+
cx.tcx.sess,
2166+
self.attrs.lists(sym::doc).next().unwrap().span(),
2167+
E0780,
2168+
"inline with wildcard import"
2169+
)
2170+
.span_label(self.span, "wildcard import")
2171+
.emit();
2172+
}
2173+
21602174
// We consider inlining the documentation of `pub use` statements, but we
21612175
// forcefully don't inline if this is not public or if the
21622176
// #[doc(no_inline)] attribute is present.
21632177
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
21642178
let mut denied = !self.vis.node.is_pub()
2165-
|| (self.vis.node.is_pub() && self.name == kw::Underscore)
2179+
|| pub_underscore
21662180
|| self.attrs.iter().any(|a| {
21672181
a.has_name(sym::doc)
21682182
&& match a.meta_item_list() {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![crate_name = "foo"]
2+
3+
pub trait Foo {}

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

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

0 commit comments

Comments
 (0)