Skip to content

rustc suggests std::os::ext::fs::FileExt then can't find it #38978

Closed
@willglynn

Description

@willglynn

I'm new to Rust and this got me sidetracked a bit. I know read_at() needs a FileExt trait, but I didn't remember where it was, so I referenced it anyway expecting the compiler would direct me to the right place. It didn't. My experience was roughly:

error: no method named `read_at` found for type `std::fs::File` in the current scope
  --> <anon>:9:11
   |
 9 |         f.read_at(&mut buf, 4000).unwrap();
   |           ^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
   = help: candidate #1: `use std::os::ext::fs::FileExt;`

Adding the suggested use, we get this playground link, which fails with the contradictory error messages:

error[E0432]: unresolved import `std::os::ext::fs::FileExt`
 --> <anon>:4:5
  |
4 | use std::os::ext::fs::FileExt;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find `ext` in `os`

error: no method named `read_at` found for type `std::fs::File` in the current scope
  --> <anon>:10:11
   |
10 |         f.read_at(&mut buf, 4000).unwrap();
   |           ^^^^^^^
   |
   = help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
   = help: candidate #1: `use std::os::ext::fs::FileExt;`

I asked #rust-beginners as a sanity check, and they said this is a known issue, namely #26454. I'm reporting it anyway because FileExt will be stable as of 1.15, and if I hit this bug that route, surely others will too.

It's not obvious from the error messages that my current target can be served by use std::os::unix::fs::FileExt;, and it's not obvious from the online docs that there is a Windows implementation of this trait either. For whatever it's worth, when I saw rustc suggest an OS-agnostic trait without mentioning the OS-specific ones, I was expecting to find an alias that worked on both platforms (and which wouldn't exist on others) rather than a compiler bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions