@@ -807,3 +807,97 @@ fn disabled_weak_optional_deps() {
807807 "bar inside lockfile!\n {lockfile}" ,
808808 ) ;
809809}
810+
811+ #[ cargo_test]
812+ fn deferred_v4 ( ) {
813+ // A modified version of the deferred test from above to enable
814+ // an entire dependency in a deferred way.
815+ Package :: new ( "bar" , "1.0.0" )
816+ . feature ( "feat" , & [ "feat_dep" ] )
817+ . add_dep ( Dependency :: new ( "feat_dep" , "1.0" ) . optional ( true ) )
818+ . file ( "src/lib.rs" , "extern crate feat_dep;" )
819+ . publish ( ) ;
820+ Package :: new ( "dep" , "1.0.0" )
821+ . add_dep ( Dependency :: new ( "bar" , "1.0" ) . optional ( true ) )
822+ . feature ( "feat" , & [ "bar?/feat" ] )
823+ . publish ( ) ;
824+ Package :: new ( "bar_activator" , "1.0.0" )
825+ . feature_dep ( "dep" , "1.0" , & [ "bar" ] )
826+ . publish ( ) ;
827+ Package :: new ( "feat_dep" , "1.0.0" )
828+ . publish ( ) ;
829+ let p = project ( )
830+ . file (
831+ "Cargo.toml" ,
832+ r#"
833+ [package]
834+ name = "foo"
835+ version = "0.1.0"
836+
837+ [dependencies]
838+ dep = { version = "1.0", features = ["feat"] }
839+ bar_activator = "1.0"
840+ "# ,
841+ )
842+ . file ( "src/lib.rs" , "" )
843+ . build ( ) ;
844+
845+ p. cargo ( "check" )
846+ . with_stderr (
847+ "\
848+ [UPDATING] [..]
849+ [DOWNLOADING] crates ...
850+ [DOWNLOADED] feat_dep v1.0.0 [..]
851+ [DOWNLOADED] dep v1.0.0 [..]
852+ [DOWNLOADED] bar_activator v1.0.0 [..]
853+ [DOWNLOADED] bar v1.0.0 [..]
854+ [CHECKING] feat_dep v1.0.0
855+ [CHECKING] bar v1.0.0
856+ [CHECKING] dep v1.0.0
857+ [CHECKING] bar_activator v1.0.0
858+ [CHECKING] foo v0.1.0 [..]
859+ [FINISHED] [..]
860+ " ,
861+ )
862+ . run ( ) ;
863+ let lockfile = p. read_lockfile ( ) ;
864+
865+ assert ! (
866+ lockfile. contains( r#"version = 3"# ) ,
867+ "lockfile version is not 3!\n {lockfile}" ,
868+ ) ;
869+ // Previous behavior: feat_dep is inside lockfile.
870+ assert ! (
871+ lockfile. contains( r#"name = "feat_dep""# ) ,
872+ "feat_dep not found\n {lockfile}" ,
873+ ) ;
874+ // Update to new lockfile version
875+ let new_lockfile = lockfile. replace ( "version = 3" , "version = 4" ) ;
876+ p. change_file ( "Cargo.lock" , & new_lockfile) ;
877+
878+ // We should still compile feat_dep
879+ p. cargo ( "check" )
880+ . with_stderr (
881+ "\
882+ [CHECKING] feat_dep v1.0.0
883+ [CHECKING] bar v1.0.0
884+ [CHECKING] dep v1.0.0
885+ [CHECKING] bar_activator v1.0.0
886+ [CHECKING] foo v0.1.0 [..]
887+ [FINISHED] [..]
888+ " ,
889+ )
890+ . run ( ) ;
891+
892+ let lockfile = p. read_lockfile ( ) ;
893+ assert ! (
894+ lockfile. contains( r#"version = 4"# ) ,
895+ "lockfile version is not 4!\n {lockfile}" ,
896+ ) ;
897+ // New behavior: feat_dep is still there.
898+ assert ! (
899+ lockfile. contains( r#"name = "feat_dep""# ) ,
900+ "feat_dep not found\n {lockfile}" ,
901+ ) ;
902+
903+ }
0 commit comments