Skip to content

fix: add a breaker to avoid infinite loops from source root cycles #17412

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 1 commit into from
Jun 13, 2024
Merged
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
9 changes: 9 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2531,13 +2531,22 @@ 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) {
if let Some(value) = config.$field.as_ref() {
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() {
Expand Down