@@ -10,7 +10,7 @@ use crate::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor}
1010use crate :: core:: manifest:: Target ;
1111use crate :: core:: resolver:: CliFeatures ;
1212use crate :: core:: { registry:: PackageRegistry , resolver:: HasDevUnits } ;
13- use crate :: core:: { Feature , Shell , Verbosity , Workspace } ;
13+ use crate :: core:: { Feature , PackageIdSpecQuery , Shell , Verbosity , Workspace } ;
1414use crate :: core:: { Package , PackageId , PackageSet , Resolve , SourceId } ;
1515use crate :: sources:: PathSource ;
1616use crate :: util:: cache_lock:: CacheLockMode ;
@@ -176,10 +176,15 @@ pub fn package_one(
176176}
177177
178178pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Option < Vec < FileLock > > > {
179- let pkgs = ws. members_with_features (
180- & opts. to_package . to_package_id_specs ( ws) ?,
181- & opts. cli_features ,
182- ) ?;
179+ let specs = & opts. to_package . to_package_id_specs ( ws) ?;
180+ // If -p is used, we should check spec is matched with the members (See #13719)
181+ if let ops:: Packages :: Packages ( _) = opts. to_package {
182+ for spec in specs. iter ( ) {
183+ let member_ids = ws. members ( ) . map ( |p| p. package_id ( ) ) ;
184+ spec. query ( member_ids) ?;
185+ }
186+ }
187+ let pkgs = ws. members_with_features ( specs, & opts. cli_features ) ?;
183188
184189 let mut dsts = Vec :: with_capacity ( pkgs. len ( ) ) ;
185190
0 commit comments