@@ -619,7 +619,7 @@ impl ProjectWorkspace {
619619 let extra_targets = cargo[ pkg]
620620 . targets
621621 . iter ( )
622- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
622+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
623623 . filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
624624 . map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
625625 . filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -985,15 +985,15 @@ fn cargo_to_crate_graph(
985985
986986 let mut lib_tgt = None ;
987987 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 {
989989 // For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
990990 // add any targets except the library target, since those will not work correctly if
991991 // they use dev-dependencies.
992992 // In fact, they can break quite badly if multiple client workspaces get merged:
993993 // https://github.com/rust-lang/rust-analyzer/issues/11300
994994 continue ;
995995 }
996- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
996+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
997997
998998 let Some ( file_id) = load ( root) else { continue } ;
999999
@@ -1005,19 +1005,24 @@ fn cargo_to_crate_graph(
10051005 cfg_options. clone ( ) ,
10061006 file_id,
10071007 name,
1008- is_proc_macro ,
1008+ kind ,
10091009 target_layout. clone ( ) ,
10101010 false ,
10111011 toolchain. cloned ( ) ,
10121012 ) ;
1013- if kind == TargetKind :: Lib {
1013+ if let TargetKind :: Lib { .. } = kind {
10141014 lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
10151015 pkg_to_lib_crate. insert ( pkg, crate_id) ;
10161016 }
10171017 // Even crates that don't set proc-macro = true are allowed to depend on proc_macro
10181018 // (just none of the APIs work when called outside of a proc macro).
10191019 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+ ) ;
10211026 }
10221027
10231028 pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1215,9 +1220,9 @@ fn handle_rustc_crates(
12151220 } ;
12161221
12171222 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 {
12191224 continue ;
1220- }
1225+ } ;
12211226 if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
12221227 let crate_id = add_target_crate_root (
12231228 crate_graph,
@@ -1227,7 +1232,7 @@ fn handle_rustc_crates(
12271232 cfg_options. clone ( ) ,
12281233 file_id,
12291234 & rustc_workspace[ tgt] . name ,
1230- rustc_workspace [ tgt ] . is_proc_macro ,
1235+ kind ,
12311236 target_layout. clone ( ) ,
12321237 true ,
12331238 toolchain. cloned ( ) ,
@@ -1236,12 +1241,7 @@ fn handle_rustc_crates(
12361241 // Add dependencies on core / std / alloc for this crate
12371242 public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
12381243 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) ;
12451245 }
12461246 rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
12471247 }
@@ -1303,7 +1303,7 @@ fn add_target_crate_root(
13031303 cfg_options : CfgOptions ,
13041304 file_id : FileId ,
13051305 cargo_name : & str ,
1306- is_proc_macro : bool ,
1306+ kind : TargetKind ,
13071307 target_layout : TargetLayoutLoadResult ,
13081308 rustc_crate : bool ,
13091309 toolchain : Option < Version > ,
@@ -1353,7 +1353,7 @@ fn add_target_crate_root(
13531353 cfg_options,
13541354 potential_cfg_options,
13551355 env,
1356- is_proc_macro,
1356+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
13571357 if rustc_crate {
13581358 CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
13591359 } else if pkg. is_member {
@@ -1364,7 +1364,7 @@ fn add_target_crate_root(
13641364 target_layout,
13651365 toolchain,
13661366 ) ;
1367- if is_proc_macro {
1367+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
13681368 let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
13691369 Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
13701370 None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments