@@ -619,7 +619,7 @@ impl ProjectWorkspace {
619
619
let extra_targets = cargo[ pkg]
620
620
. targets
621
621
. iter ( )
622
- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
622
+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
623
623
. filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
624
624
. map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
625
625
. filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -985,15 +985,15 @@ fn cargo_to_crate_graph(
985
985
986
986
let mut lib_tgt = None ;
987
987
for & tgt in cargo[ pkg] . targets . iter ( ) {
988
- if cargo[ tgt] . kind != TargetKind :: Lib && !cargo[ pkg] . is_member {
988
+ if ! matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) && !cargo[ pkg] . is_member {
989
989
// For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
990
990
// add any targets except the library target, since those will not work correctly if
991
991
// they use dev-dependencies.
992
992
// In fact, they can break quite badly if multiple client workspaces get merged:
993
993
// https://github.com/rust-lang/rust-analyzer/issues/11300
994
994
continue ;
995
995
}
996
- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
996
+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
997
997
998
998
let Some ( file_id) = load ( root) else { continue } ;
999
999
@@ -1005,19 +1005,24 @@ fn cargo_to_crate_graph(
1005
1005
cfg_options. clone ( ) ,
1006
1006
file_id,
1007
1007
name,
1008
- is_proc_macro ,
1008
+ kind ,
1009
1009
target_layout. clone ( ) ,
1010
1010
false ,
1011
1011
toolchain. cloned ( ) ,
1012
1012
) ;
1013
- if kind == TargetKind :: Lib {
1013
+ if let TargetKind :: Lib { .. } = kind {
1014
1014
lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
1015
1015
pkg_to_lib_crate. insert ( pkg, crate_id) ;
1016
1016
}
1017
1017
// Even crates that don't set proc-macro = true are allowed to depend on proc_macro
1018
1018
// (just none of the APIs work when called outside of a proc macro).
1019
1019
if let Some ( proc_macro) = libproc_macro {
1020
- add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
1020
+ add_proc_macro_dep (
1021
+ crate_graph,
1022
+ crate_id,
1023
+ proc_macro,
1024
+ matches ! ( kind, TargetKind :: Lib { is_proc_macro: true } ) ,
1025
+ ) ;
1021
1026
}
1022
1027
1023
1028
pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1215,9 +1220,9 @@ fn handle_rustc_crates(
1215
1220
} ;
1216
1221
1217
1222
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1218
- if rustc_workspace [ tgt ] . kind != TargetKind :: Lib {
1223
+ let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace [ tgt ] . kind else {
1219
1224
continue ;
1220
- }
1225
+ } ;
1221
1226
if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
1222
1227
let crate_id = add_target_crate_root (
1223
1228
crate_graph,
@@ -1227,7 +1232,7 @@ fn handle_rustc_crates(
1227
1232
cfg_options. clone ( ) ,
1228
1233
file_id,
1229
1234
& rustc_workspace[ tgt] . name ,
1230
- rustc_workspace [ tgt ] . is_proc_macro ,
1235
+ kind ,
1231
1236
target_layout. clone ( ) ,
1232
1237
true ,
1233
1238
toolchain. cloned ( ) ,
@@ -1236,12 +1241,7 @@ fn handle_rustc_crates(
1236
1241
// Add dependencies on core / std / alloc for this crate
1237
1242
public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
1238
1243
if let Some ( proc_macro) = libproc_macro {
1239
- add_proc_macro_dep (
1240
- crate_graph,
1241
- crate_id,
1242
- proc_macro,
1243
- rustc_workspace[ tgt] . is_proc_macro ,
1244
- ) ;
1244
+ add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
1245
1245
}
1246
1246
rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
1247
1247
}
@@ -1303,7 +1303,7 @@ fn add_target_crate_root(
1303
1303
cfg_options : CfgOptions ,
1304
1304
file_id : FileId ,
1305
1305
cargo_name : & str ,
1306
- is_proc_macro : bool ,
1306
+ kind : TargetKind ,
1307
1307
target_layout : TargetLayoutLoadResult ,
1308
1308
rustc_crate : bool ,
1309
1309
toolchain : Option < Version > ,
@@ -1353,7 +1353,7 @@ fn add_target_crate_root(
1353
1353
cfg_options,
1354
1354
potential_cfg_options,
1355
1355
env,
1356
- is_proc_macro,
1356
+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
1357
1357
if rustc_crate {
1358
1358
CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
1359
1359
} else if pkg. is_member {
@@ -1364,7 +1364,7 @@ fn add_target_crate_root(
1364
1364
target_layout,
1365
1365
toolchain,
1366
1366
) ;
1367
- if is_proc_macro {
1367
+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
1368
1368
let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
1369
1369
Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
1370
1370
None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments