@@ -586,7 +586,7 @@ impl ProjectWorkspace {
586
586
let extra_targets = cargo[ pkg]
587
587
. targets
588
588
. iter ( )
589
- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
589
+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
590
590
. filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
591
591
. map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
592
592
. filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -949,17 +949,17 @@ fn cargo_to_crate_graph(
949
949
950
950
let mut lib_tgt = None ;
951
951
for & tgt in cargo[ pkg] . targets . iter ( ) {
952
- if cargo[ tgt] . kind != TargetKind :: Lib && !cargo[ pkg] . is_member {
952
+ if ! matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) && !cargo[ pkg] . is_member {
953
953
// For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
954
954
// add any targets except the library target, since those will not work correctly if
955
955
// they use dev-dependencies.
956
956
// In fact, they can break quite badly if multiple client workspaces get merged:
957
957
// https://github.com/rust-lang/rust-analyzer/issues/11300
958
958
continue ;
959
959
}
960
- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
960
+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
961
961
962
- if kind == TargetKind :: Lib
962
+ if matches ! ( kind, TargetKind :: Lib { .. } )
963
963
&& sysroot. map_or ( false , |sysroot| root. starts_with ( sysroot. src_root ( ) ) )
964
964
{
965
965
if let Some ( & ( _, crate_id, _) ) =
@@ -984,19 +984,24 @@ fn cargo_to_crate_graph(
984
984
cfg_options. clone ( ) ,
985
985
file_id,
986
986
name,
987
- is_proc_macro ,
987
+ kind ,
988
988
target_layout. clone ( ) ,
989
989
false ,
990
990
toolchain. cloned ( ) ,
991
991
) ;
992
- if kind == TargetKind :: Lib {
992
+ if let TargetKind :: Lib { .. } = kind {
993
993
lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
994
994
pkg_to_lib_crate. insert ( pkg, crate_id) ;
995
995
}
996
996
// Even crates that don't set proc-macro = true are allowed to depend on proc_macro
997
997
// (just none of the APIs work when called outside of a proc macro).
998
998
if let Some ( proc_macro) = libproc_macro {
999
- add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
999
+ add_proc_macro_dep (
1000
+ crate_graph,
1001
+ crate_id,
1002
+ proc_macro,
1003
+ matches ! ( kind, TargetKind :: Lib { is_proc_macro: true } ) ,
1004
+ ) ;
1000
1005
}
1001
1006
1002
1007
pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1194,9 +1199,9 @@ fn handle_rustc_crates(
1194
1199
} ;
1195
1200
1196
1201
for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1197
- if rustc_workspace [ tgt ] . kind != TargetKind :: Lib {
1202
+ let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace [ tgt ] . kind else {
1198
1203
continue ;
1199
- }
1204
+ } ;
1200
1205
if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
1201
1206
let crate_id = add_target_crate_root (
1202
1207
crate_graph,
@@ -1206,7 +1211,7 @@ fn handle_rustc_crates(
1206
1211
cfg_options. clone ( ) ,
1207
1212
file_id,
1208
1213
& rustc_workspace[ tgt] . name ,
1209
- rustc_workspace [ tgt ] . is_proc_macro ,
1214
+ kind ,
1210
1215
target_layout. clone ( ) ,
1211
1216
true ,
1212
1217
toolchain. cloned ( ) ,
@@ -1215,12 +1220,7 @@ fn handle_rustc_crates(
1215
1220
// Add dependencies on core / std / alloc for this crate
1216
1221
public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
1217
1222
if let Some ( proc_macro) = libproc_macro {
1218
- add_proc_macro_dep (
1219
- crate_graph,
1220
- crate_id,
1221
- proc_macro,
1222
- rustc_workspace[ tgt] . is_proc_macro ,
1223
- ) ;
1223
+ add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
1224
1224
}
1225
1225
rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
1226
1226
}
@@ -1282,7 +1282,7 @@ fn add_target_crate_root(
1282
1282
cfg_options : CfgOptions ,
1283
1283
file_id : FileId ,
1284
1284
cargo_name : & str ,
1285
- is_proc_macro : bool ,
1285
+ kind : TargetKind ,
1286
1286
target_layout : TargetLayoutLoadResult ,
1287
1287
rustc_crate : bool ,
1288
1288
toolchain : Option < Version > ,
@@ -1332,7 +1332,7 @@ fn add_target_crate_root(
1332
1332
cfg_options,
1333
1333
potential_cfg_options,
1334
1334
env,
1335
- is_proc_macro,
1335
+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
1336
1336
if rustc_crate {
1337
1337
CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
1338
1338
} else if pkg. is_member {
@@ -1343,7 +1343,7 @@ fn add_target_crate_root(
1343
1343
target_layout,
1344
1344
toolchain,
1345
1345
) ;
1346
- if is_proc_macro {
1346
+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
1347
1347
let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
1348
1348
Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
1349
1349
None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments