Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ascii whitespace char for doc aliases #77570

Merged
merged 3 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 != ' '))
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
{
self.tcx
.sess
Expand All @@ -302,6 +303,16 @@ impl CheckAttrVisitor<'tcx> {
.emit();
return false;
}
if doc_alias.starts_with(' ') || doc_alias.ends_with(' ') {
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
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