Skip to content

Conversation

@mvidner
Copy link

@mvidner mvidner commented Nov 10, 2025

Thanks for tr! My team at work is considering to use it in https://github.com/agama-project/agama/ and I found that xtr gets confused by a nontrivial module structure.

Without this fix, xtr would not find the nested web modules, mistakenly finding the top-level web instead.

$ find src -type f
src/main.rs
src/software.rs
src/software/web.rs
src/storage.rs
src/storage/web.rs
src/web.rs

Without this fix, `xtr` would not find the nested `web` modules, mistakenly
finding the top-level `web` instead.

```console
$ find src -type f
src/main.rs
src/software.rs
src/software/web.rs
src/storage.rs
src/storage/web.rs
src/web.rs
```
@mvidner
Copy link
Author

mvidner commented Nov 10, 2025

In https://github.com/mvidner/tr/tree/test-fixtures/xtr/src/fixtures I have a source (sub)tree that

  • cargo builds
  • demonstrates this bug
  • but is not included in an automated test

In current.rs, "mod foo" can be found in:
1. ./current/foo.rs
2. ./current/foo/mod.rs
but if current.rs is in fact lib.rs or main.rs, then in:
3. ./foo.rs
4. ./foo/mod.rs

Therefore, let visit_item_mod try only half of the files, depending on whether
the current file is the module root.
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. That makes total sense.
Please just see my question inline.

(I wish there were tests for this code)

if subdir.is_file() {
return self
.parse_mod(adjacent_mod)
.parse_mod(subdir, false)
Copy link
Member

Choose a reason for hiding this comment

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

is the mod.rs not follow the same "root" rule as lib.rs or main.rs ?

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.

2 participants