@@ -68,7 +68,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
68
68
opts. registry . clone ( ) ,
69
69
true ,
70
70
) ?;
71
- verify_dependencies ( pkg, reg_id) ?;
71
+ verify_dependencies ( pkg, & registry , reg_id) ?;
72
72
73
73
// Prepare a tarball, with a non-surpressable warning if metadata
74
74
// is missing since this is being put online.
@@ -102,7 +102,11 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
102
102
Ok ( ( ) )
103
103
}
104
104
105
- fn verify_dependencies ( pkg : & Package , registry_src : SourceId ) -> CargoResult < ( ) > {
105
+ fn verify_dependencies (
106
+ pkg : & Package ,
107
+ registry : & Registry ,
108
+ registry_src : SourceId ,
109
+ ) -> CargoResult < ( ) > {
106
110
for dep in pkg. dependencies ( ) . iter ( ) {
107
111
if dep. source_id ( ) . is_path ( ) {
108
112
if !dep. specified_req ( ) {
@@ -115,9 +119,16 @@ fn verify_dependencies(pkg: &Package, registry_src: SourceId) -> CargoResult<()>
115
119
}
116
120
} else if dep. source_id ( ) != registry_src {
117
121
if dep. source_id ( ) . is_registry ( ) {
118
- // Block requests to send to a registry if it is not an alternative
119
- // registry
120
- if !registry_src. is_alt_registry ( ) {
122
+ // Block requests to send to crates.io with alt-registry deps.
123
+ // This extra hostname check is mostly to assist with testing,
124
+ // but also prevents someone using `--index` to specify
125
+ // something that points to crates.io.
126
+ let is_crates_io = registry
127
+ . host ( )
128
+ . to_url ( )
129
+ . map ( |u| u. host_str ( ) == Some ( "crates.io" ) )
130
+ . unwrap_or ( false ) ;
131
+ if registry_src. is_default_registry ( ) || is_crates_io {
121
132
failure:: bail!( "crates cannot be published to crates.io with dependencies sourced from other\n \
122
133
registries either publish `{}` on crates.io or pull it into this repository\n \
123
134
and specify it with a path and version\n \
@@ -128,9 +139,9 @@ fn verify_dependencies(pkg: &Package, registry_src: SourceId) -> CargoResult<()>
128
139
}
129
140
} else {
130
141
failure:: bail!(
131
- "crates cannot be published to crates.io with dependencies sourced from \
132
- a repository\n either publish `{}` as its own crate on crates.io and \
133
- specify a crates.io version as a dependency or pull it into this \
142
+ "crates cannot be published with dependencies sourced from \
143
+ a repository\n either publish `{}` as its own crate and \
144
+ specify a version as a dependency or pull it into this \
134
145
repository and specify it with a path and version\n (crate `{}` has \
135
146
repository path `{}`)",
136
147
dep. package_name( ) ,
0 commit comments