Repository: rust
Issue: `std::fs::File::create` return a wrong error on Windows when the path points to a directory
Labels: O-windows,T-libs,A-io,C-discussion,A-filesystem

`std::fs::File::create` return a wrong error on Windows.

I tried this code:

```rust
fn main() {
    // <path> points to an existing directory
    std::fs::File::create("<path>").unwrap();
}
```

I expected the `ErrorKind` is `IsADirectory`. Instead,  the `ErrorKind` is `PermissionDenied`.

### Meta

`rustc --version --verbose`:
```
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1
```

<details><summary>Backtrace</summary>
<p>

```
thread 'main' panicked at src/main.rs:2:34:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
stack backtrace:
   0:     0x7ff6b4e16e01 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ff6b4e16e01 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff6b4e16e01 - std::sys::backtrace::_print_fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:66
   3:     0x7ff6b4e16e01 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:39
   4:     0x7ff6b4e244ca - core::fmt::rt::Argument::fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\fmt\rt.rs:177
   5:     0x7ff6b4e244ca - core::fmt::write
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\fmt\mod.rs:1186
   6:     0x7ff6b4e152f7 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\io\mod.rs:1839
   7:     0x7ff6b4e16c45 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:42
   8:     0x7ff6b4e181d7 - std::panicking::default_hook::closure$1
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:268
   9:     0x7ff6b4e17fb7 - std::panicking::default_hook
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:295
  10:     0x7ff6b4e18863 - std::panicking::rust_panic_with_hook
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:801
  11:     0x7ff6b4e186e9 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:674
  12:     0x7ff6b4e1754f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\sys\backtrace.rs:170
  13:     0x7ff6b4e182ee - std::panicking::begin_panic_handler
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:665
  14:     0x7ff6b4e29861 - core::panicking::panic_fmt
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\panicking.rs:74
  15:     0x7ff6b4e29bb0 - core::result::unwrap_failed
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/core\src\result.rs:1700
  16:     0x7ff6b4e11fa4 - enum2$<core::result::Result<std::fs::File,std::io::error::Error> >::unwrap
                               at C:\Users\1plus\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:1104
  17:     0x7ff6b4e11fa4 - test_file_create::main
                               at C:\Users\1plus\Desktop\test-file-create\src\main.rs:2
  18:     0x7ff6b4e110bb - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at C:\Users\1plus\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:250
  19:     0x7ff6b4e1151e - core::hint::black_box
                               at C:\Users\1plus\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\hint.rs:389
  20:     0x7ff6b4e1151e - std::sys::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at C:\Users\1plus\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\backtrace.rs:154
  21:     0x7ff6b4e11591 - std::rt::lang_start::closure$0<tuple$<> >
                               at C:\Users\1plus\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:195
  22:     0x7ff6b4e13cec - std::rt::lang_start_internal::closure$1
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\rt.rs:174
  23:     0x7ff6b4e13cec - std::panicking::try::do_call
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:557
  24:     0x7ff6b4e13cec - std::panicking::try
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panicking.rs:520
  25:     0x7ff6b4e13cec - std::panic::catch_unwind
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\panic.rs:358
  26:     0x7ff6b4e13cec - std::rt::lang_start_internal
                               at /rustc/90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf\library/std\src\rt.rs:174
  27:     0x7ff6b4e1156a - std::rt::lang_start<tuple$<> >
                               at C:\Users\1plus\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:194
  28:     0x7ff6b4e12009 - main
  29:     0x7ff6b4e28090 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  30:     0x7ff6b4e28090 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  31:     0x7fff86cfe8d7 - BaseThreadInitThunk
  32:     0x7fff888bfbcc - RtlUserThreadStart
error: process didn't exit successfully: `target\debug\test-file-create.exe` (exit code: 101)
```

</p>
</details>