Rollup merge of #77570 - GuillaumeGomez:whitespace-doc-alias, r=jyn514,ollie27

Allow ascii whitespace char for doc aliases

Fixes issue from https://github.com/rust-lang/rust/issues/76705#issuecomment-703123847

cc @lopopolo @ollie27

r? @jyn514
This commit is contained in:
Yuki Okushi 2020-10-15 07:32:27 +09:00 committed by GitHub
commit 35210a66ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 20 deletions

View File

@ -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
@ -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"),

View File

@ -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
},
],
},
];

View File

@ -0,0 +1,4 @@
#![feature(doc_alias)]
#[doc(alias = "Demon Lord")]
pub struct Struct;

View File

@ -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;

View File

@ -36,17 +36,23 @@ LL | #[doc(alias = "
LL | | ")]
| |_^
error: ' ' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:14:7
|
LL | #[doc(alias = " ")]
| ^^^^^^^^^^^
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:15:7
--> $DIR/check-doc-alias-attr.rs:14:7
|
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^
error: aborting due to 8 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

View File

@ -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;

View File

@ -36,17 +36,23 @@ LL | #[doc(alias = "
LL | | ")]
| |_^
error: ' ' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:14:7
|
LL | #[doc(alias = " ")]
| ^^^^^^^^^^^
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:15:7
--> $DIR/check-doc-alias-attr.rs:14:7
|
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^
error: aborting due to 8 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