Skip to content

Documentation of tokio::process::Command::arg is misleading #5406

Closed
@mTsBucy1

Description

@mTsBucy1

Version
Using tokio 1.24.2, rust 1.67

Platform
Windows 10, 64 bit

Description
The example of tokio::process::Command::arg (and other methods of Command) suggests the following code:

use tokio::process::Command;

let command = Command::new("ls").arg("-l").arg("-a");

which naturally extends to

#[tokio::test]
async fn wontcompile() {
    use tokio::process::Command;

    let command = Command::new("ls").arg("-l").arg("-a");
    command.output();
}

This snippet won't compile, however, with the error:

error[E0716]: temporary value dropped while borrowed
  --> taumada-rusty-runner\src\lib.rs:80:19
   |
80 |     let command = Command::new("ls").arg("-l").arg("-a");
   |                   ^^^^^^^^^^^^^^^^^^                    - temporary value is freed at the end of this statement
   |                   |
   |                   creates a temporary value which is freed while still in use
81 |     command.output();
   |     ---------------- borrow later used here
   |
   = note: consider using a `let` binding to create a longer lived value

For more information about this error, try `rustc --explain E0716`.

Resolution
I suggest to either, like std::process::Command::arg, add a .spawn().unwrap(), or the remove the let binding named command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-bugCategory: This is a bug.M-processModule: tokio/processT-docsTopic: documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions