1
- use pulldown_cmark:: { BrokenLink , Event , Options , Parser , Tag } ;
1
+ use pulldown_cmark:: { BrokenLink , Event , LinkType , Options , Parser , Tag } ;
2
2
use rustc_ast as ast;
3
3
use rustc_ast:: util:: comments:: beautify_doc_string;
4
4
use rustc_data_structures:: fx:: FxHashMap ;
@@ -347,6 +347,21 @@ fn preprocess_link(link: &str) -> String {
347
347
strip_generics_from_path ( link) . unwrap_or_else ( |_| link. to_string ( ) )
348
348
}
349
349
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
+
350
365
/// Simplified version of `preprocessed_markdown_links` from rustdoc.
351
366
/// Must return at least the same links as it, but may add some more links on top of that.
352
367
pub ( 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
359
374
Some ( & mut |link : BrokenLink < ' _ > | Some ( ( link. reference , "" . into ( ) ) ) ) ,
360
375
)
361
376
. 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
+ }
363
380
_ => None ,
364
381
} )
365
382
. collect ( )
0 commit comments