File tree 3 files changed +51
-0
lines changed
3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,8 @@ impl Dependency {
301
301
302
302
/// Sets whether the dependency is public.
303
303
pub fn set_public ( & mut self , public : bool ) -> & mut Dependency {
304
+ // Setting 'public' only makes sense for normal dependencies
305
+ assert_eq ! ( self . kind( ) , Kind :: Normal ) ;
304
306
Rc :: make_mut ( & mut self . inner ) . public = public;
305
307
self
306
308
}
Original file line number Diff line number Diff line change @@ -1465,6 +1465,11 @@ impl DetailedTomlDependency {
1465
1465
1466
1466
if let Some ( p) = self . public {
1467
1467
cx. features . require ( Feature :: public_dependency ( ) ) ?;
1468
+
1469
+ if dep. kind ( ) != Kind :: Normal {
1470
+ bail ! ( "'public' specifier can only be used on regular dependencies, not {:?} dependencies" , dep. kind( ) ) ;
1471
+ }
1472
+
1468
1473
dep. set_public ( p) ;
1469
1474
}
1470
1475
Ok ( dep)
Original file line number Diff line number Diff line change @@ -159,3 +159,47 @@ consider adding `cargo-features = [\"public-dependency\"]` to the manifest
159
159
)
160
160
. run ( )
161
161
}
162
+
163
+
164
+ #[ test]
165
+ fn pub_dev_dependency ( ) {
166
+ Package :: new ( "pub_dep" , "0.1.0" )
167
+ . file ( "src/lib.rs" , "pub struct FromPub;" )
168
+ . publish ( ) ;
169
+
170
+ let p = project ( )
171
+ . file (
172
+ "Cargo.toml" ,
173
+ r#"
174
+ cargo-features = ["public-dependency"]
175
+
176
+ [package]
177
+ name = "foo"
178
+ version = "0.0.1"
179
+
180
+ [dev-dependencies]
181
+ pub_dep = {version = "0.1.0", public = true}
182
+ "# ,
183
+ )
184
+ . file (
185
+ "src/lib.rs" ,
186
+ "
187
+ extern crate pub_dep;
188
+ pub fn use_pub(_: pub_dep::FromPub) {}
189
+ " ,
190
+ )
191
+ . build ( ) ;
192
+
193
+ p. cargo ( "build --message-format=short" )
194
+ . masquerade_as_nightly_cargo ( )
195
+ . with_status ( 101 )
196
+ . with_stderr (
197
+ "\
198
+ error: failed to parse manifest at `[..]`
199
+
200
+ Caused by:
201
+ 'public' specifier can only be used on regular dependencies, not Development dependencies
202
+ " ,
203
+ )
204
+ . run ( )
205
+ }
You can’t perform that action at this time.
0 commit comments