@@ -267,10 +267,11 @@ impl Metadata {
267
267
cargo_args. push ( "--no-default-features" . into ( ) ) ;
268
268
}
269
269
270
- let mut all_rustdoc_args = self . rustdoc_args . clone ( ) ;
270
+ let mut all_rustdoc_args = vec ! [ "--cfg" . into( ) , "docsrs" . into( ) ] ;
271
+ all_rustdoc_args. extend_from_slice ( & self . rustdoc_args ) ;
271
272
all_rustdoc_args. extend_from_slice ( rustdoc_args) ;
272
273
273
- if !self . rustc_args . is_empty ( ) || ! all_rustdoc_args. is_empty ( ) {
274
+ if !self . rustc_args . is_empty ( ) || all_rustdoc_args. len ( ) > 2 {
274
275
cargo_args. push ( "-Z" . into ( ) ) ;
275
276
cargo_args. push ( "unstable-options" . into ( ) ) ;
276
277
}
@@ -655,14 +656,20 @@ mod test_targets {
655
656
mod test_calculations {
656
657
use super :: * ;
657
658
658
- fn default_cargo_args ( ) -> Vec < String > {
659
- vec ! [ "rustdoc" . into( ) , "--lib" . into( ) , "-Zrustdoc-map" . into( ) ]
659
+ fn default_cargo_args ( extra_args : & [ String ] ) -> Vec < String > {
660
+ let mut args = vec ! [ "rustdoc" . into( ) , "--lib" . into( ) , "-Zrustdoc-map" . into( ) ] ;
661
+ args. extend_from_slice ( extra_args) ;
662
+ args. extend_from_slice ( & [
663
+ "--config" . into ( ) ,
664
+ r#"build.rustdocflags=["--cfg", "docsrs"]"# . into ( ) ,
665
+ ] ) ;
666
+ args
660
667
}
661
668
662
669
#[ test]
663
670
fn test_defaults ( ) {
664
671
let metadata = Metadata :: default ( ) ;
665
- assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , default_cargo_args( ) ) ;
672
+ assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , default_cargo_args( & [ ] ) ) ;
666
673
let env = metadata. environment_variables ( ) ;
667
674
assert_eq ! ( env. get( "DOCS_RS" ) . map( String :: as_str) , Some ( "1" ) ) ;
668
675
assert ! ( env. get( "RUSTDOCFLAGS" ) . is_none( ) ) ;
@@ -676,17 +683,15 @@ mod test_calculations {
676
683
all_features : true ,
677
684
..Metadata :: default ( )
678
685
} ;
679
- let mut expected_args = default_cargo_args ( ) ;
680
- expected_args. push ( "--all-features" . into ( ) ) ;
686
+ let expected_args = default_cargo_args ( & [ "--all-features" . into ( ) ] ) ;
681
687
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
682
688
683
689
// no default features
684
690
let metadata = Metadata {
685
691
no_default_features : true ,
686
692
..Metadata :: default ( )
687
693
} ;
688
- let mut expected_args = default_cargo_args ( ) ;
689
- expected_args. push ( "--no-default-features" . into ( ) ) ;
694
+ let expected_args = default_cargo_args ( & [ "--no-default-features" . into ( ) ] ) ;
690
695
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
691
696
692
697
// allow passing both even though it's nonsense; cargo will give an error anyway
@@ -695,9 +700,8 @@ mod test_calculations {
695
700
no_default_features : true ,
696
701
..Metadata :: default ( )
697
702
} ;
698
- let mut expected_args = default_cargo_args ( ) ;
699
- expected_args. push ( "--all-features" . into ( ) ) ;
700
- expected_args. push ( "--no-default-features" . into ( ) ) ;
703
+ let expected_args =
704
+ default_cargo_args ( & [ "--all-features" . into ( ) , "--no-default-features" . into ( ) ] ) ;
701
705
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
702
706
703
707
// explicit empty vec
@@ -711,6 +715,8 @@ mod test_calculations {
711
715
"-Zrustdoc-map" . into( ) ,
712
716
"--features" . into( ) ,
713
717
String :: new( ) ,
718
+ "--config" . into( ) ,
719
+ r#"build.rustdocflags=["--cfg", "docsrs"]"# . into( ) ,
714
720
] ;
715
721
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
716
722
@@ -725,6 +731,8 @@ mod test_calculations {
725
731
"-Zrustdoc-map" . into( ) ,
726
732
"--features" . into( ) ,
727
733
"some_feature" . into( ) ,
734
+ "--config" . into( ) ,
735
+ r#"build.rustdocflags=["--cfg", "docsrs"]"# . into( ) ,
728
736
] ;
729
737
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
730
738
@@ -739,6 +747,8 @@ mod test_calculations {
739
747
"-Zrustdoc-map" . into( ) ,
740
748
"--features" . into( ) ,
741
749
"feature1 feature2" . into( ) ,
750
+ "--config" . into( ) ,
751
+ r#"build.rustdocflags=["--cfg", "docsrs"]"# . into( ) ,
742
752
] ;
743
753
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
744
754
@@ -761,7 +771,7 @@ mod test_calculations {
761
771
"-Z" . into( ) ,
762
772
"unstable-options" . into( ) ,
763
773
"--config" . into( ) ,
764
- r#"build.rustdocflags=["-Z", "unstable-options", "--static-root-path", "/", "--cap-lints", "warn"]"# . into( ) ,
774
+ r#"build.rustdocflags=["--cfg", "docsrs", "- Z", "unstable-options", "--static-root-path", "/", "--cap-lints", "warn"]"# . into( ) ,
765
775
] ;
766
776
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
767
777
@@ -782,6 +792,8 @@ mod test_calculations {
782
792
"-Ztarget-applies-to-host" . into( ) ,
783
793
"--config" . into( ) ,
784
794
"host.rustflags=[\" --cfg\" , \" x\" ]" . into( ) ,
795
+ "--config" . into( ) ,
796
+ "build.rustdocflags=[\" --cfg\" , \" docsrs\" ]" . into( ) ,
785
797
] ;
786
798
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
787
799
@@ -794,6 +806,8 @@ mod test_calculations {
794
806
String :: from( "rustdoc" ) ,
795
807
"--lib" . into( ) ,
796
808
"-Zrustdoc-map" . into( ) ,
809
+ "--config" . into( ) ,
810
+ "build.rustdocflags=[\" --cfg\" , \" docsrs\" ]" . into( ) ,
797
811
"-Zbuild-std" . into( ) ,
798
812
] ;
799
813
assert_eq ! ( metadata. cargo_args( & [ ] , & [ ] ) , expected_args) ;
0 commit comments