Skip to content

Commit

Permalink
Enforce whitespace ascii character check for doc alias
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 6, 2020
1 parent accc26a commit 11f3476
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ impl CheckAttrVisitor<'tcx> {
.emit();
return false;
}
if doc_alias.starts_with(' ') || doc_alias.ends_with(' ') {
self.tcx
.sess
.struct_span_err(
meta.span(),
"`#[doc(alias = \"...\")]` cannot start or end with ' '",
)
.emit();
return false;
}
if let Some(err) = match target {
Target::Impl => Some("implementation block"),
Target::ForeignMod => Some("extern block"),
Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc-ui/check-doc-alias-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ pub struct Bar;
#[doc(alias = "
")] //~^ ERROR
#[doc(alias = "\t")] //~ ERROR
#[doc(alias = " hello")] //~ ERROR
#[doc(alias = "hello ")] //~ ERROR
pub struct Foo;
14 changes: 13 additions & 1 deletion src/test/rustdoc-ui/check-doc-alias-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ error: '\t' character isn't allowed in `#[doc(alias = "...")]`
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^

error: aborting due to 7 previous errors
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:15:7
|
LL | #[doc(alias = " hello")]
| ^^^^^^^^^^^^^^^^

error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:16:7
|
LL | #[doc(alias = "hello ")]
| ^^^^^^^^^^^^^^^^

error: aborting due to 9 previous errors

2 changes: 2 additions & 0 deletions src/test/ui/check-doc-alias-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ pub struct Bar;
#[doc(alias = "
")] //~^ ERROR
#[doc(alias = "\t")] //~ ERROR
#[doc(alias = " hello")] //~ ERROR
#[doc(alias = "hello ")] //~ ERROR
pub struct Foo;
14 changes: 13 additions & 1 deletion src/test/ui/check-doc-alias-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,17 @@ error: '\t' character isn't allowed in `#[doc(alias = "...")]`
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^

error: aborting due to 7 previous errors
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:15:7
|
LL | #[doc(alias = " hello")]
| ^^^^^^^^^^^^^^^^

error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:16:7
|
LL | #[doc(alias = "hello ")]
| ^^^^^^^^^^^^^^^^

error: aborting due to 9 previous errors

0 comments on commit 11f3476

Please sign in to comment.