@@ -625,7 +625,7 @@ impl ProjectWorkspace {
625
625
let extra_targets = cargo[ pkg]
626
626
. targets
627
627
. iter ( )
628
- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
628
+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
629
629
. filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
630
630
. map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
631
631
. filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -991,15 +991,15 @@ fn cargo_to_crate_graph(
991
991
992
992
let mut lib_tgt = None ;
993
993
for & tgt in cargo[ pkg] . targets . iter ( ) {
994
- if cargo[ tgt] . kind != TargetKind :: Lib && !cargo[ pkg] . is_member {
994
+ if ! matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) && !cargo[ pkg] . is_member {
995
995
// For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
996
996
// add any targets except the library target, since those will not work correctly if
997
997
// they use dev-dependencies.
998
998
// In fact, they can break quite badly if multiple client workspaces get merged:
999
999
// https://github.com/rust-lang/rust-analyzer/issues/11300
1000
1000
continue ;
1001
1001
}
1002
- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
1002
+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
1003
1003
1004
1004
let Some ( file_id) = load ( root) else { continue } ;
1005
1005
@@ -1011,19 +1011,24 @@ fn cargo_to_crate_graph(
1011
1011
cfg_options. clone ( ) ,
1012
1012
file_id,
1013
1013
name,
1014
- is_proc_macro ,
1014
+ kind ,
1015
1015
target_layout. clone ( ) ,
1016
1016
false ,
1017
1017
toolchain. cloned ( ) ,
1018
1018
) ;
1019
- if kind == TargetKind :: Lib {
1019
+ if let TargetKind :: Lib { .. } = kind {
1020
1020
lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
1021
1021
pkg_to_lib_crate. insert ( pkg, crate_id) ;
1022
1022
}
1023
1023
// Even crates that don't set proc-macro = true are allowed to depend on proc_macro
1024
1024
// (just none of the APIs work when called outside of a proc macro).
1025
1025
if let Some ( proc_macro) = libproc_macro {
1026
- add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
1026
+ add_proc_macro_dep (
1027
+ crate_graph,
1028
+ crate_id,
1029
+ proc_macro,
1030
+ matches ! ( kind, TargetKind :: Lib { is_proc_macro: true } ) ,
1031
+ ) ;
1027
1032
}
1028
1033
1029
1034
pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1221,9 +1226,9 @@ fn handle_rustc_crates(
1221
1226
} ;
1222
1227
1223
1228
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1224
- if rustc_workspace [ tgt ] . kind != TargetKind :: Lib {
1229
+ let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace [ tgt ] . kind else {
1225
1230
continue ;
1226
- }
1231
+ } ;
1227
1232
if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
1228
1233
let crate_id = add_target_crate_root (
1229
1234
crate_graph,
@@ -1233,7 +1238,7 @@ fn handle_rustc_crates(
1233
1238
cfg_options. clone ( ) ,
1234
1239
file_id,
1235
1240
& rustc_workspace[ tgt] . name ,
1236
- rustc_workspace [ tgt ] . is_proc_macro ,
1241
+ kind ,
1237
1242
target_layout. clone ( ) ,
1238
1243
true ,
1239
1244
toolchain. cloned ( ) ,
@@ -1242,12 +1247,7 @@ fn handle_rustc_crates(
1242
1247
// Add dependencies on core / std / alloc for this crate
1243
1248
public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
1244
1249
if let Some ( proc_macro) = libproc_macro {
1245
- add_proc_macro_dep (
1246
- crate_graph,
1247
- crate_id,
1248
- proc_macro,
1249
- rustc_workspace[ tgt] . is_proc_macro ,
1250
- ) ;
1250
+ add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
1251
1251
}
1252
1252
rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
1253
1253
}
@@ -1309,7 +1309,7 @@ fn add_target_crate_root(
1309
1309
cfg_options : CfgOptions ,
1310
1310
file_id : FileId ,
1311
1311
cargo_name : & str ,
1312
- is_proc_macro : bool ,
1312
+ kind : TargetKind ,
1313
1313
target_layout : TargetLayoutLoadResult ,
1314
1314
rustc_crate : bool ,
1315
1315
toolchain : Option < Version > ,
@@ -1359,7 +1359,7 @@ fn add_target_crate_root(
1359
1359
cfg_options,
1360
1360
potential_cfg_options,
1361
1361
env,
1362
- is_proc_macro,
1362
+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
1363
1363
if rustc_crate {
1364
1364
CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
1365
1365
} else if pkg. is_member {
@@ -1370,7 +1370,7 @@ fn add_target_crate_root(
1370
1370
target_layout,
1371
1371
toolchain,
1372
1372
) ;
1373
- if is_proc_macro {
1373
+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
1374
1374
let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
1375
1375
Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
1376
1376
None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments