Skip to content

Commit 35210a6

Browse files
authored
Rollup merge of #77570 - GuillaumeGomez:whitespace-doc-alias, r=jyn514,ollie27
Allow ascii whitespace char for doc aliases Fixes issue from #76705 (comment) cc @lopopolo @ollie27 r? @jyn514
2 parents e160e5c + 11f3476 commit 35210a6

7 files changed

+66
-18
lines changed

compiler/rustc_passes/src/check_attr.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ impl CheckAttrVisitor<'tcx> {
287287
self.doc_alias_str_error(meta);
288288
return false;
289289
}
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 != ' '))
292293
{
293294
self.tcx
294295
.sess
@@ -302,6 +303,16 @@ impl CheckAttrVisitor<'tcx> {
302303
.emit();
303304
return false;
304305
}
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+
}
305316
if let Some(err) = match target {
306317
Target::Impl => Some("implementation block"),
307318
Target::ForeignMod => Some("extern block"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(doc_alias)]
2+
3+
#[doc(alias = "Demon Lord")]
4+
pub struct Struct;

src/test/rustdoc-ui/check-doc-alias-attr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Bar;
1111
#[doc(alias = "\n")] //~ ERROR
1212
#[doc(alias = "
1313
")] //~^ ERROR
14-
#[doc(alias = " ")] //~ ERROR
1514
#[doc(alias = "\t")] //~ ERROR
15+
#[doc(alias = " hello")] //~ ERROR
16+
#[doc(alias = "hello ")] //~ ERROR
1617
pub struct Foo;

src/test/rustdoc-ui/check-doc-alias-attr.stderr

+13-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ LL | #[doc(alias = "
3636
LL | | ")]
3737
| |_^
3838

39-
error: ' ' character isn't allowed in `#[doc(alias = "...")]`
39+
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
4040
--> $DIR/check-doc-alias-attr.rs:14:7
4141
|
42-
LL | #[doc(alias = " ")]
43-
| ^^^^^^^^^^^
42+
LL | #[doc(alias = "\t")]
43+
| ^^^^^^^^^^^^
4444

45-
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
45+
error: `#[doc(alias = "...")]` cannot start or end with ' '
4646
--> $DIR/check-doc-alias-attr.rs:15:7
4747
|
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+
| ^^^^^^^^^^^^^^^^
5056

51-
error: aborting due to 8 previous errors
57+
error: aborting due to 9 previous errors
5258

src/test/ui/check-doc-alias-attr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct Bar;
1111
#[doc(alias = "\n")] //~ ERROR
1212
#[doc(alias = "
1313
")] //~^ ERROR
14-
#[doc(alias = " ")] //~ ERROR
1514
#[doc(alias = "\t")] //~ ERROR
15+
#[doc(alias = " hello")] //~ ERROR
16+
#[doc(alias = "hello ")] //~ ERROR
1617
pub struct Foo;

src/test/ui/check-doc-alias-attr.stderr

+13-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ LL | #[doc(alias = "
3636
LL | | ")]
3737
| |_^
3838

39-
error: ' ' character isn't allowed in `#[doc(alias = "...")]`
39+
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
4040
--> $DIR/check-doc-alias-attr.rs:14:7
4141
|
42-
LL | #[doc(alias = " ")]
43-
| ^^^^^^^^^^^
42+
LL | #[doc(alias = "\t")]
43+
| ^^^^^^^^^^^^
4444

45-
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
45+
error: `#[doc(alias = "...")]` cannot start or end with ' '
4646
--> $DIR/check-doc-alias-attr.rs:15:7
4747
|
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+
| ^^^^^^^^^^^^^^^^
5056

51-
error: aborting due to 8 previous errors
57+
error: aborting due to 9 previous errors
5258

0 commit comments

Comments
 (0)