@@ -89,70 +89,68 @@ fn find_library_crate_aux(
8989 filesearch : @filesearch:: FileSearch
9090) -> Option < ( ~str , @~[ u8 ] ) > {
9191 let crate_name = crate_name_from_metas ( cx. metas ) ;
92- let prefix: ~str = prefix + crate_name + "-" ;
93- let suffix: ~str = /*bad*/ copy suffix;
92+ let prefix = prefix + crate_name + "-" ;
9493
9594 let mut matches = ~[ ] ;
96- filesearch:: search ( filesearch, |path| {
95+ filesearch:: search ( filesearch, |path| -> Option < ( ) > {
9796 debug ! ( "inspecting file %s" , path. to_str( ) ) ;
98- let f: ~str = path. filename ( ) . get ( ) ;
99- if !( f. starts_with ( prefix) && f. ends_with ( suffix) ) {
100- debug ! ( "skipping %s, doesn't look like %s*%s" , path. to_str( ) ,
101- prefix, suffix) ;
102- option:: None :: < ( ) >
103- } else {
104- debug ! ( "%s is a candidate" , path. to_str( ) ) ;
105- match get_metadata_section ( cx. os , path) {
106- option:: Some ( cvec) => {
107- if !crate_matches ( cvec, cx. metas , cx. hash ) {
108- debug ! ( "skipping %s, metadata doesn't match" ,
109- path. to_str( ) ) ;
110- option:: None :: < ( ) >
111- } else {
112- debug ! ( "found %s with matching metadata" , path. to_str( ) ) ;
113- matches. push ( ( path. to_str ( ) , cvec) ) ;
114- option:: None :: < ( ) >
97+ match path. filename ( ) {
98+ Some ( ref f) if f. starts_with ( prefix) && f. ends_with ( suffix) => {
99+ debug ! ( "%s is a candidate" , path. to_str( ) ) ;
100+ match get_metadata_section ( cx. os , path) {
101+ Some ( cvec) =>
102+ if !crate_matches ( cvec, cx. metas , cx. hash ) {
103+ debug ! ( "skipping %s, metadata doesn't match" ,
104+ path. to_str( ) ) ;
105+ None
106+ } else {
107+ debug ! ( "found %s with matching metadata" , path. to_str( ) ) ;
108+ matches. push ( ( path. to_str ( ) , cvec) ) ;
109+ None
110+ } ,
111+ _ => {
112+ debug ! ( "could not load metadata for %s" , path. to_str( ) ) ;
113+ None
114+ }
115115 }
116- }
117- _ => {
118- debug ! ( "could not load metadata for %s" , path. to_str( ) ) ;
119- option:: None :: < ( ) >
120- }
121116 }
122- }
123- } ) ;
117+ _ => {
118+ debug ! ( "skipping %s, doesn't look like %s*%s" , path. to_str( ) ,
119+ prefix, suffix) ;
120+ None
121+ }
122+ } } ) ;
124123
125- if matches. is_empty ( ) {
126- None
127- } else if matches. len ( ) == 1 u {
128- Some ( /*bad*/ copy matches[ 0 ] )
129- } else {
130- cx. diag . span_err (
131- cx. span , fmt ! ( "multiple matching crates for `%s`" , crate_name) ) ;
132- cx. diag . handler ( ) . note ( "candidates:" ) ;
133- for matches. iter( ) . advance |& ( ident, data) | {
134- cx. diag. handler( ) . note( fmt ! ( "path: %s" , ident) ) ;
135- let attrs = decoder:: get_crate_attributes( data) ;
136- note_linkage_attrs( cx. intr, cx. diag, attrs) ;
124+ match matches. len ( ) {
125+ 0 => None ,
126+ 1 => Some ( matches[ 0 ] ) ,
127+ _ => {
128+ cx. diag . span_err (
129+ cx. span , fmt ! ( "multiple matching crates for `%s`" , crate_name) ) ;
130+ cx. diag . handler ( ) . note ( "candidates:" ) ;
131+ for matches. each |& ( ident, data) | {
132+ cx. diag . handler ( ) . note ( fmt ! ( "path: %s" , ident) ) ;
133+ let attrs = decoder:: get_crate_attributes ( data) ;
134+ note_linkage_attrs ( cx. intr , cx. diag , attrs) ;
135+ }
136+ cx. diag . handler ( ) . abort_if_errors ( ) ;
137+ None
138+ }
137139 }
138- cx. diag. handler( ) . abort_if_errors( ) ;
139- None
140- }
141140}
142141
143142pub fn crate_name_from_metas ( metas : & [ @ast:: meta_item ] ) -> @str {
144- let name_items = attr:: find_meta_items_by_name( metas, "name" ) ;
145- match name_items. last_opt( ) {
146- Some ( i) => {
147- match attr:: get_meta_item_value_str( * i) {
148- Some ( n) => n,
149- // FIXME (#2406): Probably want a warning here since the user
150- // is using the wrong type of meta item.
151- _ => fail ! ( )
152- }
143+ for metas. each |m| {
144+ match m. node {
145+ ast:: meta_name_value( s, ref l) if s == @"name" =>
146+ match l. node {
147+ ast:: lit_str( s) => return s,
148+ _ => ( )
149+ } ,
150+ _ => ( )
153151 }
154- None => fail ! ( "expected to find the crate name" )
155152 }
153+ fail ! ( "expected to find the crate name" )
156154}
157155
158156pub fn note_linkage_attrs( intr : @ident_interner ,
0 commit comments