@@ -586,7 +586,7 @@ impl ProjectWorkspace {
586586 let extra_targets = cargo[ pkg]
587587 . targets
588588 . iter ( )
589- . filter ( |& & tgt| cargo[ tgt] . kind == TargetKind :: Lib )
589+ . filter ( |& & tgt| matches ! ( cargo[ tgt] . kind, TargetKind :: Lib { .. } ) )
590590 . filter_map ( |& tgt| cargo[ tgt] . root . parent ( ) )
591591 . map ( |tgt| tgt. normalize ( ) . to_path_buf ( ) )
592592 . filter ( |path| !path. starts_with ( & pkg_root) ) ;
@@ -949,17 +949,17 @@ fn cargo_to_crate_graph(
949949
950950 let mut lib_tgt = None ;
951951 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 {
953953 // For non-workspace-members, Cargo does not resolve dev-dependencies, so we don't
954954 // add any targets except the library target, since those will not work correctly if
955955 // they use dev-dependencies.
956956 // In fact, they can break quite badly if multiple client workspaces get merged:
957957 // https://github.com/rust-lang/rust-analyzer/issues/11300
958958 continue ;
959959 }
960- let & TargetData { ref name, kind, is_proc_macro , ref root, .. } = & cargo[ tgt] ;
960+ let & TargetData { ref name, kind, ref root, .. } = & cargo[ tgt] ;
961961
962- if kind == TargetKind :: Lib
962+ if matches ! ( kind, TargetKind :: Lib { .. } )
963963 && sysroot. map_or ( false , |sysroot| root. starts_with ( sysroot. src_root ( ) ) )
964964 {
965965 if let Some ( & ( _, crate_id, _) ) =
@@ -984,19 +984,24 @@ fn cargo_to_crate_graph(
984984 cfg_options. clone ( ) ,
985985 file_id,
986986 name,
987- is_proc_macro ,
987+ kind ,
988988 target_layout. clone ( ) ,
989989 false ,
990990 toolchain. cloned ( ) ,
991991 ) ;
992- if kind == TargetKind :: Lib {
992+ if let TargetKind :: Lib { .. } = kind {
993993 lib_tgt = Some ( ( crate_id, name. clone ( ) ) ) ;
994994 pkg_to_lib_crate. insert ( pkg, crate_id) ;
995995 }
996996 // Even crates that don't set proc-macro = true are allowed to depend on proc_macro
997997 // (just none of the APIs work when called outside of a proc macro).
998998 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+ ) ;
10001005 }
10011006
10021007 pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( ( crate_id, kind) ) ;
@@ -1194,9 +1199,9 @@ fn handle_rustc_crates(
11941199 } ;
11951200
11961201 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 {
11981203 continue ;
1199- }
1204+ } ;
12001205 if let Some ( file_id) = load ( & rustc_workspace[ tgt] . root ) {
12011206 let crate_id = add_target_crate_root (
12021207 crate_graph,
@@ -1206,7 +1211,7 @@ fn handle_rustc_crates(
12061211 cfg_options. clone ( ) ,
12071212 file_id,
12081213 & rustc_workspace[ tgt] . name ,
1209- rustc_workspace [ tgt ] . is_proc_macro ,
1214+ kind ,
12101215 target_layout. clone ( ) ,
12111216 true ,
12121217 toolchain. cloned ( ) ,
@@ -1215,12 +1220,7 @@ fn handle_rustc_crates(
12151220 // Add dependencies on core / std / alloc for this crate
12161221 public_deps. add_to_crate_graph ( crate_graph, crate_id) ;
12171222 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) ;
12241224 }
12251225 rustc_pkg_crates. entry ( pkg) . or_insert_with ( Vec :: new) . push ( crate_id) ;
12261226 }
@@ -1282,7 +1282,7 @@ fn add_target_crate_root(
12821282 cfg_options : CfgOptions ,
12831283 file_id : FileId ,
12841284 cargo_name : & str ,
1285- is_proc_macro : bool ,
1285+ kind : TargetKind ,
12861286 target_layout : TargetLayoutLoadResult ,
12871287 rustc_crate : bool ,
12881288 toolchain : Option < Version > ,
@@ -1332,7 +1332,7 @@ fn add_target_crate_root(
13321332 cfg_options,
13331333 potential_cfg_options,
13341334 env,
1335- is_proc_macro,
1335+ matches ! ( kind , TargetKind :: Lib { is_proc_macro: true } ) ,
13361336 if rustc_crate {
13371337 CrateOrigin :: Rustc { name : pkg. name . clone ( ) }
13381338 } else if pkg. is_member {
@@ -1343,7 +1343,7 @@ fn add_target_crate_root(
13431343 target_layout,
13441344 toolchain,
13451345 ) ;
1346- if is_proc_macro {
1346+ if let TargetKind :: Lib { is_proc_macro : true } = kind {
13471347 let proc_macro = match build_data. as_ref ( ) . map ( |it| it. proc_macro_dylib_path . as_ref ( ) ) {
13481348 Some ( it) => it. cloned ( ) . map ( |path| Ok ( ( Some ( cargo_name. to_owned ( ) ) , path) ) ) ,
13491349 None => Some ( Err ( "crate has not yet been built" . to_owned ( ) ) ) ,
0 commit comments