Skip to content

fix: Fix proc-macro paths using incorrect CrateId's for rust-project.json workspaces #14419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,9 @@ impl ExprCollector<'_> {
.collect(),
}
}
// FIXME: rustfmt removes this label if it is a block and not a loop
ast::Pat::LiteralPat(lit) => 'b: loop {
break if let Some(ast_lit) = lit.literal() {
#[rustfmt::skip] // https://github.com/rust-lang/rustfmt/issues/5676
ast::Pat::LiteralPat(lit) => 'b: {
if let Some(ast_lit) = lit.literal() {
let mut hir_lit: Literal = ast_lit.kind().into();
if lit.minus_token().is_some() {
let Some(h) = hir_lit.negate() else {
Expand All @@ -1099,7 +1099,7 @@ impl ExprCollector<'_> {
Pat::Lit(expr_id)
} else {
Pat::Missing
};
}
},
ast::Pat::RestPat(_) => {
// `RestPat` requires special handling and should not be mapped
Expand Down
66 changes: 32 additions & 34 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,7 @@ fn project_json_to_crate_graph(
})
.map(|(crate_id, krate, file_id)| {
let env = krate.env.clone().into_iter().collect();
if let Some(path) = krate.proc_macro_dylib_path.clone() {
proc_macros.insert(
crate_id,
Some((
krate.display_name.as_ref().map(|it| it.canonical_name().to_owned()),
path,
)),
);
}

let target_cfgs = match krate.target.as_deref() {
Some(target) => cfg_cache
.entry(target)
Expand All @@ -722,31 +714,37 @@ fn project_json_to_crate_graph(

let mut cfg_options = CfgOptions::default();
cfg_options.extend(target_cfgs.iter().chain(krate.cfg.iter()).cloned());
(
crate_id,
crate_graph.add_crate_root(
file_id,
krate.edition,
krate.display_name.clone(),
krate.version.clone(),
cfg_options.clone(),
cfg_options,
env,
krate.is_proc_macro,
if krate.display_name.is_some() {
CrateOrigin::CratesIo {
repo: krate.repository.clone(),
name: krate
.display_name
.clone()
.map(|n| n.canonical_name().to_string()),
}
} else {
CrateOrigin::CratesIo { repo: None, name: None }
},
target_layout.clone(),
),
)
let crate_graph_crate_id = crate_graph.add_crate_root(
file_id,
krate.edition,
krate.display_name.clone(),
krate.version.clone(),
cfg_options.clone(),
cfg_options,
env,
krate.is_proc_macro,
if krate.display_name.is_some() {
CrateOrigin::CratesIo {
repo: krate.repository.clone(),
name: krate.display_name.clone().map(|n| n.canonical_name().to_string()),
}
} else {
CrateOrigin::CratesIo { repo: None, name: None }
},
target_layout.clone(),
);
if krate.is_proc_macro {
if let Some(path) = krate.proc_macro_dylib_path.clone() {
proc_macros.insert(
crate_graph_crate_id,
Some((
krate.display_name.as_ref().map(|it| it.canonical_name().to_owned()),
path,
)),
);
}
}
(crate_id, crate_graph_crate_id)
})
.collect();

Expand Down