Skip to content

fix arm64 build#264

Open
riederm wants to merge 1 commit intoubnt-intrepid:mainfrom
riederm:main
Open

fix arm64 build#264
riederm wants to merge 1 commit intoubnt-intrepid:mainfrom
riederm:main

Conversation

@riederm
Copy link
Copy Markdown

@riederm riederm commented Mar 25, 2026

cargo build --release --target=aarch64-unknown-linux-gnu fails with

the arm64 implementation of the filesystem seams to differ slightly with their types ?!

error[E0277]: `?` couldn't convert the error to `TryIntoFileAttrError`
   --> /opt/cargo/git/checkouts/polyfuse-cbcbf2a95fa40771/0301238/src/types.rs:422:42
    |
422 |             nlink: st.st_nlink.try_into()?,
    |                                ----------^ the trait `From<Infallible>` is not implemented for `TryIntoFileAttrError`
    |                                |
    |                                this can't be annotated with `?` because it has type `Result<_, Infallible>

`cargo build --release --target=aarch64-unknown-linux-gnu` fails
with

```
error[E0277]: `?` couldn't convert the error to `TryIntoFileAttrError`
   --> /opt/cargo/git/checkouts/polyfuse-cbcbf2a95fa40771/0301238/src/types.rs:422:42
    |
422 |             nlink: st.st_nlink.try_into()?,
    |                                ----------^ the trait `From<Infallible>` is not implemented for `TryIntoFileAttrError`
    |                                |
    |                                this can't be annotated with `?` because it has type `Result<_, Infallible>
```
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an ARM64 build failure in FileAttr conversion by ensuring integer conversions produce an error type compatible with TryIntoFileAttrError, allowing ? to be used consistently across architectures.

Changes:

  • Force st_nlink/st_blksize conversions through u64 before narrowing to u32 in TryFrom<&libc::stat> for FileAttr.
  • Apply the same u64-then-narrow pattern for Metadata-derived nlink/blksize.

Comment thread src/types.rs
Comment on lines +422 to +426
nlink: (st.st_nlink as u64).try_into()?,
uid: Uid::from_raw(st.st_uid),
gid: Gid::from_raw(st.st_gid),
rdev: DeviceID::from_userspace_dev(st.st_rdev),
blksize: st.st_blksize.try_into()?,
blksize: (st.st_blksize as u64).try_into()?,
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

Using (st.st_nlink as u64).try_into()? / (st.st_blksize as u64).try_into()? works around the Infallible error-type mismatch on platforms where the source field is already u32, but it does so by forcing an as cast. A more direct (and easier to reason about) fix is to make TryIntoFileAttrError convertible from std::convert::Infallible (e.g., via a From<Infallible> impl that is unreachable), or explicitly handle the Infallible case when calling try_into(). That would allow keeping the original try_into()? without widening casts and keeps the intent clearer across architectures.

Copilot uses AI. Check for mistakes.
Comment thread src/types.rs
Comment on lines +452 to +456
nlink: (m.nlink() as u64).try_into()?,
uid: Uid::from_raw(m.uid()),
gid: Gid::from_raw(m.gid()),
rdev: DeviceID::from_userspace_dev(m.rdev()),
blksize: m.blksize().try_into()?,
blksize: (m.blksize() as u64).try_into()?,
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

MetadataExt::nlink() and MetadataExt::blksize() are already u64 on Unix, so the added as u64 casts are redundant here and slightly obscure that the only potentially-failing step is the u64 -> u32 narrowing conversion. Consider dropping the cast (and if you add a From<Infallible> for TryIntoFileAttrError as suggested above, the libc::stat and Metadata conversions can stay consistent).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

@ubnt-intrepid ubnt-intrepid left a comment

Choose a reason for hiding this comment

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

IMO, the fundamental problem is that the error type TryIntoFileAttrError doesn't implement From<Infallible>.
How about simply adding the following code?

impl From<Infallible> for TryIntoFileAttrError {
    fn from(never: Infallible) -> Self {
        match never {}
    }
}

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.

3 participants