]> git.lizzy.rs Git - rust.git/commitdiff
Enforce whitespace ascii character check for doc alias
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 6 Oct 2020 12:29:42 +0000 (14:29 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Tue, 6 Oct 2020 12:29:42 +0000 (14:29 +0200)
compiler/rustc_passes/src/check_attr.rs
src/test/rustdoc-ui/check-doc-alias-attr.rs
src/test/rustdoc-ui/check-doc-alias-attr.stderr
src/test/ui/check-doc-alias-attr.rs
src/test/ui/check-doc-alias-attr.stderr

index e8e54c3cfaac04e96ded8015d617403de8a0f179..1acaa4c6eff5d60e22cc53fe0ccc050ba81c481e 100644 (file)
@@ -303,6 +303,16 @@ fn check_doc_alias(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bo
                                 .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"),
index d55be9f120ca95c7f03a9c0a4dc7ac295f850c8e..0ca2349a43b0fdefdb9e7680fea465b2b283de1f 100644 (file)
@@ -12,4 +12,6 @@
 #[doc(alias = "
 ")] //~^ ERROR
 #[doc(alias = "\t")] //~ ERROR
+#[doc(alias = " hello")] //~ ERROR
+#[doc(alias = "hello ")] //~ ERROR
 pub struct Foo;
index 97444c69ff1d1885f4542d51dd9387fda388f7f5..2c417a3bb65b5a82bd3a0d896123a2b1b4b90d47 100644 (file)
@@ -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
 
index d55be9f120ca95c7f03a9c0a4dc7ac295f850c8e..0ca2349a43b0fdefdb9e7680fea465b2b283de1f 100644 (file)
@@ -12,4 +12,6 @@
 #[doc(alias = "
 ")] //~^ ERROR
 #[doc(alias = "\t")] //~ ERROR
+#[doc(alias = " hello")] //~ ERROR
+#[doc(alias = "hello ")] //~ ERROR
 pub struct Foo;
index 97444c69ff1d1885f4542d51dd9387fda388f7f5..2c417a3bb65b5a82bd3a0d896123a2b1b4b90d47 100644 (file)
@@ -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