File tree 7 files changed +66
-18
lines changed
compiler/rustc_passes/src
7 files changed +66
-18
lines changed Original file line number Diff line number Diff line change @@ -287,8 +287,9 @@ impl CheckAttrVisitor<'tcx> {
287
287
self . doc_alias_str_error ( meta) ;
288
288
return false ;
289
289
}
290
- if let Some ( c) =
291
- doc_alias. chars ( ) . find ( |& c| c == '"' || c == '\'' || c. is_whitespace ( ) )
290
+ if let Some ( c) = doc_alias
291
+ . chars ( )
292
+ . find ( |& c| c == '"' || c == '\'' || ( c. is_whitespace ( ) && c != ' ' ) )
292
293
{
293
294
self . tcx
294
295
. sess
@@ -302,6 +303,16 @@ impl CheckAttrVisitor<'tcx> {
302
303
. emit ( ) ;
303
304
return false ;
304
305
}
306
+ if doc_alias. starts_with ( ' ' ) || doc_alias. ends_with ( ' ' ) {
307
+ self . tcx
308
+ . sess
309
+ . struct_span_err (
310
+ meta. span ( ) ,
311
+ "`#[doc(alias = \" ...\" )]` cannot start or end with ' '" ,
312
+ )
313
+ . emit ( ) ;
314
+ return false ;
315
+ }
305
316
if let Some ( err) = match target {
306
317
Target :: Impl => Some ( "implementation block" ) ,
307
318
Target :: ForeignMod => Some ( "extern block" ) ,
Original file line number Diff line number Diff line change
1
+ // exact-check
2
+
3
+ const QUERY = [
4
+ 'Demon Lord' ,
5
+ ] ;
6
+
7
+ const EXPECTED = [
8
+ {
9
+ 'others' : [
10
+ {
11
+ 'path' : 'doc_alias_whitespace' ,
12
+ 'name' : 'Struct' ,
13
+ 'alias' : 'Demon Lord' ,
14
+ 'href' : '../doc_alias_whitespace/struct.Struct.html' ,
15
+ 'is_alias' : true
16
+ } ,
17
+ ] ,
18
+ } ,
19
+ ] ;
Original file line number Diff line number Diff line change
1
+ #![ feature( doc_alias) ]
2
+
3
+ #[ doc( alias = "Demon Lord" ) ]
4
+ pub struct Struct ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ pub struct Bar;
11
11
#[ doc( alias = "\n " ) ] //~ ERROR
12
12
#[ doc( alias = "
13
13
" ) ] //~^ ERROR
14
- #[ doc( alias = " " ) ] //~ ERROR
15
14
#[ doc( alias = "\t " ) ] //~ ERROR
15
+ #[ doc( alias = " hello" ) ] //~ ERROR
16
+ #[ doc( alias = "hello " ) ] //~ ERROR
16
17
pub struct Foo ;
Original file line number Diff line number Diff line change @@ -36,17 +36,23 @@ LL | #[doc(alias = "
36
36
LL | | ")]
37
37
| |_^
38
38
39
- error: ' ' character isn't allowed in `#[doc(alias = "...")]`
39
+ error: '\t ' character isn't allowed in `#[doc(alias = "...")]`
40
40
--> $DIR/check-doc-alias-attr.rs:14:7
41
41
|
42
- LL | #[doc(alias = " ")]
43
- | ^^^^^^^^^^^
42
+ LL | #[doc(alias = "\t ")]
43
+ | ^^^^^^^^^^^^
44
44
45
- error: '\t' character isn't allowed in `#[doc(alias = "...")]`
45
+ error: `#[doc(alias = "...")]` cannot start or end with ' '
46
46
--> $DIR/check-doc-alias-attr.rs:15:7
47
47
|
48
- LL | #[doc(alias = "\t")]
49
- | ^^^^^^^^^^^^
48
+ LL | #[doc(alias = " hello")]
49
+ | ^^^^^^^^^^^^^^^^
50
+
51
+ error: `#[doc(alias = "...")]` cannot start or end with ' '
52
+ --> $DIR/check-doc-alias-attr.rs:16:7
53
+ |
54
+ LL | #[doc(alias = "hello ")]
55
+ | ^^^^^^^^^^^^^^^^
50
56
51
- error: aborting due to 8 previous errors
57
+ error: aborting due to 9 previous errors
52
58
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ pub struct Bar;
11
11
#[ doc( alias = "\n " ) ] //~ ERROR
12
12
#[ doc( alias = "
13
13
" ) ] //~^ ERROR
14
- #[ doc( alias = " " ) ] //~ ERROR
15
14
#[ doc( alias = "\t " ) ] //~ ERROR
15
+ #[ doc( alias = " hello" ) ] //~ ERROR
16
+ #[ doc( alias = "hello " ) ] //~ ERROR
16
17
pub struct Foo ;
Original file line number Diff line number Diff line change @@ -36,17 +36,23 @@ LL | #[doc(alias = "
36
36
LL | | ")]
37
37
| |_^
38
38
39
- error: ' ' character isn't allowed in `#[doc(alias = "...")]`
39
+ error: '\t ' character isn't allowed in `#[doc(alias = "...")]`
40
40
--> $DIR/check-doc-alias-attr.rs:14:7
41
41
|
42
- LL | #[doc(alias = " ")]
43
- | ^^^^^^^^^^^
42
+ LL | #[doc(alias = "\t ")]
43
+ | ^^^^^^^^^^^^
44
44
45
- error: '\t' character isn't allowed in `#[doc(alias = "...")]`
45
+ error: `#[doc(alias = "...")]` cannot start or end with ' '
46
46
--> $DIR/check-doc-alias-attr.rs:15:7
47
47
|
48
- LL | #[doc(alias = "\t")]
49
- | ^^^^^^^^^^^^
48
+ LL | #[doc(alias = " hello")]
49
+ | ^^^^^^^^^^^^^^^^
50
+
51
+ error: `#[doc(alias = "...")]` cannot start or end with ' '
52
+ --> $DIR/check-doc-alias-attr.rs:16:7
53
+ |
54
+ LL | #[doc(alias = "hello ")]
55
+ | ^^^^^^^^^^^^^^^^
50
56
51
- error: aborting due to 8 previous errors
57
+ error: aborting due to 9 previous errors
52
58
You can’t perform that action at this time.
0 commit comments