11use std:: ffi:: OsStr ;
2- use std:: fmt;
32use std:: fs:: { self , File } ;
43use std:: io:: prelude:: * ;
54use std:: io:: { self , BufReader } ;
@@ -10,6 +9,8 @@ use std::sync::LazyLock as Lazy;
109use itertools:: Itertools ;
1110use rustc_data_structures:: flock;
1211use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
12+ use serde:: ser:: SerializeSeq ;
13+ use serde:: { Serialize , Serializer } ;
1314
1415use super :: { collect_paths_for_type, ensure_trailing_slash, Context , BASIC_KEYWORDS } ;
1516use crate :: clean:: Crate ;
@@ -563,36 +564,18 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
563564 types : Vec < String > ,
564565 }
565566
566- impl Implementor {
567- fn to_js_string ( & self ) -> impl fmt:: Display + ' _ {
568- fn single_quote_string ( s : & str ) -> String {
569- let mut result = String :: with_capacity ( s. len ( ) + 2 ) ;
570- result. push_str ( "'" ) ;
571- for c in s. chars ( ) {
572- if c == '"' {
573- result. push_str ( "\" " ) ;
574- } else {
575- result. extend ( c. escape_default ( ) ) ;
576- }
577- }
578- result. push_str ( "'" ) ;
579- result
567+ impl Serialize for Implementor {
568+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
569+ where
570+ S : Serializer ,
571+ {
572+ let mut seq = serializer. serialize_seq ( None ) ?;
573+ seq. serialize_element ( & self . text ) ?;
574+ if self . synthetic {
575+ seq. serialize_element ( & 1 ) ?;
576+ seq. serialize_element ( & self . types ) ?;
580577 }
581- crate :: html:: format:: display_fn ( |f| {
582- let text_esc = single_quote_string ( & self . text ) ;
583- if self . synthetic {
584- let types = crate :: html:: format:: comma_sep (
585- self . types . iter ( ) . map ( |type_| single_quote_string ( type_) ) ,
586- false ,
587- ) ;
588- // use `1` to represent a synthetic, because it's fewer bytes than `true`
589- write ! ( f, "[{text_esc},1,[{types}]]" )
590- } else {
591- // The types list is only used for synthetic impls.
592- // If this changes, `main.js` and `write_shared.rs` both need changed.
593- write ! ( f, "[{text_esc}]" )
594- }
595- } )
578+ seq. end ( )
596579 }
597580 }
598581
@@ -626,12 +609,9 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
626609 }
627610
628611 let implementors = format ! (
629- r#""{}":[{}] "# ,
612+ r#""{}":{} "# ,
630613 krate. name( cx. tcx( ) ) ,
631- crate :: html:: format:: comma_sep(
632- implementors. iter( ) . map( Implementor :: to_js_string) ,
633- false
634- )
614+ serde_json:: to_string( & implementors) . expect( "failed serde conversion" ) ,
635615 ) ;
636616
637617 let mut mydst = dst. clone ( ) ;
0 commit comments