@@ -6,8 +6,6 @@ use crate::sources::IndexSummary;
66use crate :: util:: errors:: CargoResult ;
77use std:: task:: Poll ;
88
9- use anyhow:: Context as _;
10-
119/// A source that replaces one source with the other. This manages the [source
1210/// replacement] feature.
1311///
@@ -37,6 +35,14 @@ impl<'cfg> ReplacedSource<'cfg> {
3735 inner : src,
3836 }
3937 }
38+
39+ /// Is this source a built-in replacement of crates.io?
40+ ///
41+ /// Built-in source replacement of crates.io for sparse registry or tests
42+ /// should not show messages indicating source replacement.
43+ fn is_builtin_replacement ( & self ) -> bool {
44+ self . replace_with . is_crates_io ( ) && self . to_replace . is_crates_io ( )
45+ }
4046}
4147
4248impl < ' cfg > Source for ReplacedSource < ' cfg > {
@@ -70,10 +76,14 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
7076 f ( summary. map_summary ( |s| s. map_source ( replace_with, to_replace) ) )
7177 } )
7278 . map_err ( |e| {
73- e. context ( format ! (
74- "failed to query replaced source {}" ,
75- self . to_replace
76- ) )
79+ if self . is_builtin_replacement ( ) {
80+ e
81+ } else {
82+ e. context ( format ! (
83+ "failed to query replaced source {}" ,
84+ self . to_replace
85+ ) )
86+ }
7787 } )
7888 }
7989
@@ -87,10 +97,16 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
8797
8898 fn download ( & mut self , id : PackageId ) -> CargoResult < MaybePackage > {
8999 let id = id. with_source_id ( self . replace_with ) ;
90- let pkg = self
91- . inner
92- . download ( id)
93- . with_context ( || format ! ( "failed to download replaced source {}" , self . to_replace) ) ?;
100+ let pkg = self . inner . download ( id) . map_err ( |e| {
101+ if self . is_builtin_replacement ( ) {
102+ e
103+ } else {
104+ e. context ( format ! (
105+ "failed to download replaced source {}" ,
106+ self . to_replace
107+ ) )
108+ }
109+ } ) ?;
94110 Ok ( match pkg {
95111 MaybePackage :: Ready ( pkg) => {
96112 MaybePackage :: Ready ( pkg. map_source ( self . replace_with , self . to_replace ) )
@@ -101,10 +117,16 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
101117
102118 fn finish_download ( & mut self , id : PackageId , data : Vec < u8 > ) -> CargoResult < Package > {
103119 let id = id. with_source_id ( self . replace_with ) ;
104- let pkg = self
105- . inner
106- . finish_download ( id, data)
107- . with_context ( || format ! ( "failed to download replaced source {}" , self . to_replace) ) ?;
120+ let pkg = self . inner . finish_download ( id, data) . map_err ( |e| {
121+ if self . is_builtin_replacement ( ) {
122+ e
123+ } else {
124+ e. context ( format ! (
125+ "failed to download replaced source {}" ,
126+ self . to_replace
127+ ) )
128+ }
129+ } ) ?;
108130 Ok ( pkg. map_source ( self . replace_with , self . to_replace ) )
109131 }
110132
@@ -118,9 +140,7 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
118140 }
119141
120142 fn describe ( & self ) -> String {
121- if self . replace_with . is_crates_io ( ) && self . to_replace . is_crates_io ( ) {
122- // Built-in source replacement of crates.io for sparse registry or tests
123- // doesn't need duplicate description (crates.io replacing crates.io).
143+ if self . is_builtin_replacement ( ) {
124144 self . inner . describe ( )
125145 } else {
126146 format ! (
@@ -148,8 +168,15 @@ impl<'cfg> Source for ReplacedSource<'cfg> {
148168 }
149169
150170 fn block_until_ready ( & mut self ) -> CargoResult < ( ) > {
151- self . inner
152- . block_until_ready ( )
153- . with_context ( || format ! ( "failed to update replaced source {}" , self . to_replace) )
171+ self . inner . block_until_ready ( ) . map_err ( |e| {
172+ if self . is_builtin_replacement ( ) {
173+ e
174+ } else {
175+ e. context ( format ! (
176+ "failed to update replaced source {}" ,
177+ self . to_replace
178+ ) )
179+ }
180+ } )
154181 }
155182}
0 commit comments