Skip to content

Commit

Permalink
Rollup merge of #77570 - GuillaumeGomez:whitespace-doc-alias, r=jyn51…
Browse files Browse the repository at this point in the history
…4,ollie27

Allow ascii whitespace char for doc aliases

Fixes issue from #76705 (comment)

cc @lopopolo @ollie27

r? @jyn514
  • Loading branch information
JohnTitor authored Oct 14, 2020
2 parents e160e5c + 11f3476 commit 35210a6
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 18 deletions.
15 changes: 13 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ impl CheckAttrVisitor<'tcx> {
self.doc_alias_str_error(meta);
return false;
}
if let Some(c) =
doc_alias.chars().find(|&c| c == '"' || c == '\'' || c.is_whitespace())
if let Some(c) = doc_alias
.chars()
.find(|&c| c == '"' || c == '\'' || (c.is_whitespace() && c != ' '))
{
self.tcx
.sess
Expand All @@ -302,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
19 changes: 19 additions & 0 deletions src/test/rustdoc-js/doc-alias-whitespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// exact-check

const QUERY = [
'Demon Lord',
];

const EXPECTED = [
{
'others': [
{
'path': 'doc_alias_whitespace',
'name': 'Struct',
'alias': 'Demon Lord',
'href': '../doc_alias_whitespace/struct.Struct.html',
'is_alias': true
},
],
},
];
4 changes: 4 additions & 0 deletions src/test/rustdoc-js/doc-alias-whitespace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![feature(doc_alias)]

#[doc(alias = "Demon Lord")]
pub struct Struct;
3 changes: 2 additions & 1 deletion src/test/rustdoc-ui/check-doc-alias-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Bar;
#[doc(alias = "\n")] //~ ERROR
#[doc(alias = "
")] //~^ ERROR
#[doc(alias = " ")] //~ ERROR
#[doc(alias = "\t")] //~ ERROR
#[doc(alias = " hello")] //~ ERROR
#[doc(alias = "hello ")] //~ ERROR
pub struct Foo;
20 changes: 13 additions & 7 deletions src/test/rustdoc-ui/check-doc-alias-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@ LL | #[doc(alias = "
LL | | ")]
| |_^

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

error: '\t' character isn't allowed in `#[doc(alias = "...")]`
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:15:7
|
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^
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 8 previous errors
error: aborting due to 9 previous errors

3 changes: 2 additions & 1 deletion src/test/ui/check-doc-alias-attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Bar;
#[doc(alias = "\n")] //~ ERROR
#[doc(alias = "
")] //~^ ERROR
#[doc(alias = " ")] //~ ERROR
#[doc(alias = "\t")] //~ ERROR
#[doc(alias = " hello")] //~ ERROR
#[doc(alias = "hello ")] //~ ERROR
pub struct Foo;
20 changes: 13 additions & 7 deletions src/test/ui/check-doc-alias-attr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@ LL | #[doc(alias = "
LL | | ")]
| |_^

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

error: '\t' character isn't allowed in `#[doc(alias = "...")]`
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:15:7
|
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^
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 8 previous errors
error: aborting due to 9 previous errors

0 comments on commit 35210a6

Please sign in to comment.