@@ -25,6 +25,7 @@ use rustc_session::lint;
2525use rustc_span:: edition:: Edition ;
2626use rustc_span:: Span ;
2727use std:: borrow:: Cow ;
28+ use std:: cell:: RefCell ;
2829use std:: collections:: VecDeque ;
2930use std:: default:: Default ;
3031use std:: fmt:: Write ;
@@ -1132,8 +1133,7 @@ crate fn markdown_links(md: &str) -> Vec<(String, Range<usize>)> {
11321133 return vec ! [ ] ;
11331134 }
11341135
1135- let mut links = vec ! [ ] ;
1136- let mut shortcut_links = vec ! [ ] ;
1136+ let links = RefCell :: new ( vec ! [ ] ) ;
11371137
11381138 let locate = |s : & str , fallback : Range < usize > | unsafe {
11391139 let s_start = s. as_ptr ( ) ;
@@ -1152,7 +1152,7 @@ crate fn markdown_links(md: &str) -> Vec<(String, Range<usize>)> {
11521152 let mut push = |link : BrokenLink < ' _ > | {
11531153 // FIXME: use `link.span` instead of `locate`
11541154 // (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 ) ) ) ;
11561156 None
11571157 } ;
11581158 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>)> {
11651165 for ev in iter {
11661166 if let Event :: Start ( Tag :: Link ( _, dest, _) ) = ev. 0 {
11671167 debug ! ( "found link: {}" , dest) ;
1168- links. push ( match dest {
1168+ links. borrow_mut ( ) . push ( match dest {
11691169 CowStr :: Borrowed ( s) => ( s. to_owned ( ) , locate ( s, ev. 1 ) ) ,
11701170 s @ ( CowStr :: Boxed ( ..) | CowStr :: Inlined ( ..) ) => ( s. into_string ( ) , ev. 1 ) ,
11711171 } ) ;
11721172 }
11731173 }
11741174
1175- links. append ( & mut shortcut_links) ;
1176-
1177- links
1175+ links. into_inner ( )
11781176}
11791177
11801178#[ derive( Debug ) ]
0 commit comments