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

OpenOptions: create() and create_new() are flip flopped #69254

Closed
JesterOrNot opened this issue Feb 18, 2020 · 1 comment · Fixed by #69284
Closed

OpenOptions: create() and create_new() are flip flopped #69254

JesterOrNot opened this issue Feb 18, 2020 · 1 comment · Fixed by #69284
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug.

Comments

@JesterOrNot
Copy link

I tried this code:

OpenOptions::new()
        .write(true)
        .create(true)
        .open(&args.target)

and it creates a file even if it already exists

OpenOptions::new()
        .write(true)
        .create_new(true)
        .open(&args.target)

This code creates a file only if the file does not exist

But look at the docs
For create()
image

For create_new()
image

I expected to see this happen: explanation
The functions to match their docs
Instead, this happened: explanation
They each do what the other is described to do

Meta

rustc --version --verbose:

rustc 1.41.0 (5e1a79984 2020-01-27)
binary: rustc
commit-hash: 5e1a799842ba6ed4a57e91f7ab9435947482f7d8
commit-date: 2020-01-27
host: x86_64-unknown-linux-gnu
release: 1.41.0
LLVM version: 9.0
Backtrace

gitpod /workspace/nushell $ RUST_BACKTRACE=1 cargo build
   Compiling nu v0.9.1 (/workspace/nushell)
    Finished dev [unoptimized + debuginfo] target(s) in 26.35s

@JesterOrNot JesterOrNot added the C-bug Category: This is a bug. label Feb 18, 2020
@jumbatm
Copy link
Contributor

jumbatm commented Feb 18, 2020

This appears to be a doc issue, not a library bug.

In RFC 1252 expand_open_options, it says create should open an existing file, or create a new file if it does not already exist, and create_new should open a new file, failing if it doesn't exist, which is consistent with the observed behaviour. I believe the current wording is a bit ambiguous, though.

cc @pitdicker

@rustbot modify labels to +T-doc

@rustbot rustbot added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Feb 18, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 19, 2020
…ylan-DPC

Reword OpenOptions::{create, create_new} doc.

Closes rust-lang#69254.

Currently, the doc comment for `fs::OpenOptions::create` doesn't mention its behaviour when opening an existing file, and `fs::OpenOptions::create_new`'s doc comment is worded in a way that doesn't make it clear that it actually _fails_ if the file already exists, not overwrite the existing file with a new one.

This PR addresses addresses this by rewording the doc comments to be more explicit.

r? @GuillaumeGomez
@bors bors closed this as completed in a97f354 Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants