@@ -726,22 +726,36 @@ 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+ let type_via_filename = ( || {
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+ match type_via_filename {
751+ Some ( type_via_filename) => {
752+ type_via_filename. insert ( loc_canon. clone ( ) , PathKind :: ExternFlag ) ;
753+ }
754+ None => {
755+ self . crate_rejections
756+ . via_filename
757+ . push ( CrateMismatch { path : loc_orig. clone ( ) , got : String :: new ( ) } ) ;
740758 }
741- } else {
742- self . crate_rejections
743- . via_filename
744- . push ( CrateMismatch { path : loc_orig. clone ( ) , got : String :: new ( ) } ) ;
745759 }
746760 }
747761
0 commit comments