Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
willglynn opened this issue Jan 11, 2017 · 3 comments
Closed

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

willglynn opened this issue Jan 11, 2017 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@willglynn
Copy link

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.

@PSeitz
Copy link
Contributor

PSeitz commented Feb 21, 2017

When I add use std::os::windows::fs::FileExt; I still get no method named read_at found for type std::fs::File in the current scope under windows.

Edit: It seems there is only a os specific version #35704, because windows updates the file pointer. seek seems to be the os independent version.

@tbu-
Copy link
Contributor

tbu- commented Mar 7, 2017

You can use seek_read on Windows, it behaves similarly (but not identically) to read_at.

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label May 27, 2017
@Mark-Simulacrum
Copy link
Member

Hm, I'm going to close in favor of #26454. I don't think that it's all that helpful to keep this issue around as well; and FileExt is now stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants