mirror of https://github.com/rust-lang/rust.git
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:
commit
35210a66ed
|
@ -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"),
|
||||
|
|
|
@ -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
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
|
@ -0,0 +1,4 @@
|
|||
#![feature(doc_alias)]
|
||||
|
||||
#[doc(alias = "Demon Lord")]
|
||||
pub struct Struct;
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue