@@ -1218,8 +1218,11 @@ fn get_example_candidates() -> Vec<clap_complete::CompletionCandidate> {
12181218 get_targets_from_metadata ( )
12191219 . unwrap_or_default ( )
12201220 . into_iter ( )
1221- . filter_map ( |target| match target. kind ( ) {
1222- TargetKind :: ExampleBin => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1221+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1222+ TargetKind :: ExampleBin => Some (
1223+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1224+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1225+ ) ,
12231226 _ => None ,
12241227 } )
12251228 . collect :: < Vec < _ > > ( )
@@ -1229,8 +1232,11 @@ fn get_bench_candidates() -> Vec<clap_complete::CompletionCandidate> {
12291232 get_targets_from_metadata ( )
12301233 . unwrap_or_default ( )
12311234 . into_iter ( )
1232- . filter_map ( |target| match target. kind ( ) {
1233- TargetKind :: Bench => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1235+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1236+ TargetKind :: Bench => Some (
1237+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1238+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1239+ ) ,
12341240 _ => None ,
12351241 } )
12361242 . collect :: < Vec < _ > > ( )
@@ -1240,8 +1246,11 @@ fn get_test_candidates() -> Vec<clap_complete::CompletionCandidate> {
12401246 get_targets_from_metadata ( )
12411247 . unwrap_or_default ( )
12421248 . into_iter ( )
1243- . filter_map ( |target| match target. kind ( ) {
1244- TargetKind :: Test => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1249+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1250+ TargetKind :: Test => Some (
1251+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1252+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1253+ ) ,
12451254 _ => None ,
12461255 } )
12471256 . collect :: < Vec < _ > > ( )
@@ -1251,14 +1260,17 @@ fn get_bin_candidates() -> Vec<clap_complete::CompletionCandidate> {
12511260 get_targets_from_metadata ( )
12521261 . unwrap_or_default ( )
12531262 . into_iter ( )
1254- . filter_map ( |target| match target. kind ( ) {
1255- TargetKind :: Bin => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1263+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1264+ TargetKind :: Bin => Some (
1265+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1266+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1267+ ) ,
12561268 _ => None ,
12571269 } )
12581270 . collect :: < Vec < _ > > ( )
12591271}
12601272
1261- fn get_targets_from_metadata ( ) -> CargoResult < Vec < Target > > {
1273+ fn get_targets_from_metadata ( ) -> CargoResult < Vec < ( InternedString , Target ) > > {
12621274 let cwd = std:: env:: current_dir ( ) ?;
12631275 let gctx = GlobalContext :: new ( shell:: Shell :: new ( ) , cwd. clone ( ) , cargo_home_with_cwd ( & cwd) ?) ;
12641276 let ws = Workspace :: new ( & find_root_manifest_for_wd ( & cwd) ?, & gctx) ?;
@@ -1267,7 +1279,7 @@ fn get_targets_from_metadata() -> CargoResult<Vec<Target>> {
12671279
12681280 let targets = packages
12691281 . into_iter ( )
1270- . flat_map ( |pkg| pkg. targets ( ) . into_iter ( ) . cloned ( ) )
1282+ . flat_map ( |pkg| pkg. targets ( ) . into_iter ( ) . cloned ( ) . map ( |t| ( pkg . name ( ) , t ) ) )
12711283 . collect :: < Vec < _ > > ( ) ;
12721284
12731285 Ok ( targets)
0 commit comments