Skip to content

Commit cf55624

Browse files
committed
Expand proc-macros in workspace root, not package root
1 parent 2025b43 commit cf55624

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

crates/hir-ty/src/display.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_apfloat::{
3434
};
3535
use smallvec::SmallVec;
3636
use span::Edition;
37-
use stdx::{never, IsNoneOr};
37+
use stdx::never;
3838
use triomphe::Arc;
3939

4040
use crate::{
@@ -1489,12 +1489,14 @@ fn generic_args_sans_defaults<'ga>(
14891489
}
14901490
// otherwise, if the arg is equal to the param default, hide it (unless the
14911491
// default is an error which can happen for the trait Self type)
1492-
#[allow(unstable_name_collisions)]
1493-
default_parameters.get(i).is_none_or(|default_parameter| {
1494-
// !is_err(default_parameter.skip_binders())
1495-
// &&
1496-
arg != &default_parameter.clone().substitute(Interner, &parameters)
1497-
})
1492+
match default_parameters.get(i) {
1493+
None => true,
1494+
Some(default_parameter) => {
1495+
// !is_err(default_parameter.skip_binders())
1496+
// &&
1497+
arg != &default_parameter.clone().substitute(Interner, &parameters)
1498+
}
1499+
}
14981500
};
14991501
let mut default_from = 0;
15001502
for (i, parameter) in parameters.iter().enumerate() {

crates/proc-macro-api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl ProcMacro {
154154
mixed_site: Span,
155155
) -> Result<Result<tt::Subtree<Span>, PanicMessage>, ServerError> {
156156
let version = self.process.version();
157-
let current_dir = env.get("CARGO_MANIFEST_DIR");
157+
let current_dir = env.get("CARGO_RUSTC_CURRENT_DIR");
158158

159159
let mut span_data_table = SpanDataIndexMap::default();
160160
let def_site = span_data_table.insert_full(def_site).0;

crates/project-model/src/env.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use base_db::Env;
33
use rustc_hash::FxHashMap;
44
use toolchain::Tool;
55

6-
use crate::{utf8_stdout, ManifestPath, PackageData, Sysroot, TargetKind};
6+
use crate::{utf8_stdout, CargoWorkspace, ManifestPath, PackageData, Sysroot, TargetKind};
77

88
/// Recreates the compile-time environment variables that Cargo sets.
99
///
@@ -46,8 +46,9 @@ pub(crate) fn inject_cargo_package_env(env: &mut Env, package: &PackageData) {
4646
);
4747
}
4848

49-
pub(crate) fn inject_cargo_env(env: &mut Env) {
49+
pub(crate) fn inject_cargo_env(env: &mut Env, cargo: &CargoWorkspace) {
5050
env.set("CARGO", Tool::Cargo.path().to_string());
51+
env.set("CARGO_RUSTC_CURRENT_DIR", cargo.manifest_path().to_string());
5152
}
5253

5354
pub(crate) fn inject_rustc_tool_env(env: &mut Env, cargo_name: &str, kind: TargetKind) {

crates/project-model/src/workspace.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,7 @@ fn cargo_to_crate_graph(
10201020
let crate_id = add_target_crate_root(
10211021
crate_graph,
10221022
proc_macros,
1023+
cargo,
10231024
pkg_data,
10241025
build_data,
10251026
cfg_options.clone(),
@@ -1239,6 +1240,7 @@ fn handle_rustc_crates(
12391240
let crate_id = add_target_crate_root(
12401241
crate_graph,
12411242
proc_macros,
1243+
rustc_workspace,
12421244
&rustc_workspace[pkg],
12431245
build_scripts.get_output(pkg),
12441246
cfg_options.clone(),
@@ -1298,6 +1300,7 @@ fn handle_rustc_crates(
12981300
fn add_target_crate_root(
12991301
crate_graph: &mut CrateGraph,
13001302
proc_macros: &mut ProcMacroPaths,
1303+
cargo: &CargoWorkspace,
13011304
pkg: &PackageData,
13021305
build_data: Option<&BuildScriptOutput>,
13031306
cfg_options: CfgOptions,
@@ -1330,7 +1333,7 @@ fn add_target_crate_root(
13301333

13311334
let mut env = Env::default();
13321335
inject_cargo_package_env(&mut env, pkg);
1333-
inject_cargo_env(&mut env);
1336+
inject_cargo_env(&mut env, cargo);
13341337
inject_rustc_tool_env(&mut env, cargo_name, kind);
13351338

13361339
if let Some(envs) = build_data.map(|it| &it.envs) {

0 commit comments

Comments
 (0)