File tree Expand file tree Collapse file tree 5 files changed +43
-15
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 5 files changed +43
-15
lines changed Original file line number Diff line number Diff line change 1
- Cannot use ` doc(inline) ` with wildcard imports
1
+ Cannot use ` doc(inline) ` with anonymous imports
2
2
3
3
Erroneous code example:
4
4
5
- ``` compile_fail,E0780
5
+ ``` compile_fail,E0780,edition2018
6
6
extern crate foo;
7
7
8
8
#[doc(inline)] // error: invalid doc argument
9
9
pub use foo::Foo as _;
10
10
```
11
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.
12
+ Anonymous imports are always rendered with ` #[doc(no_inline)] ` . To fix this
13
+ error, remove the ` #[doc(inline)] ` attribute.
18
14
19
15
Example:
20
16
21
- ```
17
+ ``` ignore (cannot-doctest-multicrate-project)
22
18
extern crate foo;
23
19
24
20
pub use foo::Foo as _;
Original file line number Diff line number Diff line change @@ -2157,17 +2157,17 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
2157
2157
return Vec :: new ( ) ;
2158
2158
}
2159
2159
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) ;
2161
2161
let pub_underscore = self . vis . node . is_pub ( ) && self . name == kw:: Underscore ;
2162
2162
2163
2163
if pub_underscore && inlined {
2164
2164
rustc_errors:: struct_span_err!(
2165
2165
cx. tcx. sess,
2166
- self . attrs . lists ( sym :: doc ) . next ( ) . unwrap( ) . span( ) ,
2166
+ doc_meta_item . unwrap( ) . span( ) ,
2167
2167
E0780 ,
2168
- "inline with wildcard import "
2168
+ "anonymous imports cannot be inlined "
2169
2169
)
2170
- . span_label ( self . span , "wildcard import" )
2170
+ . span_label ( self . span , "anonymous import" )
2171
2171
. emit ( ) ;
2172
2172
}
2173
2173
@@ -2189,7 +2189,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
2189
2189
} ) ;
2190
2190
// Also check whether imports were asked to be inlined, in case we're trying to re-export a
2191
2191
// crate in Rust 2018+
2192
- let please_inline = self . attrs . lists ( sym :: doc ) . has_word ( sym :: inline ) ;
2192
+ let please_inline = inlined ;
2193
2193
let path = self . path . clean ( cx) ;
2194
2194
let inner = if self . glob {
2195
2195
if !denied {
Original file line number Diff line number Diff line change @@ -431,12 +431,22 @@ impl AttributesExt for [ast::Attribute] {
431
431
crate trait NestedAttributesExt {
432
432
/// Returns `true` if the attribute list contains a specific `Word`
433
433
fn has_word ( self , word : Symbol ) -> bool ;
434
+ fn get_word_attr ( self , word : Symbol ) -> ( Option < ast:: NestedMetaItem > , bool ) ;
434
435
}
435
436
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
+ {
437
440
fn has_word ( self , word : Symbol ) -> bool {
438
441
self . into_iter ( ) . any ( |attr| attr. is_word ( ) && attr. has_name ( word) )
439
442
}
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
+ }
440
450
}
441
451
442
452
/// A portion of documentation, extracted from a `#[doc]` attribute.
Original file line number Diff line number Diff line change
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 ( ) { }
Original file line number Diff line number Diff line change
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`.
You can’t perform that action at this time.
0 commit comments