fn compare_resolve(
    config: &Config,
    current_pkg: &Package,
    orig_resolve: &Resolve,
    new_resolve: &Resolve,
) -> CargoResult<()> {
    if config.shell().verbosity() != Verbosity::Verbose {
        return Ok(());
    }
    let new_set: BTreeSet<PackageId> = new_resolve.iter().collect();
    let orig_set: BTreeSet<PackageId> = orig_resolve.iter().collect();
    let added = new_set.difference(&orig_set);
    // Removed entries are ignored, this is used to quickly find hints for why
    // an entry changed.
    let removed: Vec<&PackageId> = orig_set.difference(&new_set).collect();
    for pkg_id in added {
        if pkg_id.name() == current_pkg.name() && pkg_id.version() == current_pkg.version() {
            // Skip the package that is being created, since its SourceId
            // (directory) changes.
            continue;
        }
        // Check for candidates where the source has changed (such as [patch]
        // or a dependency with multiple sources like path/version).
        let removed_candidates: Vec<&PackageId> = removed
            .iter()
            .filter(|orig_pkg_id| {
                orig_pkg_id.name() == pkg_id.name() && orig_pkg_id.version() == pkg_id.version()
            })
            .cloned()
            .collect();
        let extra = match removed_candidates.len() {
            0 => {
                // This can happen if the original was out of date.
                let previous_versions: Vec<&PackageId> = removed
                    .iter()
                    .filter(|orig_pkg_id| orig_pkg_id.name() == pkg_id.name())
                    .cloned()
                    .collect();
                match previous_versions.len() {
                    0 => String::new(),
                    1 => format!(
                        ", previous version was `{}`",
                        previous_versions[0].version()
                    ),
                    _ => format!(
                        ", previous versions were: {}",
                        previous_versions
                            .iter()
                            .map(|pkg_id| format!("`{}`", pkg_id.version()))
                            .collect::<Vec<_>>()
                            .join(", ")
                    ),
                }
            }
            1 => {
                // This can happen for multi-sourced dependencies like
                // `{path="...", version="..."}` or `[patch]` replacement.
                // `[replace]` is not captured in Cargo.lock.
                format!(
                    ", was originally sourced from `{}`",
                    removed_candidates[0].source_id()
                )
            }
            _ => {
                // I don't know if there is a way to actually trigger this,
                // but handle it just in case.
                let comma_list = removed_candidates
                    .iter()
                    .map(|pkg_id| format!("`{}`", pkg_id.source_id()))
                    .collect::<Vec<_>>()
                    .join(", ");
                format!(
                    ", was originally sourced from one of these sources: {}",
                    comma_list
                )
            }
        };
        let msg = format!(
            "package `{}` added to the packaged Cargo.lock file{}",
            pkg_id, extra
        );
        config.shell().note(msg)?;
    }
    Ok(())
}
/// Generate warnings when packaging Cargo.lock, and the resolve have changed.
Generate warnings when packaging Cargo.lock, and the resolve have changed.
Generate warnings when packaging Cargo . lock and the resolve have changed .
fn compare_resolve(
    config: &Config,
    current_pkg: &Package,
    orig_resolve: &Resolve,
    new_resolve: &Resolve,
) -> CargoResult<()> {
    if config.shell().verbosity() != Verbosity::Verbose {
        return Ok(());
    }
    let new_set: BTreeSet<PackageId> = new_resolve.iter().collect();
    let orig_set: BTreeSet<PackageId> = orig_resolve.iter().collect();
    let added = new_set.difference(&orig_set);
    // Removed entries are ignored, this is used to quickly find hints for why
    // an entry changed.
    let removed: Vec<&PackageId> = orig_set.difference(&new_set).collect();
    for pkg_id in added {
        if pkg_id.name() == current_pkg.name() && pkg_id.version() == current_pkg.version() {
            // Skip the package that is being created, since its SourceId
            // (directory) changes.
            continue;
        }
        // Check for candidates where the source has changed (such as [patch]
        // or a dependency with multiple sources like path/version).
        let removed_candidates: Vec<&PackageId> = removed
            .iter()
            .filter(|orig_pkg_id| {
                orig_pkg_id.name() == pkg_id.name() && orig_pkg_id.version() == pkg_id.version()
            })
            .cloned()
            .collect();
        let extra = match removed_candidates.len() {
            0 => {
                // This can happen if the original was out of date.
                let previous_versions: Vec<&PackageId> = removed
                    .iter()
                    .filter(|orig_pkg_id| orig_pkg_id.name() == pkg_id.name())
                    .cloned()
                    .collect();
                match previous_versions.len() {
                    0 => String::new(),
                    1 => format!(
                        ", previous version was `{}`",
                        previous_versions[0].version()
                    ),
                    _ => format!(
                        ", previous versions were: {}",
                        previous_versions
                            .iter()
                            .map(|pkg_id| format!("`{}`", pkg_id.version()))
                            .collect::<Vec<_>>()
                            .join(", ")
                    ),
                }
            }
            1 => {
                // This can happen for multi-sourced dependencies like
                // `{path="...", version="..."}` or `[patch]` replacement.
                // `[replace]` is not captured in Cargo.lock.
                format!(
                    ", was originally sourced from `{}`",
                    removed_candidates[0].source_id()
                )
            }
            _ => {
                // I don't know if there is a way to actually trigger this,
                // but handle it just in case.
                let comma_list = removed_candidates
                    .iter()
                    .map(|pkg_id| format!("`{}`", pkg_id.source_id()))
                    .collect::<Vec<_>>()
                    .join(", ");
                format!(
                    ", was originally sourced from one of these sources: {}",
                    comma_list
                )
            }
        };
        let msg = format!(
            "package `{}` added to the packaged Cargo.lock file{}",
            pkg_id, extra
        );
        config.shell().note(msg)?;
    }
    Ok(())
}
fn compare_resolve ( config : & Config , current_pkg : & Package , orig_resolve : & Resolve , new_resolve : & Resolve , ) -> CargoResult < ( ) > { if config . shell ( ) . verbosity ( ) != Verbosity :: Verbose { return Ok ( ( ) ) ; } let new_set : BTreeSet < PackageId > = new_resolve . iter ( ) . collect ( ) ; let orig_set : BTreeSet < PackageId > = orig_resolve . iter ( ) . collect ( ) ; let added = new_set . difference ( & orig_set ) ; // Removed entries are ignored, this is used to quickly find hints for why // an entry changed. let removed : Vec < & PackageId > = orig_set . difference ( & new_set ) . collect ( ) ; for pkg_id in added { if pkg_id . name ( ) == current_pkg . name ( ) && pkg_id . version ( ) == current_pkg . version ( ) { // Skip the package that is being created, since its SourceId // (directory) changes. continue ; } // Check for candidates where the source has changed (such as [patch] // or a dependency with multiple sources like path/version). let removed_candidates : Vec < & PackageId > = removed . iter ( ) . filter ( | orig_pkg_id | { orig_pkg_id . name ( ) == pkg_id . name ( ) && orig_pkg_id . version ( ) == pkg_id . version ( ) } ) . cloned ( ) . collect ( ) ; let extra = match removed_candidates . len ( ) { 0 => { // This can happen if the original was out of date. let previous_versions : Vec < & PackageId > = removed . iter ( ) . filter ( | orig_pkg_id | orig_pkg_id . name ( ) == pkg_id . name ( ) ) . cloned ( ) . collect ( ) ; match previous_versions . len ( ) { 0 => String :: new ( ) , 1 => format ! ( " " previous_versions [ 0 ] version ( ) ) , _ => format ! ( " " previous_versions iter ( ) map ( pkg_id format ( " " pkg_id version ( ) ) ) collect Vec ( ) join ( " " ) ) , } } 1 => { // This can happen for multi-sourced dependencies like // `{path="...", version="..."}` or `[patch]` replacement. // `[replace]` is not captured in Cargo.lock. format ! ( " " removed_candidates [ 0 ] source_id ( ) ) } _ => { // I don't know if there is a way to actually trigger this, // but handle it just in case. let comma_list = removed_candidates . iter ( ) . map ( | pkg_id | format ! ( " " pkg_id source_id ( ) ) ) . collect :: < Vec < _ > > ( ) . join ( " " ) ; format ! ( " " comma_list ) } } ; let msg = format ! ( " " pkg_id extra ) ; config . shell ( ) . note ( msg ) ? ; } Ok ( ( ) ) }
Generate warnings when packaging Cargo.lock, and the resolve have changed.
Generate warnings when packaging Cargo . lock and the resolve have changed .
config
&Config
current_pkg
&Package
orig_resolve
&Resolve
new_resolve
&Resolve
config
&Config
current_pkg
&Package
orig_resolve
&Resolve
new_resolve
&Resolve