Skip to content

Commit 4cb7162

Browse files
committed
Merge remote-tracking branch 'upstream/master' into deduplicate-crate-graph
2 parents c02d4f6 + dcee5fd commit 4cb7162

File tree

11 files changed

+90
-116
lines changed

11 files changed

+90
-116
lines changed

crates/hir-def/src/body/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn your_stack_belongs_to_me() {
5252
cov_mark::check!(your_stack_belongs_to_me);
5353
lower(
5454
r#"
55+
#![recursion_limit = "32"]
5556
macro_rules! n_nuple {
5657
($e:tt) => ();
5758
($($rest:tt)*) => {{
@@ -68,6 +69,7 @@ fn your_stack_belongs_to_me2() {
6869
cov_mark::check!(overflow_but_not_me);
6970
lower(
7071
r#"
72+
#![recursion_limit = "32"]
7173
macro_rules! foo {
7274
() => {{ foo!(); foo!(); }}
7375
}
@@ -78,8 +80,6 @@ fn main() { foo!(); }
7880

7981
#[test]
8082
fn recursion_limit() {
81-
cov_mark::check!(your_stack_belongs_to_me);
82-
8383
lower(
8484
r#"
8585
#![recursion_limit = "2"]

crates/hir-def/src/nameres/collector.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,13 +1451,7 @@ impl DefCollector<'_> {
14511451
depth: usize,
14521452
container: ItemContainerId,
14531453
) {
1454-
let recursion_limit = self.def_map.recursion_limit() as usize;
1455-
let recursion_limit = Limit::new(if cfg!(test) {
1456-
// Without this, `body::tests::your_stack_belongs_to_me` stack-overflows in debug
1457-
std::cmp::min(32, recursion_limit)
1458-
} else {
1459-
recursion_limit
1460-
});
1454+
let recursion_limit = Limit::new(self.def_map.recursion_limit() as usize);
14611455
if recursion_limit.check(depth).is_err() {
14621456
cov_mark::hit!(macro_expansion_overflow);
14631457
tracing::warn!("macro expansion is too deep");

crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212

1313
use intern::Symbol;
1414
use proc_macro::bridge::{self, server};
15-
use span::{Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
15+
use span::{FileId, Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
1616
use tt::{TextRange, TextSize};
1717

1818
use crate::server_impl::{
@@ -32,8 +32,10 @@ mod tt {
3232

3333
type TokenStream = crate::server_impl::TokenStream<Span>;
3434

35-
#[derive(Clone)]
36-
pub struct SourceFile;
35+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
36+
pub struct SourceFile {
37+
file_id: FileId,
38+
}
3739
pub struct FreeFunctions;
3840

3941
pub struct RaSpanServer {
@@ -291,9 +293,8 @@ impl server::TokenStream for RaSpanServer {
291293
}
292294

293295
impl server::SourceFile for RaSpanServer {
294-
fn eq(&mut self, _file1: &Self::SourceFile, _file2: &Self::SourceFile) -> bool {
295-
// FIXME
296-
true
296+
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
297+
file1 == file2
297298
}
298299
fn path(&mut self, _file: &Self::SourceFile) -> String {
299300
// FIXME
@@ -308,9 +309,8 @@ impl server::Span for RaSpanServer {
308309
fn debug(&mut self, span: Self::Span) -> String {
309310
format!("{:?}", span)
310311
}
311-
fn source_file(&mut self, _span: Self::Span) -> Self::SourceFile {
312-
// FIXME stub, requires db
313-
SourceFile {}
312+
fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
313+
SourceFile { file_id: span.anchor.file_id.file_id() }
314314
}
315315
fn save_span(&mut self, _span: Self::Span) -> usize {
316316
// FIXME, quote is incompatible with third-party tools

crates/project-model/src/cargo_workspace.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ops;
44
use std::str::from_utf8;
55

66
use anyhow::Context;
7+
use base_db::Env;
78
use cargo_metadata::{CargoOpt, MetadataCommand};
89
use la_arena::{Arena, Idx};
910
use paths::{AbsPath, AbsPathBuf, Utf8PathBuf};
@@ -34,6 +35,8 @@ pub struct CargoWorkspace {
3435
target_directory: AbsPathBuf,
3536
manifest_path: ManifestPath,
3637
is_virtual_workspace: bool,
38+
/// Environment variables set in the `.cargo/config` file.
39+
config_env: Env,
3740
}
3841

3942
impl ops::Index<Package> for CargoWorkspace {
@@ -395,6 +398,7 @@ impl CargoWorkspace {
395398
pub fn new(
396399
mut meta: cargo_metadata::Metadata,
397400
ws_manifest_path: ManifestPath,
401+
cargo_config_env: Env,
398402
) -> CargoWorkspace {
399403
let mut pkg_by_id = FxHashMap::default();
400404
let mut packages = Arena::default();
@@ -516,6 +520,7 @@ impl CargoWorkspace {
516520
target_directory,
517521
manifest_path: ws_manifest_path,
518522
is_virtual_workspace,
523+
config_env: cargo_config_env,
519524
}
520525
}
521526

@@ -602,4 +607,8 @@ impl CargoWorkspace {
602607
pub fn is_virtual_workspace(&self) -> bool {
603608
self.is_virtual_workspace
604609
}
610+
611+
pub fn env(&self) -> &Env {
612+
&self.config_env
613+
}
605614
}

crates/project-model/src/env.rs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Cargo-like environment variables injection.
22
use base_db::Env;
3+
use paths::Utf8Path;
34
use rustc_hash::FxHashMap;
45
use toolchain::Tool;
56

@@ -63,7 +64,7 @@ pub(crate) fn cargo_config_env(
6364
manifest: &ManifestPath,
6465
extra_env: &FxHashMap<String, String>,
6566
sysroot: &Sysroot,
66-
) -> FxHashMap<String, String> {
67+
) -> Env {
6768
let mut cargo_config = sysroot.tool(Tool::Cargo, manifest.parent());
6869
cargo_config.envs(extra_env);
6970
cargo_config
@@ -75,7 +76,7 @@ pub(crate) fn cargo_config_env(
7576
// if successful we receive `env.key.value = "value" per entry
7677
tracing::debug!("Discovering cargo config env by {:?}", cargo_config);
7778
utf8_stdout(&mut cargo_config)
78-
.map(parse_output_cargo_config_env)
79+
.map(|stdout| parse_output_cargo_config_env(manifest, stdout))
7980
.inspect(|env| {
8081
tracing::debug!("Discovered cargo config env: {:?}", env);
8182
})
@@ -85,18 +86,38 @@ pub(crate) fn cargo_config_env(
8586
.unwrap_or_default()
8687
}
8788

88-
fn parse_output_cargo_config_env(stdout: String) -> FxHashMap<String, String> {
89-
stdout
90-
.lines()
91-
.filter_map(|l| l.strip_prefix("env."))
92-
.filter_map(|l| l.split_once(" = "))
93-
.filter_map(|(k, v)| {
94-
if k.contains('.') {
95-
k.strip_suffix(".value").zip(Some(v))
96-
} else {
97-
Some((k, v))
89+
fn parse_output_cargo_config_env(manifest: &ManifestPath, stdout: String) -> Env {
90+
let mut env = Env::default();
91+
let mut relatives = vec![];
92+
for (key, val) in
93+
stdout.lines().filter_map(|l| l.strip_prefix("env.")).filter_map(|l| l.split_once(" = "))
94+
{
95+
let val = val.trim_matches('"').to_owned();
96+
if let Some((key, modifier)) = key.split_once('.') {
97+
match modifier {
98+
"relative" => relatives.push((key, val)),
99+
"value" => _ = env.insert(key, val),
100+
_ => {
101+
tracing::warn!(
102+
"Unknown modifier in cargo config env: {}, expected `relative` or `value`",
103+
modifier
104+
);
105+
continue;
106+
}
98107
}
99-
})
100-
.map(|(key, value)| (key.to_owned(), value.trim_matches('"').to_owned()))
101-
.collect()
108+
} else {
109+
env.insert(key, val);
110+
}
111+
}
112+
// FIXME: The base here should be the parent of the `.cargo/config` file, not the manifest.
113+
// But cargo does not provide this information.
114+
let base = <_ as AsRef<Utf8Path>>::as_ref(manifest.parent());
115+
for (key, val) in relatives {
116+
if let Some(val) = env.get(&val) {
117+
env.insert(key, base.join(val).to_string());
118+
} else {
119+
env.insert(key, base.to_string());
120+
}
121+
}
122+
env
102123
}

crates/project-model/src/sysroot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl Sysroot {
422422
res.packages.remove(idx);
423423
});
424424

425-
let cargo_workspace = CargoWorkspace::new(res, library_manifest);
425+
let cargo_workspace = CargoWorkspace::new(res, library_manifest, Default::default());
426426
Some(Sysroot {
427427
root: sysroot_dir.clone(),
428428
src_root: Some(sysroot_src_dir.clone()),

crates/project-model/src/tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ fn load_cargo_with_overrides(
2828
let meta: Metadata = get_test_json_file(file);
2929
let manifest_path =
3030
ManifestPath::try_from(AbsPathBuf::try_from(meta.workspace_root.clone()).unwrap()).unwrap();
31-
let cargo_workspace = CargoWorkspace::new(meta, manifest_path);
31+
let cargo_workspace = CargoWorkspace::new(meta, manifest_path, Default::default());
3232
let project_workspace = ProjectWorkspace {
3333
kind: ProjectWorkspaceKind::Cargo {
3434
cargo: cargo_workspace,
3535
build_scripts: WorkspaceBuildScripts::default(),
3636
rustc: Err(None),
37-
cargo_config_extra_env: Default::default(),
3837
error: None,
3938
set_test: true,
4039
},
@@ -290,7 +289,7 @@ fn smoke_test_real_sysroot_cargo() {
290289
let meta: Metadata = get_test_json_file("hello-world-metadata.json");
291290
let manifest_path =
292291
ManifestPath::try_from(AbsPathBuf::try_from(meta.workspace_root.clone()).unwrap()).unwrap();
293-
let cargo_workspace = CargoWorkspace::new(meta, manifest_path);
292+
let cargo_workspace = CargoWorkspace::new(meta, manifest_path, Default::default());
294293
let sysroot = Sysroot::discover(
295294
AbsPath::assert(Utf8Path::new(env!("CARGO_MANIFEST_DIR"))),
296295
&Default::default(),
@@ -302,7 +301,6 @@ fn smoke_test_real_sysroot_cargo() {
302301
cargo: cargo_workspace,
303302
build_scripts: WorkspaceBuildScripts::default(),
304303
rustc: Err(None),
305-
cargo_config_extra_env: Default::default(),
306304
error: None,
307305
set_test: true,
308306
},

0 commit comments

Comments
 (0)