Skip to content

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

Closed

Description

@JesterOrNot

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

Activity

  1. jumbatm commented on Feb 18, 2020

    @jumbatm
    Contributor

    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

  2. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Feb 18, 2020
  3. added 2 commits that reference this issue on Feb 19, 2020
    06717d8
    a97f354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions