@@ -547,7 +547,7 @@ impl ProjectWorkspace {
547
547
let extra_targets = cargo[ pkg]
548
548
. targets
549
549
. iter ( )
550
- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
550
+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
551
551
. filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
552
552
. map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
553
553
. filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -912,17 +912,17 @@ fn cargo_to_crate_graph(
912
912
913
913
let mut lib_tgt = None ;
914
914
for & tgt in cargo[ pkg] . targets . iter ( ) {
915
- if cargo[ tgt] . kind != TargetKind :: Lib && !cargo[ pkg] . is_member {
915
+ if ! matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) && !cargo[ pkg] . is_member {
916
916
// For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
917
917
// add any targets except the library target, since those will not work correctly if
918
918
// they use dev-dependencies.
919
919
// In fact, they can break quite badly if multiple client workspaces get merged:
920
920
// https://github.com/rust-lang/rust-analyzer/issues/11300
921
921
continue ;
922
922
}
923
- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
923
+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
924
924
925
- if kind == TargetKind :: Lib
925
+ if matches ! ( kind, TargetKind :: Lib { .. } )
926
926
&& sysroot. map_or ( false , |sysroot| root. starts_with ( sysroot. src_root ( ) ) )
927
927
{
928
928
if let Some ( & ( _, crate_id, _) ) =
@@ -947,19 +947,24 @@ fn cargo_to_crate_graph(
947
947
cfg_options. clone ( ) ,
948
948
file_id,
949
949
name,
950
- is_proc_macro ,
950
+ kind ,
951
951
target_layout. clone ( ) ,
952
952
false ,
953
953
toolchain. cloned ( ) ,
954
954
) ;
955
- if kind == TargetKind :: Lib {
955
+ if let TargetKind :: Lib { .. } = kind {
956
956
lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
957
957
pkg_to_lib_crate. insert ( pkg, crate_id) ;
958
958
}
959
959
// Even crates that don't set proc-macro = true are allowed to depend on proc_macro
960
960
// (just none of the APIs work when called outside of a proc macro).
961
961
if let Some ( proc_macro) = libproc_macro {
962
- add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
962
+ add_proc_macro_dep (
963
+ crate_graph,
964
+ crate_id,
965
+ proc_macro,
966
+ matches ! ( kind, TargetKind :: Lib { is_proc_macro: true } ) ,
967
+ ) ;
963
968
}
964
969
965
970
pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1157,9 +1162,9 @@ fn handle_rustc_crates(
1157
1162
} ;
1158
1163
1159
1164
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1160
- if rustc_workspace [ tgt ] . kind != TargetKind :: Lib {
1165
+ let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace [ tgt ] . kind else {
1161
1166
continue ;
1162
- }
1167
+ } ;
1163
1168
if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
1164
1169
let crate_id = add_target_crate_root (
1165
1170
crate_graph,
@@ -1169,7 +1174,7 @@ fn handle_rustc_crates(
1169
1174
cfg_options. clone ( ) ,
1170
1175
file_id,
1171
1176
& rustc_workspace[ tgt] . name ,
1172
- rustc_workspace [ tgt ] . is_proc_macro ,
1177
+ kind ,
1173
1178
target_layout. clone ( ) ,
1174
1179
true ,
1175
1180
toolchain. cloned ( ) ,
@@ -1178,12 +1183,7 @@ fn handle_rustc_crates(
1178
1183
// Add dependencies on core / std / alloc for this crate
1179
1184
public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
1180
1185
if let Some ( proc_macro) = libproc_macro {
1181
- add_proc_macro_dep (
1182
- crate_graph,
1183
- crate_id,
1184
- proc_macro,
1185
- rustc_workspace[ tgt] . is_proc_macro ,
1186
- ) ;
1186
+ add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
1187
1187
}
1188
1188
rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
1189
1189
}
@@ -1245,7 +1245,7 @@ fn add_target_crate_root(
1245
1245
cfg_options : CfgOptions ,
1246
1246
file_id : FileId ,
1247
1247
cargo_name : & str ,
1248
- is_proc_macro : bool ,
1248
+ kind : TargetKind ,
1249
1249
target_layout : TargetLayoutLoadResult ,
1250
1250
rustc_crate : bool ,
1251
1251
toolchain : Option < Version > ,
@@ -1295,7 +1295,7 @@ fn add_target_crate_root(
1295
1295
cfg_options,
1296
1296
potential_cfg_options,
1297
1297
env,
1298
- is_proc_macro,
1298
+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
1299
1299
if rustc_crate {
1300
1300
CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
1301
1301
} else if pkg. is_member {
@@ -1306,7 +1306,7 @@ fn add_target_crate_root(
1306
1306
target_layout,
1307
1307
toolchain,
1308
1308
) ;
1309
- if is_proc_macro {
1309
+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
1310
1310
let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
1311
1311
Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
1312
1312
None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments