@@ -2,12 +2,12 @@ use std::collections::{BTreeMap, HashMap, HashSet};
22use std:: fmt;
33use std:: str:: FromStr ;
44
5- use serde:: ser;
65use serde:: de;
6+ use serde:: ser;
77
88use core:: { Dependency , Package , PackageId , SourceId , Workspace } ;
9- use util:: { internal, Graph } ;
109use util:: errors:: { CargoError , CargoResult , CargoResultExt } ;
10+ use util:: { internal, Graph } ;
1111
1212use super :: Resolve ;
1313
@@ -29,23 +29,8 @@ struct Patch {
2929
3030pub type Metadata = BTreeMap < String , String > ;
3131
32- pub enum ErrorHandle {
33- Ignore ,
34- Raise ,
35- }
36-
37- impl ErrorHandle {
38- fn is_ignore ( & self ) -> bool {
39- use self :: ErrorHandle :: * ;
40- match self {
41- Ignore => true ,
42- Raise => false ,
43- }
44- }
45- }
46-
4732impl EncodableResolve {
48- pub fn into_resolve ( self , ws : & Workspace , ignore_errors : ErrorHandle ) -> CargoResult < Resolve > {
33+ pub fn into_resolve ( self , ws : & Workspace ) -> CargoResult < Resolve > {
4934 let path_deps = build_path_deps ( ws) ;
5035
5136 let packages = {
@@ -58,7 +43,7 @@ impl EncodableResolve {
5843
5944 // `PackageId`s in the lock file don't include the `source` part
6045 // for workspace members, so we reconstruct proper ids.
61- let ( live_pkgs, all_pkgs ) = {
46+ let live_pkgs = {
6247 let mut live_pkgs = HashMap :: new ( ) ;
6348 let mut all_pkgs = HashSet :: new ( ) ;
6449 for pkg in packages. iter ( ) {
@@ -69,10 +54,7 @@ impl EncodableResolve {
6954 } ;
7055
7156 if !all_pkgs. insert ( enc_id. clone ( ) ) {
72- bail ! (
73- "package `{}` is specified twice in the lockfile" ,
74- pkg. name
75- ) ;
57+ bail ! ( "package `{}` is specified twice in the lockfile" , pkg. name) ;
7658 }
7759 let id = match pkg. source . as_ref ( ) . or_else ( || path_deps. get ( & pkg. name ) ) {
7860 // We failed to find a local package in the workspace.
@@ -86,33 +68,11 @@ impl EncodableResolve {
8668
8769 assert ! ( live_pkgs. insert( enc_id, ( id, pkg) ) . is_none( ) )
8870 }
89- ( live_pkgs, all_pkgs )
71+ live_pkgs
9072 } ;
9173
92- let lookup_id = |enc_id : & EncodablePackageId ,
93- dependent_pkg : Option < & PackageId > |
94- -> CargoResult < Option < PackageId > > {
95- match live_pkgs. get ( enc_id) {
96- Some ( & ( ref id, _) ) => Ok ( Some ( id. clone ( ) ) ) ,
97- None => if all_pkgs. contains ( enc_id) {
98- // Package is found in the lockfile, but it is
99- // no longer a member of the workspace.
100- Ok ( None )
101- } else if ignore_errors. is_ignore ( ) {
102- // We are asked to ignore errors
103- Ok ( None )
104- } else {
105- let suggestion = dependent_pkg
106- . map ( |p| format ! ( "\n consider running 'cargo update -p {}'" , p. name( ) ) )
107- . unwrap_or_default ( ) ;
108- bail ! (
109- "package `{}` is specified as a dependency, \
110- but is missing from the package list{}",
111- enc_id,
112- suggestion,
113- ) ;
114- } ,
115- }
74+ let lookup_id = |enc_id : & EncodablePackageId | -> Option < PackageId > {
75+ live_pkgs. get ( enc_id) . map ( |& ( ref id, _) | id. clone ( ) )
11676 } ;
11777
11878 let g = {
@@ -129,7 +89,7 @@ impl EncodableResolve {
12989 } ;
13090
13191 for edge in deps. iter ( ) {
132- if let Some ( to_depend_on) = lookup_id ( edge, Some ( id ) ) ? {
92+ if let Some ( to_depend_on) = lookup_id ( edge) {
13393 g. link ( id. clone ( ) , to_depend_on) ;
13494 }
13595 }
@@ -142,7 +102,7 @@ impl EncodableResolve {
142102 for & ( ref id, pkg) in live_pkgs. values ( ) {
143103 if let Some ( ref replace) = pkg. replace {
144104 assert ! ( pkg. dependencies. is_none( ) ) ;
145- if let Some ( replace_id) = lookup_id ( replace, Some ( id ) ) ? {
105+ if let Some ( replace_id) = lookup_id ( replace) {
146106 replacements. insert ( id. clone ( ) , replace_id) ;
147107 }
148108 }
@@ -173,10 +133,11 @@ impl EncodableResolve {
173133 for ( k, v) in metadata. iter ( ) . filter ( |p| p. 0 . starts_with ( prefix) ) {
174134 to_remove. push ( k. to_string ( ) ) ;
175135 let k = & k[ prefix. len ( ) ..] ;
176- let enc_id: EncodablePackageId = k. parse ( )
136+ let enc_id: EncodablePackageId = k
137+ . parse ( )
177138 . chain_err ( || internal ( "invalid encoding of checksum in lockfile" ) ) ?;
178- let id = match lookup_id ( & enc_id, None ) {
179- Ok ( Some ( id) ) => id,
139+ let id = match lookup_id ( & enc_id) {
140+ Some ( id) => id,
180141 _ => continue ,
181142 } ;
182143
@@ -217,7 +178,8 @@ fn build_path_deps(ws: &Workspace) -> HashMap<String, SourceId> {
217178 // such as `cargo install` with a lock file from a remote dependency. In
218179 // that case we don't need to fixup any path dependencies (as they're not
219180 // actually path dependencies any more), so we ignore them.
220- let members = ws. members ( )
181+ let members = ws
182+ . members ( )
221183 . filter ( |p| p. package_id ( ) . source_id ( ) . is_path ( ) )
222184 . collect :: < Vec < _ > > ( ) ;
223185
@@ -317,7 +279,8 @@ impl FromStr for EncodablePackageId {
317279 fn from_str ( s : & str ) -> CargoResult < EncodablePackageId > {
318280 let mut s = s. splitn ( 3 , ' ' ) ;
319281 let name = s. next ( ) . unwrap ( ) ;
320- let version = s. next ( )
282+ let version = s
283+ . next ( )
321284 . ok_or_else ( || internal ( "invalid serialized PackageId" ) ) ?;
322285 let source_id = match s. next ( ) {
323286 Some ( s) => {
@@ -373,7 +336,8 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> {
373336 let mut ids: Vec < _ > = self . resolve . iter ( ) . collect ( ) ;
374337 ids. sort ( ) ;
375338
376- let encodable = ids. iter ( )
339+ let encodable = ids
340+ . iter ( )
377341 . filter_map ( |& id| Some ( encodable_resolve_node ( id, self . resolve ) ) )
378342 . collect :: < Vec < _ > > ( ) ;
379343
@@ -395,7 +359,8 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> {
395359 } ;
396360
397361 let patch = Patch {
398- unused : self . resolve
362+ unused : self
363+ . resolve
399364 . unused_patches ( )
400365 . iter ( )
401366 . map ( |id| EncodableDependency {
0 commit comments