Improve some attributes error spans

This commit is contained in:
Guillaume Gomez 2020-11-28 17:53:20 +01:00
parent 7df0052df8
commit 63816da5ed
6 changed files with 33 additions and 31 deletions

View File

@ -182,7 +182,9 @@ impl Attribute {
pub fn name_value_literal_span(&self) -> Option<Span> {
match self.kind {
AttrKind::Normal(ref item, _) => item.meta(self.span).and_then(|meta| meta.name_value_literal_span()),
AttrKind::Normal(ref item, _) => {
item.meta(self.span).and_then(|meta| meta.name_value_literal_span())
}
AttrKind::DocComment(..) => None,
}
}

View File

@ -319,7 +319,7 @@ impl CheckAttrVisitor<'tcx> {
self.tcx
.sess
.struct_span_err(
meta.span(),
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
&format!(
"{:?} character isn't allowed in `#[doc(alias = \"...\")]`",
c,
@ -332,7 +332,7 @@ impl CheckAttrVisitor<'tcx> {
self.tcx
.sess
.struct_span_err(
meta.span(),
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
"`#[doc(alias = \"...\")]` cannot start or end with ' '",
)
.emit();

View File

@ -17,42 +17,42 @@ LL | #[doc(alias("bar"))]
| ^^^^^^^^^^^^
error: '\"' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:9:7
--> $DIR/check-doc-alias-attr.rs:9:15
|
LL | #[doc(alias = "\"")]
| ^^^^^^^^^^^^
| ^^^^
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:10:7
--> $DIR/check-doc-alias-attr.rs:10:15
|
LL | #[doc(alias = "\n")]
| ^^^^^^^^^^^^
| ^^^^
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:11:7
--> $DIR/check-doc-alias-attr.rs:11:15
|
LL | #[doc(alias = "
| _______^
| _______________^
LL | | ")]
| |_^
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:13:7
--> $DIR/check-doc-alias-attr.rs:13:15
|
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^
| ^^^^
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:14:7
--> $DIR/check-doc-alias-attr.rs:14:15
|
LL | #[doc(alias = " hello")]
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:15:7
--> $DIR/check-doc-alias-attr.rs:15:15
|
LL | #[doc(alias = "hello ")]
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^
error: aborting due to 9 previous errors

View File

@ -1,8 +1,8 @@
error: '\'' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/doc-alias-crate-level.rs:5:7
--> $DIR/doc-alias-crate-level.rs:5:15
|
LL | #[doc(alias = "shouldn't work!")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^
error: `#![doc(alias = "...")]` isn't allowed as a crate level attribute
--> $DIR/doc-alias-crate-level.rs:3:8

View File

@ -17,42 +17,42 @@ LL | #[doc(alias("bar"))]
| ^^^^^^^^^^^^
error: '\"' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:10:7
--> $DIR/check-doc-alias-attr.rs:10:15
|
LL | #[doc(alias = "\"")]
| ^^^^^^^^^^^^
| ^^^^
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:11:7
--> $DIR/check-doc-alias-attr.rs:11:15
|
LL | #[doc(alias = "\n")]
| ^^^^^^^^^^^^
| ^^^^
error: '\n' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:12:7
--> $DIR/check-doc-alias-attr.rs:12:15
|
LL | #[doc(alias = "
| _______^
| _______________^
LL | | ")]
| |_^
error: '\t' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/check-doc-alias-attr.rs:14:7
--> $DIR/check-doc-alias-attr.rs:14:15
|
LL | #[doc(alias = "\t")]
| ^^^^^^^^^^^^
| ^^^^
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:15:7
--> $DIR/check-doc-alias-attr.rs:15:15
|
LL | #[doc(alias = " hello")]
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^
error: `#[doc(alias = "...")]` cannot start or end with ' '
--> $DIR/check-doc-alias-attr.rs:16:7
--> $DIR/check-doc-alias-attr.rs:16:15
|
LL | #[doc(alias = "hello ")]
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^
error: aborting due to 9 previous errors

View File

@ -1,8 +1,8 @@
error: '\'' character isn't allowed in `#[doc(alias = "...")]`
--> $DIR/doc-alias-crate-level.rs:7:8
--> $DIR/doc-alias-crate-level.rs:7:16
|
LL | #![doc(alias = "shouldn't work!")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^
error: aborting due to previous error