Conversation
`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>
```
There was a problem hiding this comment.
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_blksizeconversions throughu64before narrowing tou32inTryFrom<&libc::stat> for FileAttr. - Apply the same
u64-then-narrow pattern forMetadata-derivednlink/blksize.
| 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()?, |
There was a problem hiding this comment.
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.
| 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()?, |
There was a problem hiding this comment.
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).
ubnt-intrepid
left a comment
There was a problem hiding this comment.
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 {}
}
}
cargo build --release --target=aarch64-unknown-linux-gnufails withthe arm64 implementation of the filesystem seams to differ slightly with their types ?!