@@ -742,8 +742,8 @@ impl<'gctx> Workspace<'gctx> {
742742 // self.root_manifest must be Some to have retrieved workspace_config
743743 let root_manifest_path = self . root_manifest . clone ( ) . unwrap ( ) ;
744744
745- let members_paths =
746- workspace_config . members_paths ( workspace_config. members . as_ref ( ) . unwrap_or ( & vec ! [ ] ) ) ?;
745+ let members_paths = workspace_config
746+ . members_paths ( workspace_config. members . as_deref ( ) . unwrap_or_default ( ) ) ?;
747747 let default_members_paths = if root_manifest_path == self . current_manifest {
748748 if let Some ( ref default) = workspace_config. default_members {
749749 Some ( workspace_config. members_paths ( default) ?)
@@ -754,22 +754,23 @@ impl<'gctx> Workspace<'gctx> {
754754 None
755755 } ;
756756
757- for path in & members_paths {
757+ for ( path, glob ) in & members_paths {
758758 self . find_path_deps ( & path. join ( "Cargo.toml" ) , & root_manifest_path, false )
759759 . with_context ( || {
760760 format ! (
761761 "failed to load manifest for workspace member `{}`\n \
762- referenced by workspace at `{}`",
762+ referenced{} by workspace at `{}`",
763763 path. display( ) ,
764- root_manifest_path. display( )
764+ glob. map( |g| format!( " as `{g}`" ) ) . unwrap_or_default( ) ,
765+ root_manifest_path. display( ) ,
765766 )
766767 } ) ?;
767768 }
768769
769770 self . find_path_deps ( & root_manifest_path, & root_manifest_path, false ) ?;
770771
771772 if let Some ( default) = default_members_paths {
772- for path in default {
773+ for ( path, default_member_glob ) in default {
773774 let normalized_path = paths:: normalize_path ( & path) ;
774775 let manifest_path = normalized_path. join ( "Cargo.toml" ) ;
775776 if !self . members . contains ( & manifest_path) {
@@ -779,16 +780,19 @@ impl<'gctx> Workspace<'gctx> {
779780 // manifest path, both because `members_paths` doesn't
780781 // include `/Cargo.toml`, and because excluded paths may not
781782 // be crates.
782- let exclude = members_paths. contains ( & normalized_path)
783+ let exclude = members_paths. iter ( ) . any ( | ( m , _ ) | * m == normalized_path)
783784 && workspace_config. is_excluded ( & normalized_path) ;
784785 if exclude {
785786 continue ;
786787 }
787788 bail ! (
788- "package `{}` is listed in default-members but is not a member\n \
789- for workspace at {} .",
789+ "package `{}` is listed in default-members{} but is not a member\n \
790+ for workspace at `{}` .",
790791 path. display( ) ,
791- root_manifest_path. display( )
792+ default_member_glob
793+ . map( |g| format!( " as `{g}`" ) )
794+ . unwrap_or_default( ) ,
795+ root_manifest_path. display( ) ,
792796 )
793797 }
794798 self . default_members . push ( manifest_path)
@@ -1872,8 +1876,13 @@ impl WorkspaceRootConfig {
18721876 self . members . is_some ( )
18731877 }
18741878
1879+ /// Returns expanded paths along with the glob that they were expanded from.
1880+ /// The glob is `None` if the path matched exactly.
18751881 #[ tracing:: instrument( skip_all) ]
1876- fn members_paths ( & self , globs : & [ String ] ) -> CargoResult < Vec < PathBuf > > {
1882+ fn members_paths < ' g > (
1883+ & self ,
1884+ globs : & ' g [ String ] ,
1885+ ) -> CargoResult < Vec < ( PathBuf , Option < & ' g str > ) > > {
18771886 let mut expanded_list = Vec :: new ( ) ;
18781887
18791888 for glob in globs {
@@ -1883,16 +1892,19 @@ impl WorkspaceRootConfig {
18831892 // If glob does not find any valid paths, then put the original
18841893 // path in the expanded list to maintain backwards compatibility.
18851894 if expanded_paths. is_empty ( ) {
1886- expanded_list. push ( pathbuf) ;
1895+ expanded_list. push ( ( pathbuf, None ) ) ;
18871896 } else {
1897+ let used_glob_pattern = expanded_paths. len ( ) > 1 || expanded_paths[ 0 ] != pathbuf;
1898+ let glob = used_glob_pattern. then_some ( glob. as_str ( ) ) ;
1899+
18881900 // Some OS can create system support files anywhere.
18891901 // (e.g. macOS creates `.DS_Store` file if you visit a directory using Finder.)
18901902 // Such files can be reported as a member path unexpectedly.
18911903 // Check and filter out non-directory paths to prevent pushing such accidental unwanted path
18921904 // as a member.
18931905 for expanded_path in expanded_paths {
18941906 if expanded_path. is_dir ( ) {
1895- expanded_list. push ( expanded_path) ;
1907+ expanded_list. push ( ( expanded_path, glob ) ) ;
18961908 }
18971909 }
18981910 }
0 commit comments