diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-07-06 16:11:12 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-08-11 23:21:05 +0200 |
| commit | 213dc41fe7e9e4ab56a58d7048deaa658015bc44 (patch) | |
| tree | f7d9e15d667900010007d05260c3683b337556ee | |
| parent | 441fd2255763c2aeea616aeac61b2c795a4c5330 (diff) | |
| download | rust-213dc41fe7e9e4ab56a58d7048deaa658015bc44.tar.gz rust-213dc41fe7e9e4ab56a58d7048deaa658015bc44.zip | |
Add checks for doc alias on which item it's used
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index cf57ffd0b4b..e1a84e99836 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -31,6 +31,27 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<String> { std::iter::once(crate_name).chain(relative).collect() } +fn check_doc_alias_attrs( + attrs: &[ast::Attribute], + item_kind: &str, + diagnostic: &::rustc_errors::Handler, +) { + for attr in attrs { + if let Some(attr) = attr.meta() { + if let Some(list) = attr.meta_item_list() { + for meta in list { + if meta.check_name(sym::alias) { + diagnostic.span_err( + meta.span(), + &format!("`#[doc(alias = \"...\")]` isn't allowed on {}", item_kind), + ); + } + } + } + } + } +} + // Also, is there some reason that this doesn't use the 'visit' // framework from syntax?. @@ -387,6 +408,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { match item.kind { hir::ItemKind::ForeignMod(ref fm) => { + check_doc_alias_attrs(&item.attrs, "extern block", self.cx.sess().diagnostic()); for item in fm.items { self.visit_foreign_item(item, None, om); } @@ -561,6 +583,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { self_ty, ref items, } => { + check_doc_alias_attrs( + &item.attrs, + "implementation block", + self.cx.sess().diagnostic(), + ); // Don't duplicate impls when inlining or if it's implementing a trait, we'll pick // them up regardless of where they're located. if !self.inlining && of_trait.is_none() { |
