You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### What does this PR try to resolve?
When you typo a feature name on the CLI, the error message isn't very
helpful. Concretely, I was testing a PR which adds a feature called
`cosmic_text` to enable a `cosmic-text` dependency, and got a correct
but unhelpful error message:
```rust
error: Package `scenes v0.0.0 ([ELIDED]/linebender/vello/examples/scenes)` does not have feature `cosmic-text`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
```
I had to dig into the Cargo.lock file to find out how to fix this.
### How should we test and review this PR?
Observe the new test cases
Copy file name to clipboardExpand all lines: tests/testsuite/features_namespaced.rs
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -418,6 +418,8 @@ regex
418
418
p.cargo("run --features lazy_static")
419
419
.with_stderr_data(str![[r#"
420
420
[ERROR] Package `foo v0.1.0 ([ROOT]/foo)` does not have feature `lazy_static`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
421
+
Dependency `lazy_static` would be enabled by these features:
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have the feature `testt`
408
410
411
+
[HELP] a feature with a similar name exists: `test`
412
+
409
413
"#]])
410
414
.run();
411
415
@@ -426,6 +430,169 @@ feature set
426
430
.run();
427
431
}
428
432
433
+
#[cargo_test]
434
+
fncommand_line_optional_dep(){
435
+
// Enabling a dependency used as a `dep:` errors helpfully
436
+
Package::new("bar","1.0.0").publish();
437
+
let p = project()
438
+
.file(
439
+
"Cargo.toml",
440
+
r#"
441
+
[package]
442
+
name = "a"
443
+
version = "0.1.0"
444
+
edition = "2015"
445
+
446
+
[features]
447
+
foo = ["dep:bar"]
448
+
449
+
[dependencies]
450
+
bar = { version = "1.0.0", optional = true }
451
+
"#,
452
+
)
453
+
.file("src/lib.rs",r#""#)
454
+
.build();
455
+
456
+
p.cargo("check --features bar")
457
+
.with_status(101)
458
+
.with_stderr_data(str![[r#"
459
+
[UPDATING] `dummy-registry` index
460
+
[LOCKING] 1 package to latest compatible version
461
+
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
462
+
Dependency `bar` would be enabled by these features:
463
+
- `foo`
464
+
465
+
"#]])
466
+
.run();
467
+
}
468
+
469
+
#[cargo_test]
470
+
fncommand_line_optional_dep_three_options(){
471
+
// Trying to enable an optional dependency used as a `dep:` errors helpfully, when there are three features which would enable the dependency
472
+
Package::new("bar","1.0.0").publish();
473
+
let p = project()
474
+
.file(
475
+
"Cargo.toml",
476
+
r#"
477
+
[package]
478
+
name = "a"
479
+
version = "0.1.0"
480
+
edition = "2015"
481
+
482
+
[features]
483
+
f1 = ["dep:bar"]
484
+
f2 = ["dep:bar"]
485
+
f3 = ["dep:bar"]
486
+
487
+
[dependencies]
488
+
bar = { version = "1.0.0", optional = true }
489
+
"#,
490
+
)
491
+
.file("src/lib.rs",r#""#)
492
+
.build();
493
+
494
+
p.cargo("check --features bar")
495
+
.with_status(101)
496
+
.with_stderr_data(str![[r#"
497
+
[UPDATING] `dummy-registry` index
498
+
[LOCKING] 1 package to latest compatible version
499
+
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
500
+
Dependency `bar` would be enabled by these features:
501
+
- `f1`
502
+
- `f2`
503
+
- `f3`
504
+
505
+
"#]])
506
+
.run();
507
+
}
508
+
509
+
#[cargo_test]
510
+
fncommand_line_optional_dep_many_options(){
511
+
// Trying to enable an optional dependency used as a `dep:` errors helpfully, when there are many features which would enable the dependency
512
+
Package::new("bar","1.0.0").publish();
513
+
let p = project()
514
+
.file(
515
+
"Cargo.toml",
516
+
r#"
517
+
[package]
518
+
name = "a"
519
+
version = "0.1.0"
520
+
edition = "2015"
521
+
522
+
[features]
523
+
f1 = ["dep:bar"]
524
+
f2 = ["dep:bar"]
525
+
f3 = ["dep:bar"]
526
+
f4 = ["dep:bar"]
527
+
528
+
[dependencies]
529
+
bar = { version = "1.0.0", optional = true }
530
+
"#,
531
+
)
532
+
.file("src/lib.rs",r#""#)
533
+
.build();
534
+
535
+
p.cargo("check --features bar")
536
+
.with_status(101)
537
+
.with_stderr_data(str![[r#"
538
+
[UPDATING] `dummy-registry` index
539
+
[LOCKING] 1 package to latest compatible version
540
+
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
541
+
Dependency `bar` would be enabled by these features:
542
+
- `f1`
543
+
- `f2`
544
+
- `f3`
545
+
...
546
+
547
+
"#]])
548
+
.run();
549
+
}
550
+
551
+
#[cargo_test]
552
+
fncommand_line_optional_dep_many_paths(){
553
+
// Trying to enable an optional dependency used as a `dep:` errors helpfully, when a features would enable the dependency in multiple ways
554
+
Package::new("bar","1.0.0")
555
+
.feature("a",&[])
556
+
.feature("b",&[])
557
+
.feature("c",&[])
558
+
.feature("d",&[])
559
+
.publish();
560
+
let p = project()
561
+
.file(
562
+
"Cargo.toml",
563
+
r#"
564
+
[package]
565
+
name = "a"
566
+
version = "0.1.0"
567
+
edition = "2015"
568
+
569
+
[features]
570
+
f1 = ["dep:bar", "bar/a", "bar/b"] # Remove the implicit feature
571
+
f2 = ["bar/b", "bar/c"] # Overlaps with previous
572
+
f3 = ["bar/d"] # No overlap with previous
573
+
574
+
[dependencies]
575
+
bar = { version = "1.0.0", optional = true }
576
+
"#,
577
+
)
578
+
.file("src/lib.rs",r#""#)
579
+
.build();
580
+
581
+
p.cargo("check --features bar")
582
+
.with_status(101)
583
+
.with_stderr_data(str![[r#"
584
+
[UPDATING] `dummy-registry` index
585
+
[LOCKING] 1 package to latest compatible version
586
+
[ERROR] Package `a v0.1.0 ([ROOT]/foo)` does not have feature `bar`. It has an optional dependency with that name, but that dependency uses the "dep:" syntax in the features table, so it does not have an implicit feature with that name.
587
+
Dependency `bar` would be enabled by these features:
588
+
- `f1`
589
+
- `f2`
590
+
- `f3`
591
+
592
+
"#]])
593
+
.run();
594
+
}
595
+
429
596
#[cargo_test]
430
597
fnvirtual_member_slash(){
431
598
// member slash feature syntax
@@ -655,6 +822,8 @@ m1-feature set
655
822
.with_stderr_data(str![[r#"
656
823
[ERROR] Package `member1 v0.1.0 ([ROOT]/foo/member1)` does not have the feature `m2-feature`
657
824
825
+
[HELP] a feature with a similar name exists: `m1-feature`
0 commit comments