diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-01-04 15:05:36 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2021-01-04 15:05:36 +0100 |
| commit | c4c010f5348f215adf98f4ca0ae66c4f999943dd (patch) | |
| tree | 57a2286d5e043ee97a822596b2cc60374023ecd0 | |
| parent | 887398ff688e2e3cf8a95e588d0b51420e08fb6b (diff) | |
| download | rust-c4c010f5348f215adf98f4ca0ae66c4f999943dd.tar.gz rust-c4c010f5348f215adf98f4ca0ae66c4f999943dd.zip | |
Add an error in case the doc alias is the same as the item it's aliasing
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index aeaa862f5fd..420c002c5fc 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -310,7 +310,7 @@ impl CheckAttrVisitor<'tcx> { .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 @@ impl CheckAttrVisitor<'tcx> { .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 } |
