@@ -625,7 +625,7 @@ impl ProjectWorkspace {
625625 let extra_targets = cargo[ pkg]
626626 . targets
627627 . iter ( )
628- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
628+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
629629 . filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
630630 . map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
631631 . filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -991,15 +991,15 @@ fn cargo_to_crate_graph(
991991
992992 let mut lib_tgt = None ;
993993 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 {
995995 // For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
996996 // add any targets except the library target, since those will not work correctly if
997997 // they use dev-dependencies.
998998 // In fact, they can break quite badly if multiple client workspaces get merged:
999999 // https://github.com/rust-lang/rust-analyzer/issues/11300
10001000 continue ;
10011001 }
1002- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
1002+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
10031003
10041004 let Some ( file_id) = load ( root) else { continue } ;
10051005
@@ -1011,19 +1011,24 @@ fn cargo_to_crate_graph(
10111011 cfg_options. clone ( ) ,
10121012 file_id,
10131013 name,
1014- is_proc_macro ,
1014+ kind ,
10151015 target_layout. clone ( ) ,
10161016 false ,
10171017 toolchain. cloned ( ) ,
10181018 ) ;
1019- if kind == TargetKind :: Lib {
1019+ if let TargetKind :: Lib { .. } = kind {
10201020 lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
10211021 pkg_to_lib_crate. insert ( pkg, crate_id) ;
10221022 }
10231023 // Even crates that don't set proc-macro = true are allowed to depend on proc_macro
10241024 // (just none of the APIs work when called outside of a proc macro).
10251025 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+ ) ;
10271032 }
10281033
10291034 pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1221,9 +1226,9 @@ fn handle_rustc_crates(
12211226 } ;
12221227
12231228 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 {
12251230 continue ;
1226- }
1231+ } ;
12271232 if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
12281233 let crate_id = add_target_crate_root (
12291234 crate_graph,
@@ -1233,7 +1238,7 @@ fn handle_rustc_crates(
12331238 cfg_options. clone ( ) ,
12341239 file_id,
12351240 & rustc_workspace[ tgt] . name ,
1236- rustc_workspace [ tgt ] . is_proc_macro ,
1241+ kind ,
12371242 target_layout. clone ( ) ,
12381243 true ,
12391244 toolchain. cloned ( ) ,
@@ -1242,12 +1247,7 @@ fn handle_rustc_crates(
12421247 // Add dependencies on core / std / alloc for this crate
12431248 public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
12441249 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) ;
12511251 }
12521252 rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
12531253 }
@@ -1309,7 +1309,7 @@ fn add_target_crate_root(
13091309 cfg_options : CfgOptions ,
13101310 file_id : FileId ,
13111311 cargo_name : & str ,
1312- is_proc_macro : bool ,
1312+ kind : TargetKind ,
13131313 target_layout : TargetLayoutLoadResult ,
13141314 rustc_crate : bool ,
13151315 toolchain : Option < Version > ,
@@ -1359,7 +1359,7 @@ fn add_target_crate_root(
13591359 cfg_options,
13601360 potential_cfg_options,
13611361 env,
1362- is_proc_macro,
1362+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
13631363 if rustc_crate {
13641364 CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
13651365 } else if pkg. is_member {
@@ -1370,7 +1370,7 @@ fn add_target_crate_root(
13701370 target_layout,
13711371 toolchain,
13721372 ) ;
1373- if is_proc_macro {
1373+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
13741374 let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
13751375 Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
13761376 None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments