1616//! A few exceptions are allowed as there's known bugs in rustdoc, but this 
1717//! should catch the majority of "broken link" cases. 
1818
19- use  std:: cell:: RefCell ; 
19+ use  std:: cell:: { Cell ,   RefCell } ; 
2020use  std:: collections:: { HashMap ,  HashSet } ; 
2121use  std:: io:: ErrorKind ; 
2222use  std:: path:: { Component ,  Path ,  PathBuf } ; 
@@ -544,7 +544,7 @@ fn parse_html<Sink: TokenSink>(source: &str, sink: Sink) -> Sink {
544544    let  mut  input = BufferQueue :: default ( ) ; 
545545    input. push_back ( tendril. try_reinterpret ( ) . unwrap ( ) ) ; 
546546
547-     let  mut   tok = Tokenizer :: new ( sink,  TokenizerOpts :: default ( ) ) ; 
547+     let  tok = Tokenizer :: new ( sink,  TokenizerOpts :: default ( ) ) ; 
548548    let  _ = tok. feed ( & mut  input) ; 
549549    assert ! ( input. is_empty( ) ) ; 
550550    tok. end ( ) ; 
@@ -554,8 +554,8 @@ fn parse_html<Sink: TokenSink>(source: &str, sink: Sink) -> Sink {
554554#[ derive( Default ) ]  
555555struct  AttrCollector  { 
556556    attr_name :  & ' static  [ u8 ] , 
557-     base :  Option < String > , 
558-     found_attrs :  Vec < ( u64 ,  String ) > , 
557+     base :  Cell < Option < String > > , 
558+     found_attrs :  RefCell < Vec < ( u64 ,  String ) > > , 
559559    /// Tracks whether or not it is inside a <script> tag. 
560560/// 
561561/// A lot of our sources have JSON script tags which have HTML embedded 
@@ -564,34 +564,34 @@ struct AttrCollector {
564564/// `TokenSinkResult::Script(…)` (and then maybe switch parser?), but I 
565565/// don't fully understand the best way to use that, and this seems good 
566566/// enough for now. 
567- in_script :  bool , 
567+ in_script :  Cell < bool > , 
568568} 
569569
570570impl  TokenSink  for  AttrCollector  { 
571571    type  Handle  = ( ) ; 
572572
573-     fn  process_token ( & mut   self ,  token :  Token ,  line_number :  u64 )  -> TokenSinkResult < ( ) >  { 
573+     fn  process_token ( & self ,  token :  Token ,  line_number :  u64 )  -> TokenSinkResult < ( ) >  { 
574574        match  token { 
575575            TagToken ( tag)  => { 
576576                let  tag_name = tag. name . as_bytes ( ) ; 
577577                if  tag_name == b"base"  { 
578578                    if  let  Some ( href)  =
579579                        tag. attrs . iter ( ) . find ( |attr| attr. name . local . as_bytes ( )  == b"href" ) 
580580                    { 
581-                         self . base  =  Some ( href. value . to_string ( ) ) ; 
581+                         self . base . set ( Some ( href. value . to_string ( ) ) ) ; 
582582                    } 
583583                    return  TokenSinkResult :: Continue ; 
584584                }  else  if  tag_name == b"script"  { 
585-                     self . in_script  =  !self . in_script ; 
585+                     self . in_script . set ( !self . in_script . get ( ) ) ; 
586586                } 
587-                 if  self . in_script  { 
587+                 if  self . in_script . get ( )  { 
588588                    return  TokenSinkResult :: Continue ; 
589589                } 
590590                for  attr in  tag. attrs . iter ( )  { 
591591                    let  name = attr. name . local . as_bytes ( ) ; 
592592                    if  name == self . attr_name  { 
593593                        let  url = attr. value . to_string ( ) ; 
594-                         self . found_attrs . push ( ( line_number,  url) ) ; 
594+                         self . found_attrs . borrow_mut ( ) . push ( ( line_number,  url) ) ; 
595595                    } 
596596                } 
597597            } 
@@ -607,7 +607,7 @@ impl TokenSink for AttrCollector {
607607fn  get_urls ( source :  & str )  -> ( Option < String > ,  Vec < ( u64 ,  String ) > )  { 
608608    let  collector = AttrCollector  {  attr_name :  b"href" ,  ..AttrCollector :: default ( )  } ; 
609609    let  sink = parse_html ( source,  collector) ; 
610-     ( sink. base ,  sink. found_attrs ) 
610+     ( sink. base . into_inner ( ) ,  sink. found_attrs . into_inner ( ) ) 
611611} 
612612
613613/// Retrieves id="..." attributes from HTML elements. 
@@ -619,7 +619,7 @@ fn parse_ids(ids: &mut HashSet<String>, file: &str, source: &str, report: &mut R
619619
620620    let  collector = AttrCollector  {  attr_name :  b"id" ,  ..AttrCollector :: default ( )  } ; 
621621    let  sink = parse_html ( source,  collector) ; 
622-     for  ( line_number,  id)  in  sink. found_attrs  { 
622+     for  ( line_number,  id)  in  sink. found_attrs . into_inner ( )  { 
623623        let  encoded = small_url_encode ( & id) ; 
624624        if  let  Some ( id)  = ids. replace ( id)  { 
625625            report. errors  += 1 ; 
0 commit comments