@@ -726,22 +726,35 @@ impl<'a> CrateLocator<'a> {
726726 let Some ( file) = loc_orig. file_name ( ) . and_then ( |s| s. to_str ( ) ) else {
727727 return Err ( CrateError :: ExternLocationNotFile ( self . crate_name , loc_orig. clone ( ) ) ) ;
728728 } ;
729- if file. starts_with ( "lib" ) && ( file. ends_with ( ".rlib" ) || file. ends_with ( ".rmeta" ) )
730- || file. starts_with ( self . target . dll_prefix . as_ref ( ) )
731- && file. ends_with ( self . target . dll_suffix . as_ref ( ) )
732- {
733- let loc_canon = loc_canon. clone ( ) ;
734- if file. ends_with ( ".rlib" ) {
735- rlibs. insert ( loc_canon, PathKind :: ExternFlag ) ;
736- } else if file. ends_with ( ".rmeta" ) {
737- rmetas. insert ( loc_canon, PathKind :: ExternFlag ) ;
738- } else {
739- dylibs. insert ( loc_canon, PathKind :: ExternFlag ) ;
729+ // FnMut cannot return reference to captured value, so references
730+ // must be taken outside the closure.
731+ let rlibs = & mut rlibs;
732+ let rmetas = & mut rmetas;
733+ let dylibs = & mut dylibs;
734+ match ( || {
735+ if file. starts_with ( "lib" ) {
736+ if file. ends_with ( ".rlib" ) {
737+ return Some ( rlibs) ;
738+ }
739+ if file. ends_with ( ".rmeta" ) {
740+ return Some ( rmetas) ;
741+ }
742+ }
743+ let dll_prefix = self . target . dll_prefix . as_ref ( ) ;
744+ let dll_suffix = self . target . dll_suffix . as_ref ( ) ;
745+ if file. starts_with ( dll_prefix) && file. ends_with ( dll_suffix) {
746+ return Some ( dylibs) ;
747+ }
748+ None
749+ } ) ( ) {
750+ Some ( dst) => {
751+ dst. insert ( loc_canon. clone ( ) , PathKind :: ExternFlag ) ;
752+ }
753+ None => {
754+ self . crate_rejections
755+ . via_filename
756+ . push ( CrateMismatch { path : loc_orig. clone ( ) , got : String :: new ( ) } ) ;
740757 }
741- } else {
742- self . crate_rejections
743- . via_filename
744- . push ( CrateMismatch { path : loc_orig. clone ( ) , got : String :: new ( ) } ) ;
745758 }
746759 }
747760
0 commit comments