@@ -27,7 +27,6 @@ use rustc_session::lint;
27
27
use rustc_span:: edition:: Edition ;
28
28
use rustc_span:: Span ;
29
29
use std:: borrow:: Cow ;
30
- use std:: cell:: RefCell ;
31
30
use std:: collections:: VecDeque ;
32
31
use std:: default:: Default ;
33
32
use std:: fmt:: Write ;
@@ -39,7 +38,7 @@ use crate::doctest;
39
38
use crate :: html:: highlight;
40
39
use crate :: html:: toc:: TocBuilder ;
41
40
42
- use pulldown_cmark:: { html, CodeBlockKind , CowStr , Event , Options , Parser , Tag } ;
41
+ use pulldown_cmark:: { html, BrokenLink , CodeBlockKind , CowStr , Event , Options , Parser , Tag } ;
43
42
44
43
#[ cfg( test) ]
45
44
mod tests;
@@ -931,15 +930,17 @@ impl Markdown<'_> {
931
930
if md. is_empty ( ) {
932
931
return String :: new ( ) ;
933
932
}
934
- let replacer = |_: & str , s : & str | {
935
- if let Some ( link) = links. iter ( ) . find ( |link| & * link. original_text == s) {
936
- Some ( ( link. href . clone ( ) , link. new_text . clone ( ) ) )
933
+ let mut replacer = |broken_link : BrokenLink < ' _ > | {
934
+ if let Some ( link) =
935
+ links. iter ( ) . find ( |link| & * link. original_text == broken_link. reference )
936
+ {
937
+ Some ( ( link. href . as_str ( ) . into ( ) , link. new_text . as_str ( ) . into ( ) ) )
937
938
} else {
938
939
None
939
940
}
940
941
} ;
941
942
942
- let p = Parser :: new_with_broken_link_callback ( md, opts ( ) , Some ( & replacer) ) ;
943
+ let p = Parser :: new_with_broken_link_callback ( md, opts ( ) , Some ( & mut replacer) ) ;
943
944
944
945
let mut s = String :: with_capacity ( md. len ( ) * 3 / 2 ) ;
945
946
@@ -1009,9 +1010,11 @@ impl MarkdownSummaryLine<'_> {
1009
1010
return String :: new ( ) ;
1010
1011
}
1011
1012
1012
- let replacer = |_: & str , s : & str | {
1013
- if let Some ( link) = links. iter ( ) . find ( |link| & * link. original_text == s) {
1014
- Some ( ( link. href . clone ( ) , link. new_text . clone ( ) ) )
1013
+ let mut replacer = |broken_link : BrokenLink < ' _ > | {
1014
+ if let Some ( link) =
1015
+ links. iter ( ) . find ( |link| & * link. original_text == broken_link. reference )
1016
+ {
1017
+ Some ( ( link. href . as_str ( ) . into ( ) , link. new_text . as_str ( ) . into ( ) ) )
1015
1018
} else {
1016
1019
None
1017
1020
}
@@ -1020,7 +1023,7 @@ impl MarkdownSummaryLine<'_> {
1020
1023
let p = Parser :: new_with_broken_link_callback (
1021
1024
md,
1022
1025
Options :: ENABLE_STRIKETHROUGH ,
1023
- Some ( & replacer) ,
1026
+ Some ( & mut replacer) ,
1024
1027
) ;
1025
1028
1026
1029
let mut s = String :: new ( ) ;
@@ -1067,7 +1070,7 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
1067
1070
}
1068
1071
1069
1072
let mut links = vec ! [ ] ;
1070
- let shortcut_links = RefCell :: new ( vec ! [ ] ) ;
1073
+ let mut shortcut_links = vec ! [ ] ;
1071
1074
1072
1075
{
1073
1076
let locate = |s : & str | unsafe {
@@ -1084,11 +1087,13 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
1084
1087
}
1085
1088
} ;
1086
1089
1087
- let push = |_: & str , s : & str | {
1088
- shortcut_links. borrow_mut ( ) . push ( ( s. to_owned ( ) , locate ( s) ) ) ;
1090
+ let mut push = |link : BrokenLink < ' _ > | {
1091
+ // FIXME: use `link.span` instead of `locate`
1092
+ // (doing it now includes the `[]` as well as the text)
1093
+ shortcut_links. push ( ( link. reference . to_owned ( ) , locate ( link. reference ) ) ) ;
1089
1094
None
1090
1095
} ;
1091
- let p = Parser :: new_with_broken_link_callback ( md, opts ( ) , Some ( & push) ) ;
1096
+ let p = Parser :: new_with_broken_link_callback ( md, opts ( ) , Some ( & mut push) ) ;
1092
1097
1093
1098
// There's no need to thread an IdMap through to here because
1094
1099
// the IDs generated aren't going to be emitted anywhere.
@@ -1106,8 +1111,7 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
1106
1111
}
1107
1112
}
1108
1113
1109
- let mut shortcut_links = shortcut_links. into_inner ( ) ;
1110
- links. extend ( shortcut_links. drain ( ..) ) ;
1114
+ links. append ( & mut shortcut_links) ;
1111
1115
1112
1116
links
1113
1117
}
0 commit comments