// Attempts to extract *one* library from the set `m`. If the set has no
// elements, `None` is returned. If the set has more than one element, then
// the errors and notes are emitted about the set of libraries.
//
// With only one library in the set, this function will extract it, and then
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
// be read, it is assumed that the file isn't a valid rust library (no
// errors are emitted).
Attempts to extract *one* library from the set `m`. If the set has no
elements, `None` is returned. If the set has more than one element, then
the errors and notes are emitted about the set of libraries.

With only one library in the set, this function will extract it, and then
read the metadata from it if `*slot` is `None`. If the metadata couldn't
be read, it is assumed that the file isn't a valid rust library (no
errors are emitted).
Attempts to extract * one * library from the set ` m ` . If the set has no elements ` None ` is returned . If the set has more than one element then the errors and notes are emitted about the set of libraries . With only one library in the set this function will extract it and then read the metadata from it if ` * slot ` is ` None ` . If the metadata couldn ' t be read it is assumed that the file isn ' t a valid rust library ( no errors are emitted ) .
fn extract_one(&mut self, m: HashMap<PathBuf, PathKind>, flavor: CrateFlavor,
                   slot: &mut Option<(Svh, MetadataBlob)>) -> Option<(PathBuf, PathKind)> {
        let mut ret: Option<(PathBuf, PathKind)> = None;
        let mut error = 0;
        if slot.is_some() {
            // FIXME(#10786): for an optimization, we only read one of the
            //                libraries' metadata sections. In theory we should
            //                read both, but reading dylib metadata is quite
            //                slow.
            if m.is_empty() {
                return None
            } else if m.len() == 1 {
                return Some(m.into_iter().next().unwrap())
            }
        }
        let mut err: Option<DiagnosticBuilder> = None;
        for (lib, kind) in m {
            info!("{} reading metadata from: {}", flavor, lib.display());
            let (hash, metadata) = match get_metadata_section(self.target, flavor, &lib) {
                Ok(blob) => {
                    if let Some(h) = self.crate_matches(blob.as_slice(), &lib) {
                        (h, blob)
                    } else {
                        info!("metadata mismatch");
                        continue
                    }
                }
                Err(err) => {
                    info!("no metadata found: {}", err);
                    continue
                }
            };
            // If we see multiple hashes, emit an error about duplicate candidates.
            if slot.as_ref().map_or(false, |s| s.0 != hash) {
                let mut e = struct_span_err!(self.sess, self.span, E0465,
                                             "multiple {} candidates for `{}` found",
                                             flavor, self.crate_name);
                e.span_note(self.span,
                            &format!(r"candidate #1: {}",
                                     ret.as_ref().unwrap().0
                                        .display()));
                if let Some(ref mut e) = err {
                    e.emit();
                }
                err = Some(e);
                error = 1;
                *slot = None;
            }
            if error > 0 {
                error += 1;
                err.as_mut().unwrap().span_note(self.span,
                                                &format!(r"candidate #{}: {}", error,
                                                         lib.display()));
                continue
            }
            *slot = Some((hash, metadata));
            ret = Some((lib, kind));
        }
        if error > 0 {
            err.unwrap().emit();
            None
        } else {
            ret
        }
    }
fn extract_one ( & mut self , m : HashMap < PathBuf , PathKind > , flavor : CrateFlavor , slot : & mut Option < ( Svh , MetadataBlob ) > ) -> Option < ( PathBuf , PathKind ) > { let mut ret : Option < ( PathBuf , PathKind ) > = None ; let mut error = 0 ; if slot . is_some ( ) { // FIXME(#10786): for an optimization, we only read one of the //                libraries' metadata sections. In theory we should //                read both, but reading dylib metadata is quite //                slow. if m . is_empty ( ) { return None } else if m . len ( ) == 1 { return Some ( m . into_iter ( ) . next ( ) . unwrap ( ) ) } } let mut err : Option < DiagnosticBuilder > = None ; for ( lib , kind ) in m { info ! ( " " flavor lib display ( ) ) ; let ( hash , metadata ) = match get_metadata_section ( self . target , flavor , & lib ) { Ok ( blob ) => { if let Some ( h ) = self . crate_matches ( blob . as_slice ( ) , & lib ) { ( h , blob ) } else { info ! ( " " ) ; continue } } Err ( err ) => { info ! ( " " err ) ; continue } } ; // If we see multiple hashes, emit an error about duplicate candidates. if slot . as_ref ( ) . map_or ( false , | s | s . 0 != hash ) { let mut e = struct_span_err ! ( self sess self span E0465 " " flavor self crate_name ) ; e . span_note ( self . span , & format ! ( r"candidate #1: {}" ret as_ref ( ) unwrap ( ) 0 display ( ) ) ) ; if let Some ( ref mut e ) = err { e . emit ( ) ; } err = Some ( e ) ; error = 1 ; * slot = None ; } if error > 0 { error += 1 ; err . as_mut ( ) . unwrap ( ) . span_note ( self . span , & format ! ( r"candidate #{}: {}" error lib display ( ) ) ) ; continue } * slot = Some ( ( hash , metadata ) ) ; ret = Some ( ( lib , kind ) ) ; } if error > 0 { err . unwrap ( ) . emit ( ) ; None } else { ret } }
Attempts to extract *one* library from the set `m`.
Attempts to extract * one * library from the set ` m ` .
&mut self
m
HashMap<PathBuf, PathKind>
flavor
CrateFlavor
slot
&mut Option<(Svh, MetadataBlob)>