File tree Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,16 @@ pub trait ArgMatchesExt {
283283 if config. cli_unstable ( ) . avoid_dev_deps {
284284 ws. set_require_optional_deps ( false ) ;
285285 }
286+ if ws. is_virtual ( ) && !config. cli_unstable ( ) . package_features {
287+ for flag in & [ "features" , "all-features" , "no-default-features" ] {
288+ if self . _is_present ( flag) {
289+ bail ! (
290+ "--{} is not allowed in the root of a virtual workspace" ,
291+ flag
292+ ) ;
293+ }
294+ }
295+ }
286296 Ok ( ws)
287297 }
288298
Original file line number Diff line number Diff line change @@ -1988,3 +1988,72 @@ fn cli_parse_ok() {
19881988
19891989 p. cargo ( "run --features a b" ) . run ( ) ;
19901990}
1991+
1992+ #[ cargo_test]
1993+ fn virtual_ws_flags ( ) {
1994+ // Reject features flags in the root of a virtual workspace.
1995+ let p = project ( )
1996+ . file (
1997+ "Cargo.toml" ,
1998+ r#"
1999+ [workspace]
2000+ members = ["a"]
2001+ "# ,
2002+ )
2003+ . file (
2004+ "a/Cargo.toml" ,
2005+ r#"
2006+ [package]
2007+ name = "a"
2008+ version = "0.1.0"
2009+
2010+ [features]
2011+ f1 = []
2012+ "# ,
2013+ )
2014+ . file ( "a/src/lib.rs" , "" )
2015+ . build ( ) ;
2016+
2017+ p. cargo ( "build --features=f1" )
2018+ . with_stderr ( "[ERROR] --features is not allowed in the root of a virtual workspace" )
2019+ . with_status ( 101 )
2020+ . run ( ) ;
2021+
2022+ p. cargo ( "build --no-default-features" )
2023+ . with_stderr (
2024+ "[ERROR] --no-default-features is not allowed in the root of a virtual workspace" ,
2025+ )
2026+ . with_status ( 101 )
2027+ . run ( ) ;
2028+
2029+ p. cargo ( "build --all-features" )
2030+ . with_stderr ( "[ERROR] --all-features is not allowed in the root of a virtual workspace" )
2031+ . with_status ( 101 )
2032+ . run ( ) ;
2033+
2034+ // It's OK if cwd is in a member.
2035+ p. cargo ( "check --features=f1 -v" )
2036+ . cwd ( "a" )
2037+ . with_stderr (
2038+ "\
2039+ [CHECKING] a [..]
2040+ [RUNNING] `rustc --crate-name a a/src/lib.rs [..]--cfg [..]feature[..]f1[..]
2041+ [FINISHED] dev [..]
2042+ " ,
2043+ )
2044+ . run ( ) ;
2045+
2046+ p. cargo ( "clean" ) . run ( ) ;
2047+
2048+ // And -Zpackage-features is OK because it is designed to support this.
2049+ p. cargo ( "check --features=f1 -p a -Z package-features -v" )
2050+ . masquerade_as_nightly_cargo ( )
2051+ . with_stderr (
2052+ "\
2053+ [CHECKING] a [..]
2054+ [RUNNING] `rustc --crate-name a a/src/lib.rs [..]--cfg [..]feature[..]f1[..]
2055+ [FINISHED] dev [..]
2056+ " ,
2057+ )
2058+ . run ( ) ;
2059+ }
You can’t perform that action at this time.
0 commit comments