@@ -201,3 +201,105 @@ warning: unused optional dependency
201
201
)
202
202
. run ( ) ;
203
203
}
204
+
205
+ #[ cargo_test( nightly, reason = "edition2024 is not stable" ) ]
206
+ fn inactive_weak_optional_dep ( ) {
207
+ Package :: new ( "dep_name" , "0.1.0" )
208
+ . feature ( "dep_feature" , & [ ] )
209
+ . publish ( ) ;
210
+
211
+ // `dep_name`` is included as a weak optional dependency throught speficying the `dep_name?/dep_feature` in feature table.
212
+ // In edition2024, `dep_name` need to be add `dep:dep_name` to feature table to speficying activate it.
213
+
214
+ // This test explain the conclusion mentioned above
215
+ let p = project ( )
216
+ . file (
217
+ "Cargo.toml" ,
218
+ r#"
219
+ cargo-features = ["edition2024"]
220
+ [package]
221
+ name = "foo"
222
+ version = "0.1.0"
223
+ edition = "2024"
224
+
225
+ [dependencies]
226
+ dep_name = { version = "0.1.0", optional = true }
227
+
228
+ [features]
229
+ foo_feature = ["dep:dep_name", "dep_name?/dep_feature"]
230
+ "# ,
231
+ )
232
+ . file ( "src/lib.rs" , "" )
233
+ . build ( ) ;
234
+ p. cargo ( "check -Zcargo-lints" )
235
+ . masquerade_as_nightly_cargo ( & [ "cargo-lints" , "edition2024" ] )
236
+ . run ( ) ;
237
+
238
+ // This test proves no regression when dep_name isn't included
239
+ let p = project ( )
240
+ . file (
241
+ "Cargo.toml" ,
242
+ r#"
243
+ cargo-features = ["edition2024"]
244
+ [package]
245
+ name = "foo"
246
+ version = "0.1.0"
247
+ edition = "2024"
248
+
249
+ [dependencies]
250
+
251
+ [features]
252
+ foo_feature = ["dep_name?/dep_feature"]
253
+ "# ,
254
+ )
255
+ . file ( "src/lib.rs" , "" )
256
+ . build ( ) ;
257
+
258
+ p. cargo ( "check -Zcargo-lints" )
259
+ . masquerade_as_nightly_cargo ( & [ "cargo-lints" , "edition2024" ] )
260
+ . with_status ( 101 )
261
+ . with_stderr (
262
+ "\
263
+ error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
264
+
265
+ Caused by:
266
+ feature `foo_feature` includes `dep_name?/dep_feature`, but `dep_name` is not a dependency
267
+ " ,
268
+ )
269
+ . run ( ) ;
270
+
271
+ // This test is that we need to improve in edition2024, we need to tell that a weak optioanl dependency needs specify
272
+ // the `dep:` syntax, like `dep:dep_name`.
273
+ let p = project ( )
274
+ . file (
275
+ "Cargo.toml" ,
276
+ r#"
277
+ cargo-features = ["edition2024"]
278
+ [package]
279
+ name = "foo"
280
+ version = "0.1.0"
281
+ edition = "2024"
282
+
283
+ [dependencies]
284
+ dep_name = { version = "0.1.0", optional = true }
285
+
286
+ [features]
287
+ foo_feature = ["dep_name?/dep_feature"]
288
+ "# ,
289
+ )
290
+ . file ( "src/lib.rs" , "" )
291
+ . build ( ) ;
292
+
293
+ p. cargo ( "check -Zcargo-lints" )
294
+ . masquerade_as_nightly_cargo ( & [ "cargo-lints" , "edition2024" ] )
295
+ . with_status ( 101 )
296
+ . with_stderr (
297
+ "\
298
+ error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
299
+
300
+ Caused by:
301
+ feature `foo_feature` includes `dep_name?/dep_feature`, but `dep_name` is not a dependency
302
+ " ,
303
+ )
304
+ . run ( ) ;
305
+ }
0 commit comments