@@ -547,7 +547,7 @@ impl ProjectWorkspace {
547547 let extra_targets = cargo[ pkg]
548548 . targets
549549 . iter ( )
550- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
550+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
551551 . filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
552552 . map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
553553 . filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -912,17 +912,17 @@ fn cargo_to_crate_graph(
912912
913913 let mut lib_tgt = None ;
914914 for & tgt in cargo[ pkg] . targets . iter ( ) {
915- if cargo[ tgt] . kind != TargetKind :: Lib && !cargo[ pkg] . is_member {
915+ if ! matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) && !cargo[ pkg] . is_member {
916916 // For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
917917 // add any targets except the library target, since those will not work correctly if
918918 // they use dev-dependencies.
919919 // In fact, they can break quite badly if multiple client workspaces get merged:
920920 // https://github.com/rust-lang/rust-analyzer/issues/11300
921921 continue ;
922922 }
923- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
923+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
924924
925- if kind == TargetKind :: Lib
925+ if matches ! ( kind, TargetKind :: Lib { .. } )
926926 && sysroot. map_or ( false , |sysroot| root. starts_with ( sysroot. src_root ( ) ) )
927927 {
928928 if let Some ( & ( _, crate_id, _) ) =
@@ -947,19 +947,24 @@ fn cargo_to_crate_graph(
947947 cfg_options. clone ( ) ,
948948 file_id,
949949 name,
950- is_proc_macro ,
950+ kind ,
951951 target_layout. clone ( ) ,
952952 false ,
953953 toolchain. cloned ( ) ,
954954 ) ;
955- if kind == TargetKind :: Lib {
955+ if let TargetKind :: Lib { .. } = kind {
956956 lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
957957 pkg_to_lib_crate. insert ( pkg, crate_id) ;
958958 }
959959 // Even crates that don't set proc-macro = true are allowed to depend on proc_macro
960960 // (just none of the APIs work when called outside of a proc macro).
961961 if let Some ( proc_macro) = libproc_macro {
962- add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
962+ add_proc_macro_dep (
963+ crate_graph,
964+ crate_id,
965+ proc_macro,
966+ matches ! ( kind, TargetKind :: Lib { is_proc_macro: true } ) ,
967+ ) ;
963968 }
964969
965970 pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1157,9 +1162,9 @@ fn handle_rustc_crates(
11571162 } ;
11581163
11591164 for & tgt in rustc_workspace[ pkg] . targets . iter ( ) {
1160- if rustc_workspace [ tgt ] . kind != TargetKind :: Lib {
1165+ let kind @ TargetKind :: Lib { is_proc_macro } = rustc_workspace [ tgt ] . kind else {
11611166 continue ;
1162- }
1167+ } ;
11631168 if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
11641169 let crate_id = add_target_crate_root (
11651170 crate_graph,
@@ -1169,7 +1174,7 @@ fn handle_rustc_crates(
11691174 cfg_options. clone ( ) ,
11701175 file_id,
11711176 & rustc_workspace[ tgt] . name ,
1172- rustc_workspace [ tgt ] . is_proc_macro ,
1177+ kind ,
11731178 target_layout. clone ( ) ,
11741179 true ,
11751180 toolchain. cloned ( ) ,
@@ -1178,12 +1183,7 @@ fn handle_rustc_crates(
11781183 // Add dependencies on core / std / alloc for this crate
11791184 public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
11801185 if let Some ( proc_macro) = libproc_macro {
1181- add_proc_macro_dep (
1182- crate_graph,
1183- crate_id,
1184- proc_macro,
1185- rustc_workspace[ tgt] . is_proc_macro ,
1186- ) ;
1186+ add_proc_macro_dep ( crate_graph, crate_id, proc_macro, is_proc_macro) ;
11871187 }
11881188 rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
11891189 }
@@ -1245,7 +1245,7 @@ fn add_target_crate_root(
12451245 cfg_options : CfgOptions ,
12461246 file_id : FileId ,
12471247 cargo_name : & str ,
1248- is_proc_macro : bool ,
1248+ kind : TargetKind ,
12491249 target_layout : TargetLayoutLoadResult ,
12501250 rustc_crate : bool ,
12511251 toolchain : Option < Version > ,
@@ -1295,7 +1295,7 @@ fn add_target_crate_root(
12951295 cfg_options,
12961296 potential_cfg_options,
12971297 env,
1298- is_proc_macro,
1298+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
12991299 if rustc_crate {
13001300 CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
13011301 } else if pkg. is_member {
@@ -1306,7 +1306,7 @@ fn add_target_crate_root(
13061306 target_layout,
13071307 toolchain,
13081308 ) ;
1309- if is_proc_macro {
1309+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
13101310 let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
13111311 Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
13121312 None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments