Skip to content

Commit 11f3476

Browse files
Enforce whitespace ascii character check for doc alias
1 parent accc26a commit 11f3476

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

compiler/rustc_passes/src/check_attr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,16 @@ impl CheckAttrVisitor<'tcx> {
303303
.emit();
304304
return false;
305305
}
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+
}
306316
if let Some(err) = match target {
307317
Target::Impl => Some("implementation block"),
308318
Target::ForeignMod => Some("extern block"),

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

+2
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ pub struct Bar;
1212
#[doc(alias = "
1313
")] //~^ ERROR
1414
#[doc(alias = "\t")] //~ ERROR
15+
#[doc(alias = " hello")] //~ ERROR
16+
#[doc(alias = "hello ")] //~ ERROR
1517
pub struct Foo;

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,17 @@ error: '\t' character isn't allowed in `#[doc(alias = "...")]`
4242
LL | #[doc(alias = "\t")]
4343
| ^^^^^^^^^^^^
4444

45-
error: aborting due to 7 previous errors
45+
error: `#[doc(alias = "...")]` cannot start or end with ' '
46+
--> $DIR/check-doc-alias-attr.rs:15:7
47+
|
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+
| ^^^^^^^^^^^^^^^^
56+
57+
error: aborting due to 9 previous errors
4658

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

+2
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ pub struct Bar;
1212
#[doc(alias = "
1313
")] //~^ ERROR
1414
#[doc(alias = "\t")] //~ ERROR
15+
#[doc(alias = " hello")] //~ ERROR
16+
#[doc(alias = "hello ")] //~ ERROR
1517
pub struct Foo;

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,17 @@ error: '\t' character isn't allowed in `#[doc(alias = "...")]`
4242
LL | #[doc(alias = "\t")]
4343
| ^^^^^^^^^^^^
4444

45-
error: aborting due to 7 previous errors
45+
error: `#[doc(alias = "...")]` cannot start or end with ' '
46+
--> $DIR/check-doc-alias-attr.rs:15:7
47+
|
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+
| ^^^^^^^^^^^^^^^^
56+
57+
error: aborting due to 9 previous errors
4658

0 commit comments

Comments
 (0)