Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/rust-analyzer/src/config.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index e8504979be..ef890fa3e6 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -2531,6 +2531,7 @@ macro_rules! _impl_for_config_data {
#[allow(non_snake_case)]
$vis fn $field(&self, source_root: Option<SourceRootId>) -> &$ty {
let mut par: Option<SourceRootId> = source_root;
+ let mut traversals = 0;
while let Some(source_root_id) = par {
par = self.source_root_parent_map.get(&source_root_id).copied();
if let Some((config, _)) = self.ratoml_files.get(&source_root_id) {
@@ -2538,6 +2539,14 @@ macro_rules! _impl_for_config_data {
return value;
}
}
+ // Prevent infinite loops caused by cycles by giving up when it's
+ // clear that we must have either visited all source roots or
+ // encountered a cycle.
+ traversals += 1;
+ if traversals >= self.source_root_parent_map.len() {
+ // i.e. no source root contains the config we're looking for
+ break;
+ }
}
if let Some((root_path_ratoml, _)) = self.root_ratoml.as_ref() {