1- use pulldown_cmark:: { BrokenLink , Event , Options , Parser , Tag } ;
1+ use pulldown_cmark:: { BrokenLink , Event , LinkType , Options , Parser , Tag } ;
22use rustc_ast as ast;
33use rustc_ast:: util:: comments:: beautify_doc_string;
44use rustc_data_structures:: fx:: FxHashMap ;
@@ -347,6 +347,21 @@ fn preprocess_link(link: &str) -> String {
347347 strip_generics_from_path ( link) . unwrap_or_else ( |_| link. to_string ( ) )
348348}
349349
350+ /// Keep inline and reference links `[]`,
351+ /// but skip autolinks `<>` which we never consider to be intra-doc links.
352+ pub fn may_be_doc_link ( link_type : LinkType ) -> bool {
353+ match link_type {
354+ LinkType :: Inline
355+ | LinkType :: Reference
356+ | LinkType :: ReferenceUnknown
357+ | LinkType :: Collapsed
358+ | LinkType :: CollapsedUnknown
359+ | LinkType :: Shortcut
360+ | LinkType :: ShortcutUnknown => true ,
361+ LinkType :: Autolink | LinkType :: Email => false ,
362+ }
363+ }
364+
350365/// Simplified version of `preprocessed_markdown_links` from rustdoc.
351366/// Must return at least the same links as it, but may add some more links on top of that.
352367pub ( crate ) fn attrs_to_preprocessed_links ( attrs : & [ ast:: Attribute ] ) -> Vec < String > {
@@ -359,7 +374,9 @@ pub(crate) fn attrs_to_preprocessed_links(attrs: &[ast::Attribute]) -> Vec<Strin
359374 Some ( & mut |link : BrokenLink < ' _ > | Some ( ( link. reference , "" . into ( ) ) ) ) ,
360375 )
361376 . filter_map ( |event| match event {
362- Event :: Start ( Tag :: Link ( _, dest, _) ) => Some ( preprocess_link ( & dest) ) ,
377+ Event :: Start ( Tag :: Link ( link_type, dest, _) ) if may_be_doc_link ( link_type) => {
378+ Some ( preprocess_link ( & dest) )
379+ }
363380 _ => None ,
364381 } )
365382 . collect ( )
0 commit comments