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
22
33Erroneous code example:
44
5- ``` compile_fail,E0780
5+ ``` compile_fail,E0780,edition2018
66extern crate foo;
77
88#[doc(inline)] // error: invalid doc argument
99pub 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
1915Example:
2016
21- ```
17+ ``` ignore (cannot-doctest-multicrate-project)
2218extern crate foo;
2319
2420pub 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<'_> {
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 {
Original file line number Diff line number Diff line change @@ -431,12 +431,22 @@ impl AttributesExt for [ast::Attribute] {
431431crate 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.
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