File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,8 @@ impl Dependency {
301301
302302 /// Sets whether the dependency is public.
303303 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 ) ;
304306 Rc :: make_mut ( & mut self . inner ) . public = public;
305307 self
306308 }
Original file line number Diff line number Diff line change @@ -1465,6 +1465,11 @@ impl DetailedTomlDependency {
14651465
14661466 if let Some ( p) = self . public {
14671467 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+
14681473 dep. set_public ( p) ;
14691474 }
14701475 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
159159 )
160160 . run ( )
161161}
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