@@ -795,3 +795,67 @@ windows
795
795
)
796
796
. run ( ) ;
797
797
}
798
+
799
+ #[ cargo_test]
800
+ fn precedence ( ) {
801
+ // Ensure that the precedence of cargo-rustc is only lower than RUSTFLAGS,
802
+ // but higher than most flags set by cargo.
803
+ //
804
+ // See rust-lang/cargo#14346
805
+ let p = project ( )
806
+ . file (
807
+ "Cargo.toml" ,
808
+ r#"
809
+ [package]
810
+ name = "foo"
811
+ edition = "2021"
812
+
813
+ [lints.rust]
814
+ unexpected_cfgs = "allow"
815
+ "# ,
816
+ )
817
+ . file ( "src/lib.rs" , "" )
818
+ . build ( ) ;
819
+
820
+ p. cargo ( "rustc --release -v -- --cfg cargo_rustc -C strip=symbols" )
821
+ . env ( "RUSTFLAGS" , "--cfg from_rustflags" )
822
+ . with_stderr_data (
823
+ str![ [ r#"
824
+ [COMPILING] foo v0.0.0 ([ROOT]/foo)
825
+ [RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
826
+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
827
+
828
+ "# ] ]
829
+ )
830
+ . run ( ) ;
831
+
832
+ // Ensure the short-live env var to work
833
+ p. cargo ( "clean" ) . run ( ) ;
834
+ p. cargo ( "rustc --release -v -- --cfg cargo_rustc -C strip=symbols" )
835
+ . env ( "RUSTFLAGS" , "--cfg from_rustflags" )
836
+ . env ( "__CARGO_RUSTC_ORIG_ARGS_PRIO" , "1" )
837
+ . masquerade_as_nightly_cargo ( & [ "cargo-rustc-precedence" ] )
838
+ . with_stderr_data (
839
+ str![ [ r#"
840
+ [COMPILING] foo v0.0.0 ([ROOT]/foo)
841
+ [RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
842
+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
843
+
844
+ "# ] ]
845
+ )
846
+ . run ( ) ;
847
+
848
+ // Ensure non-nightly to work as before
849
+ p. cargo ( "clean" ) . run ( ) ;
850
+ p. cargo ( "rustc --release -v -- --cfg cargo_rustc -C strip=symbols" )
851
+ . env ( "RUSTFLAGS" , "--cfg from_rustflags" )
852
+ . with_stderr_data (
853
+ str![ [ r#"
854
+ [COMPILING] foo v0.0.0 ([ROOT]/foo)
855
+ [RUNNING] `rustc [..]--cfg cargo_rustc -C strip=symbols [..]-C strip=debuginfo [..]--cfg from_rustflags`
856
+ [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
857
+
858
+ "# ] ]
859
+ )
860
+ . run ( ) ;
861
+ }
0 commit comments