@@ -742,8 +742,8 @@ impl<'gctx> Workspace<'gctx> {
742
742
// self.root_manifest must be Some to have retrieved workspace_config
743
743
let root_manifest_path = self . root_manifest . clone ( ) . unwrap ( ) ;
744
744
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 ( ) ) ?;
747
747
let default_members_paths = if root_manifest_path == self . current_manifest {
748
748
if let Some ( ref default) = workspace_config. default_members {
749
749
Some ( workspace_config. members_paths ( default) ?)
@@ -754,22 +754,23 @@ impl<'gctx> Workspace<'gctx> {
754
754
None
755
755
} ;
756
756
757
- for path in & members_paths {
757
+ for ( path, glob ) in & members_paths {
758
758
self . find_path_deps ( & path. join ( "Cargo.toml" ) , & root_manifest_path, false )
759
759
. with_context ( || {
760
760
format ! (
761
761
"failed to load manifest for workspace member `{}`\n \
762
- referenced by workspace at `{}`",
762
+ referenced{} by workspace at `{}`",
763
763
path. display( ) ,
764
- root_manifest_path. display( )
764
+ glob. map( |g| format!( " via `{g}`" ) ) . unwrap_or_default( ) ,
765
+ root_manifest_path. display( ) ,
765
766
)
766
767
} ) ?;
767
768
}
768
769
769
770
self . find_path_deps ( & root_manifest_path, & root_manifest_path, false ) ?;
770
771
771
772
if let Some ( default) = default_members_paths {
772
- for path in default {
773
+ for ( path, default_member_glob ) in default {
773
774
let normalized_path = paths:: normalize_path ( & path) ;
774
775
let manifest_path = normalized_path. join ( "Cargo.toml" ) ;
775
776
if !self . members . contains ( & manifest_path) {
@@ -779,16 +780,19 @@ impl<'gctx> Workspace<'gctx> {
779
780
// manifest path, both because `members_paths` doesn't
780
781
// include `/Cargo.toml`, and because excluded paths may not
781
782
// be crates.
782
- let exclude = members_paths. contains ( & normalized_path)
783
+ let exclude = members_paths. iter ( ) . any ( | ( m , _ ) | * m == normalized_path)
783
784
&& workspace_config. is_excluded ( & normalized_path) ;
784
785
if exclude {
785
786
continue ;
786
787
}
787
788
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 `{}` .",
790
791
path. display( ) ,
791
- root_manifest_path. display( )
792
+ default_member_glob
793
+ . map( |g| format!( " via `{g}`" ) )
794
+ . unwrap_or_default( ) ,
795
+ root_manifest_path. display( ) ,
792
796
)
793
797
}
794
798
self . default_members . push ( manifest_path)
@@ -1872,8 +1876,13 @@ impl WorkspaceRootConfig {
1872
1876
self . members . is_some ( )
1873
1877
}
1874
1878
1879
+ /// Returns expanded paths along with the glob that they were expanded from.
1880
+ /// The glob is `None` if the path matched exactly.
1875
1881
#[ 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 > ) > > {
1877
1886
let mut expanded_list = Vec :: new ( ) ;
1878
1887
1879
1888
for glob in globs {
@@ -1883,16 +1892,19 @@ impl WorkspaceRootConfig {
1883
1892
// If glob does not find any valid paths, then put the original
1884
1893
// path in the expanded list to maintain backwards compatibility.
1885
1894
if expanded_paths. is_empty ( ) {
1886
- expanded_list. push ( pathbuf) ;
1895
+ expanded_list. push ( ( pathbuf, None ) ) ;
1887
1896
} 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
+
1888
1900
// Some OS can create system support files anywhere.
1889
1901
// (e.g. macOS creates `.DS_Store` file if you visit a directory using Finder.)
1890
1902
// Such files can be reported as a member path unexpectedly.
1891
1903
// Check and filter out non-directory paths to prevent pushing such accidental unwanted path
1892
1904
// as a member.
1893
1905
for expanded_path in expanded_paths {
1894
1906
if expanded_path. is_dir ( ) {
1895
- expanded_list. push ( expanded_path) ;
1907
+ expanded_list. push ( ( expanded_path, glob ) ) ;
1896
1908
}
1897
1909
}
1898
1910
}
0 commit comments