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

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

Closed
mTsBucy1 opened this issue Jan 28, 2023 · 1 comment · Fixed by #5413
Closed

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

mTsBucy1 opened this issue Jan 28, 2023 · 1 comment · Fixed by #5413
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-process Module: tokio/process T-docs Topic: documentation

Comments

@mTsBucy1
Copy link
Contributor

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.

@mTsBucy1 mTsBucy1 added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Jan 28, 2023
@Darksonn Darksonn added E-help-wanted Call for participation: Help is requested to fix this issue. T-docs Topic: documentation E-easy Call for participation: Experience needed to fix: Easy / not much M-process Module: tokio/process labels Jan 28, 2023
@Darksonn
Copy link
Contributor

You're right, this is misleading. It would be nice to improve the documentation here.

mTsBucy1 added a commit to mTsBucy1/tokio-contrib-fork that referenced this issue Jan 30, 2023
mTsBucy1 added a commit to mTsBucy1/tokio-contrib-fork that referenced this issue Jan 30, 2023
@Darksonn Darksonn removed E-help-wanted Call for participation: Help is requested to fix this issue. E-easy Call for participation: Experience needed to fix: Easy / not much labels Jan 30, 2023
Noah-Kennedy added a commit that referenced this issue Mar 1, 2023
# 1.26.0 (March 1st, 2023)

### Fixed

- sync: don't leak tracing spans in mutex guards ([#5469])
- sync: drop wakers after unlocking the mutex in Notify ([#5471])
- sync: drop wakers outside lock in semaphore ([#5475])
- macros: fix empty `join!` and `try_join!` ([#5504])

### Added

- fs: add `fs::try_exists` ([#4299])
- net: add types for named unix pipes ([#5351])
- sync: add `MappedOwnedMutexGuard` ([#5474])

### Documented

- task: clarify what happens to spawned work during runtime shutdown ([#5394])
- task: clarify `process::Command` docs (#5406) ([#5413])
- sync: add doc aliases for `blocking_*` methods ([#5448])
- task: fix wording with 'unsend' ([#5452])
- signal: updated Documentation for Signals ([#5459])
- sync: fix docs for Send/Sync bounds in broadcast ([#5480])
- io: improve AsyncFd example ([#5481])
- tokio: document supported platforms ([#5483])
- runtime: document the nature of the main future ([#5494])
- sync: document drop behavior for channels ([#5497])
- time: document immediate completion guarantee for timeouts ([#5509])
- runtime: remove extra period in docs ([#5511])

### Changed

- net: use Message Read Mode for named pipes ([#5350])
- chore: update windows-sys to 0.45 ([#5386])
- sync: mark lock guards with `#[clippy::has_significant_drop]` ([#5422])
- sync: reduce contention in watch channel ([#5464])
- time: remove cache padding in timer entries ([#5468])
- time: Improve `Instant::now()` perf with test-util ([#5513])

### Internal Changes
- tests: port proptest fuzz harnesses to use cargo-fuzz ([#5392])
- time: don't store deadline twice in sleep entries ([#5410])
- rt: remove Arc from Clock ([#5434])
- sync: make `notify_waiters` calls atomic ([#5458])
- net: refactor named pipe builders to not use bitfields ([#5477])
- io: use `poll_fn` in `copy_bidirectional` ([#5486])
- fs: add more tests for filesystem functionality ([#5493])
- net: fix test compilation failure ([#5506])
- io: ignore SplitByUtf8BoundaryIfWindows test on miri ([#5507])

### Unstable

- metrics: add a new metric for budget exhaustion yields ([#5517])

[#4299]: #4299
[#5350]: #5350
[#5351]: #5351
[#5386]: #5386
[#5392]: #5392
[#5394]: #5394
[#5410]: #5410
[#5413]: #5413
[#5422]: #5422
[#5434]: #5434
[#5448]: #5448
[#5452]: #5452
[#5458]: #5458
[#5459]: #5459
[#5464]: #5464
[#5468]: #5468
[#5469]: #5469
[#5471]: #5471
[#5474]: #5474
[#5475]: #5475
[#5477]: #5477
[#5480]: #5480
[#5481]: #5481
[#5483]: #5483
[#5486]: #5486
[#5493]: #5493
[#5494]: #5494
[#5497]: #5497
[#5504]: #5504
[#5506]: #5506
[#5507]: #5507
[#5509]: #5509
[#5511]: #5511
[#5513]: #5513
[#5517]: #5517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-process Module: tokio/process T-docs Topic: documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants