Skip to content

fix: format deeply nested trees - #132

Merged
m4tx merged 4 commits into
google:mainfrom
Daiyuanranfeng:fix/deep-display-indent
Nov 30, 2026
Merged

m4tx merged 4 commits into
google:mainfrom
Daiyuanranfeng:fix/deep-display-indent

Conversation

@Daiyuanranfeng

Copy link
Copy Markdown
Contributor

Summary

  • write indentation in fixed-size chunks instead of using formatter width padding
  • avoid the width overflow panic when formatting deeply nested device trees
  • add regression coverage for indentation beyond u16::MAX

Fixes #103

Validation

  • cargo fmt --all -- --check
  • cargo test --locked --all-features (143 tests passed)
  • cargo clippy --locked --all-features --all-targets (passes with existing warnings outside this change)
  • git diff --check

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.33%. Comparing base (6db8e5d) to head (6ce2d03).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
+ Coverage   95.32%   95.33%   +0.01%     
==========================================
  Files          27       27              
  Lines        4040     4054      +14     
==========================================
+ Hits         3851     3865      +14     
  Misses        189      189              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/fdt/node.rs Outdated
FdtEventIter::new(self)
}

pub(crate) fn write_indent<W: fmt::Write>(f: &mut W, indent: usize) -> fmt::Result {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is pub(crate) and used in fdt/property.rs as well, can we move this to src/utils.rs?

Comment thread src/fdt/node.rs Outdated
Comment on lines +166 to +171
const SPACES: &str = " ";

for _ in 0..indent / SPACES.len() {
f.write_str(SPACES)?;
}
f.write_str(&SPACES[..indent % SPACES.len()])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to just use write_char here in a loop, instead of using the SPACES constant here. I get it that write_str can be faster, but I'd like to avoid having unnecessary data in the binary, unless we benchmark that it's worth it.

@Daiyuanranfeng

Copy link
Copy Markdown
Contributor Author

@m4tx Thanks for the review. I moved the shared indentation helper into the existing src/util.rs module and switched it to a write_char loop. cargo test --all-features passed locally. Could you take another look when you have a chance?

@m4tx m4tx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - the last issue to address is moving the unit test into a test module.

Comment thread src/util.rs Resolved
@Daiyuanranfeng

Copy link
Copy Markdown
Contributor Author

@m4tx Moved \large_indentation_does_not_panic\ into a #[cfg(test)] mod tests\ block at the bottom of \src/util.rs\ (placed after
ame_without_address\ so Clippy's \items_after_test_module\ lint stays happy). Verified locally with \cargo test --all-features.

@m4tx m4tx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thanks! Please rebase the changes on top of current main branch so that we can merge this.

@Daiyuanranfeng
Daiyuanranfeng force-pushed the fix/deep-display-indent branch from 77ceb3d to 6ce2d03 Compare November 30, 2026 04:44
@Daiyuanranfeng

Copy link
Copy Markdown
Contributor Author

Thanks for the review. The indentation test is in a #[cfg(test)] mod tests block, and I have rebased the branch onto the current main to resolve the merge conflict.

On Windows, cargo fmt --all -- --check and cargo test --locked --all-features pass. cargo clippy --locked --all-features --all-targets passes with warnings in unchanged upstream files. With -D warnings, Clippy stops on two comparison_chain warnings in src/fdt_mut/buffer.rs, outside this PR's diff.

@m4tx m4tx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks a lot!

@m4tx
m4tx merged commit 6380b8e into google:main Nov 30, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display panics on a tree nested 16,384 levels deep

2 participants