about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-08-24 20:20:03 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2020-09-03 22:11:29 +0200
commit6e43ff5ceafb2674af709f09e72c4f1f53eecf22 (patch)
tree0a0e7dc5db8bd715afa3737a4a977cb8cb495251
parent6c44bcc4ffeb0ee8059c2c167388c69dedf1ea44 (diff)
downloadrust-6e43ff5ceafb2674af709f09e72c4f1f53eecf22.tar.gz
rust-6e43ff5ceafb2674af709f09e72c4f1f53eecf22.zip
Add check for doc alias on associated const in trait impls
-rw-r--r--compiler/rustc_passes/src/check_attr.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 832cde86d0b..392070839dc 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -250,13 +250,23 @@ impl CheckAttrVisitor<'tcx> {
                                     None
                                 }
                             }
+                            Target::AssocConst => {
+                                let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
+                                let containing_item = self.tcx.hir().expect_item(parent_hir_id);
+                                // We can't link to trait impl's consts.
+                                let err = "associated constant in trait implementation block";
+                                match containing_item.kind {
+                                    ItemKind::Impl { of_trait: Some(_), .. } => Some(err),
+                                    _ => None,
+                                }
+                            }
                             _ => None,
                         } {
                             self.tcx
                                 .sess
                                 .struct_span_err(
                                     meta.span(),
-                                    &format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err,),
+                                    &format!("`#[doc(alias = \"...\")]` isn't allowed on {}", err),
                                 )
                                 .emit();
                         }