Auto merge of #80686 - GuillaumeGomez:error-doc-alias-same-name, r=jyn514
Error when #[doc(alias)] has same name as the item Something I came across when reviewing some doc alias PRs. r? `@jyn514`
This commit is contained in:
commit
f4b9d32ef5
@ -310,7 +310,7 @@ fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target)
|
||||
.sess
|
||||
.struct_span_err(
|
||||
meta.name_value_literal_span().unwrap_or_else(|| meta.span()),
|
||||
&format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c,),
|
||||
&format!("{:?} character isn't allowed in `#[doc(alias = \"...\")]`", c),
|
||||
)
|
||||
.emit();
|
||||
return false;
|
||||
@ -358,6 +358,17 @@ fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target)
|
||||
.emit();
|
||||
return false;
|
||||
}
|
||||
let item_name = self.tcx.hir().name(hir_id);
|
||||
if item_name.to_string() == doc_alias {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(
|
||||
meta.span(),
|
||||
&format!("`#[doc(alias = \"...\")]` is the same as the item's name"),
|
||||
)
|
||||
.emit();
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
4
src/test/rustdoc-ui/doc-alias-same-name.rs
Normal file
4
src/test/rustdoc-ui/doc-alias-same-name.rs
Normal file
@ -0,0 +1,4 @@
|
||||
#![crate_type = "lib"]
|
||||
|
||||
#[doc(alias = "Foo")] //~ ERROR
|
||||
pub struct Foo;
|
8
src/test/rustdoc-ui/doc-alias-same-name.stderr
Normal file
8
src/test/rustdoc-ui/doc-alias-same-name.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: `#[doc(alias = "...")]` is the same as the item's name
|
||||
--> $DIR/doc-alias-same-name.rs:3:7
|
||||
|
|
||||
LL | #[doc(alias = "Foo")]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
4
src/test/ui/doc-alias-same-name.rs
Normal file
4
src/test/ui/doc-alias-same-name.rs
Normal file
@ -0,0 +1,4 @@
|
||||
#![crate_type = "lib"]
|
||||
|
||||
#[doc(alias = "Foo")] //~ ERROR
|
||||
pub struct Foo;
|
8
src/test/ui/doc-alias-same-name.stderr
Normal file
8
src/test/ui/doc-alias-same-name.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: `#[doc(alias = "...")]` is the same as the item's name
|
||||
--> $DIR/doc-alias-same-name.rs:3:7
|
||||
|
|
||||
LL | #[doc(alias = "Foo")]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user