@@ -25,6 +25,7 @@ use rustc_session::lint;
25
25
use rustc_span:: edition:: Edition ;
26
26
use rustc_span:: Span ;
27
27
use std:: borrow:: Cow ;
28
+ use std:: cell:: RefCell ;
28
29
use std:: collections:: VecDeque ;
29
30
use std:: default:: Default ;
30
31
use std:: fmt:: Write ;
@@ -1132,8 +1133,7 @@ crate fn markdown_links(md: &str) -> Vec<(String, Range<usize>)> {
1132
1133
return vec ! [ ] ;
1133
1134
}
1134
1135
1135
- let mut links = vec ! [ ] ;
1136
- let mut shortcut_links = vec ! [ ] ;
1136
+ let links = RefCell :: new ( vec ! [ ] ) ;
1137
1137
1138
1138
let locate = |s : & str , fallback : Range < usize > | unsafe {
1139
1139
let s_start = s. as_ptr ( ) ;
@@ -1152,7 +1152,7 @@ crate fn markdown_links(md: &str) -> Vec<(String, Range<usize>)> {
1152
1152
let mut push = |link : BrokenLink < ' _ > | {
1153
1153
// FIXME: use `link.span` instead of `locate`
1154
1154
// (doing it now includes the `[]` as well as the text)
1155
- shortcut_links . push ( ( link. reference . to_owned ( ) , locate ( link. reference , link. span ) ) ) ;
1155
+ links . borrow_mut ( ) . push ( ( link. reference . to_owned ( ) , locate ( link. reference , link. span ) ) ) ;
1156
1156
None
1157
1157
} ;
1158
1158
let p = Parser :: new_with_broken_link_callback ( md, opts ( ) , Some ( & mut push) ) . into_offset_iter ( ) ;
@@ -1165,16 +1165,14 @@ crate fn markdown_links(md: &str) -> Vec<(String, Range<usize>)> {
1165
1165
for ev in iter {
1166
1166
if let Event :: Start ( Tag :: Link ( _, dest, _) ) = ev. 0 {
1167
1167
debug ! ( "found link: {}" , dest) ;
1168
- links. push ( match dest {
1168
+ links. borrow_mut ( ) . push ( match dest {
1169
1169
CowStr :: Borrowed ( s) => ( s. to_owned ( ) , locate ( s, ev. 1 ) ) ,
1170
1170
s @ ( CowStr :: Boxed ( ..) | CowStr :: Inlined ( ..) ) => ( s. into_string ( ) , ev. 1 ) ,
1171
1171
} ) ;
1172
1172
}
1173
1173
}
1174
1174
1175
- links. append ( & mut shortcut_links) ;
1176
-
1177
- links
1175
+ links. into_inner ( )
1178
1176
}
1179
1177
1180
1178
#[ derive( Debug ) ]
0 commit comments