@@ -197,7 +197,12 @@ pub(crate) async fn extract(ctx: &DiscoverCtx<'_>, out: &mut Discovery) {
197197 }
198198 let mut manifests: Vec < ( String , DocumentMut ) > = Vec :: new ( ) ;
199199 if let Some ( doc) = root {
200- let root_pins = manifest_has_socket_pin ( & doc) ;
200+ // Any Socket pin the root or the config carries, a `[patch]`
201+ // entry included: members may hold the declarations it governs.
202+ let root_pins = doc. to_string ( ) . contains ( PIN_NAME_PREFIX )
203+ || config
204+ . as_ref ( )
205+ . is_some_and ( |c| c. 1 . to_string ( ) . contains ( PIN_NAME_PREFIX ) ) ;
201206 // A vendored copy wired in the root or the config is weighed against
202207 // every member's declarations ([`patch_bypassed`]).
203208 let vendored = !wired_all. is_empty ( ) ;
@@ -348,14 +353,14 @@ async fn read_toml(ctx: &DiscoverCtx<'_>, file: &str, out: &mut Discovery) -> Op
348353/// not a declaration — or a build `target/`). Unparseable ones are skipped
349354/// (diagnosed).
350355///
351- /// Members only ever decide about Socket wiring, so the walk is skipped
352- /// when there is none they could decide about: a parsed lock with no
353- /// Socket-sourced package, or an unparseable one (no ref either way). With
354- /// no lock, a member matters only when some manifest carries a
355- /// `socket- patch-` pin ( a lockless pin, [`UnlockedPin`]); the walk has the
356- /// texts, so the parse is skipped otherwise . `vendored` (the root manifest
357- /// or the config wires a Socket copy through `[patch]`, whose lock entries
358- /// are sourceless) always reads them, whatever the lock : a member's
356+ /// Members only ever decide about Socket wiring, so they are parsed only
357+ /// when there is some they could decide about: a lock with a
358+ /// Socket-sourced package, or a `socket-patch-` name in a member's own
359+ /// text, the root's or the config's (a pin to diagnose or recognize, a
360+ /// `[ patch]` entry members declare, a lockless pin, [`UnlockedPin`]),
361+ /// whatever the lock says (stale, unparseable or absent) . `vendored` (the
362+ /// root manifest or the config wires a Socket copy through `[patch]`,
363+ /// whose lock entries are sourceless) always reads them: a member's
359364/// declaration from a source the `[patch]` does not redirect bypasses the
360365/// copy ([`patch_bypassed`]).
361366async fn read_members (
@@ -365,19 +370,15 @@ async fn read_members(
365370 vendored : bool ,
366371 out : & mut Discovery ,
367372) -> Vec < ( String , DocumentMut ) > {
368- let lockless = match lock {
369- _ if vendored => false ,
370- Lock :: Parsed ( _) if has_socket_sourced ( ctx, lock) => false ,
371- Lock :: Parsed ( _) | Lock :: Unparseable => return Vec :: new ( ) ,
372- Lock :: Absent => true ,
373- } ;
373+ let socket_sourced =
374+ vendored || ( matches ! ( lock, Lock :: Parsed ( _) ) && has_socket_sourced ( ctx, lock) ) ;
374375 let texts: Vec < ( String , String ) > =
375376 crate :: utils:: cargo_workspace:: member_manifest_texts_in ( & ctx. view )
376377 . await
377378 . into_iter ( )
378379 . filter ( |( rel, _) | crate :: patch:: redirect:: is_cargo_member_manifest_key ( rel) )
379380 . collect ( ) ;
380- if lockless && !root_pins && !texts. iter ( ) . any ( |( _, t) | t. contains ( PIN_NAME_PREFIX ) ) {
381+ if !socket_sourced && !root_pins && !texts. iter ( ) . any ( |( _, t) | t. contains ( PIN_NAME_PREFIX ) ) {
381382 return Vec :: new ( ) ;
382383 }
383384 let mut members = Vec :: new ( ) ;
@@ -390,16 +391,6 @@ async fn read_members(
390391 members
391392}
392393
393- /// Whether some dependency declaration of `doc` names a `socket-patch-`
394- /// registry.
395- fn manifest_has_socket_pin ( doc : & DocumentMut ) -> bool {
396- dependency_entries ( doc) . iter ( ) . any ( |d| {
397- d. registry
398- . as_deref ( )
399- . is_some_and ( |r| r. trim ( ) . starts_with ( PIN_NAME_PREFIX ) )
400- } )
401- }
402-
403394/// Whether the lock resolves some package from a Socket patch server.
404395fn has_socket_sourced ( ctx : & DiscoverCtx < ' _ > , lock : & Lock ) -> bool {
405396 lock. packages ( ) . iter ( ) . any ( |p| {
@@ -1050,7 +1041,10 @@ fn beside_the_pin(
10501041 let refused: Vec < String > = unpinned
10511042 . iter ( )
10521043 . filter_map ( |( d, selects) | {
1053- let why = match ( & d. source , d. registry . as_deref ( ) , selects) {
1044+ // `registry = "crates-io"` is crates.io itself, which the
1045+ // rewriter re-pins like a declaration with no `registry` (#386).
1046+ let registry = d. registry . as_deref ( ) . filter ( |r| r. trim ( ) != "crates-io" ) ;
1047+ let why = match ( & d. source , registry, selects) {
10541048 ( DeclSource :: Registry , None , CargoReqMatch :: Ours ) => return None ,
10551049 ( DeclSource :: Registry , None , _) => {
10561050 let also: Vec < & str > = others
@@ -2609,6 +2603,19 @@ mod tests {
26092603 "{}" ,
26102604 u. detail
26112605 ) ;
2606+ // Review on #2019 (round 2): `registry = "crates-io"` is crates.io,
2607+ // which a re-scan re-pins (#386).
2608+ let p = mixed_workspace (
2609+ & pinned ( "serde" , "=1.0.1" , UUID_A ) ,
2610+ "serde = { version = \" 1\" , registry = \" crates-io\" }" ,
2611+ & [ ] ,
2612+ ) ;
2613+ let u = run ( & p) . await . unattested . remove ( 0 ) ;
2614+ assert ! (
2615+ u. detail. contains( "re-run `socket-patch scan`" ) ,
2616+ "{}" ,
2617+ u. detail
2618+ ) ;
26122619
26132620 // `"1"` also matches the crates.io 1.0.200 locked beside it.
26142621 let p = mixed_workspace (
@@ -3058,6 +3065,24 @@ mod tests {
30583065 let p = Project :: new ( ) ;
30593066 workspace_with_member ( & p, & pinned ( "serde" , "1" , UUID_A ) ) ;
30603067 assert ! ( member_read( & p. discover( ) . await ) ) ;
3068+ // Review on #2012 (round 2): a stale crates.io lock beside a member
3069+ // pin still reads the member, so the pin is diagnosed (a stale lock
3070+ // or a server outside the allowlist) and its uuid recognized.
3071+ let p = Project :: new ( ) ;
3072+ workspace_with_member ( & p, & pinned ( "serde" , "1" , UUID_A ) ) ;
3073+ p. write (
3074+ "Cargo.lock" ,
3075+ lock ( & [ ( "serde" , "1.0.1" , Some ( CRATES_IO ) , Some ( CKSUM ) ) ] ) ,
3076+ ) ;
3077+ let out = p. discover ( ) . await ;
3078+ assert ! ( member_read( & out) ) ;
3079+ assert ! (
3080+ out. diagnostics
3081+ . iter( )
3082+ . any( |d| d. code == DIAG_REF_UNATTRIBUTABLE ) ,
3083+ "{:?}" ,
3084+ out. diagnostics
3085+ ) ;
30613086 }
30623087
30633088 /// A rotated grant token in the definition is the same patch.
0 commit comments