]> git.lizzy.rs Git - rust.git/commitdiff
Add check for doc alias on associated const in trait impls
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Mon, 24 Aug 2020 18:20:03 +0000 (20:20 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 3 Sep 2020 20:11:29 +0000 (22:11 +0200)
compiler/rustc_passes/src/check_attr.rs

index 832cde86d0b7b1e7d0a21f475c958a810dddfccf..392070839dc2a8eead3676e431de81e48b0ad021 100644 (file)
@@ -250,13 +250,23 @@ fn check_doc_alias(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bo
                                     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();
                         }