File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1890,7 +1890,24 @@ impl<'gctx> Workspace<'gctx> {
18901890 && !cli_features. all_features
18911891 && cli_features. uses_default_features )
18921892 {
1893- bail ! ( "cannot specify features for packages outside of workspace" ) ;
1893+ let hint = specs
1894+ . iter ( )
1895+ . find_map ( |spec| {
1896+ self . members ( )
1897+ . filter_map ( |member| {
1898+ edit_distance ( spec. name ( ) , member. name ( ) . as_str ( ) , 2 )
1899+ . map ( |distance| ( distance, member) )
1900+ } )
1901+ . min_by_key ( |( distance, _) | * distance)
1902+ . map ( |( _, member) | {
1903+ format ! (
1904+ "\n \n help: a workspace member with a similar name exists: `{}`" ,
1905+ member. name( )
1906+ )
1907+ } )
1908+ } )
1909+ . unwrap_or_default ( ) ;
1910+ bail ! ( "cannot specify features for packages outside of workspace{hint}" ) ;
18941911 }
18951912 // Add all members from the workspace so we can ensure `-p nonmember`
18961913 // is in the resolve graph.
Original file line number Diff line number Diff line change @@ -781,8 +781,8 @@ fn non_member() {
781781
782782#[ cargo_test]
783783fn non_member_typo ( ) {
784- // -p with a mistyped package name currently shows a misleading error
785- // without any hint about similar workspace member names .
784+ // -p with a mistyped package name shows a helpful error hint
785+ // about similarly named workspace members .
786786 let p = project ( )
787787 . file (
788788 "Cargo.toml" ,
@@ -801,6 +801,8 @@ fn non_member_typo() {
801801 . with_stderr_data ( str![ [ r#"
802802[ERROR] cannot specify features for packages outside of workspace
803803
804+ [HELP] a workspace member with a similar name exists: `bar`
805+
804806"# ] ] )
805807 . run ( ) ;
806808}
You can’t perform that action at this time.
0 commit comments