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

add documentation for the while keyword #60761

Closed
wants to merge 1 commit into from

Conversation

Pulkit07
Copy link
Contributor

while keyword is used to define while loops in rust.

Fixes #60736.

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 12, 2019
Copy link
Contributor

@timvisee timvisee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me, in a similar style to for. Great!

Had some thoughts, left them in review comments.

src/libstd/keyword_docs.rs Outdated Show resolved Hide resolved
src/libstd/keyword_docs.rs Outdated Show resolved Hide resolved
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0fd9c158:start=1557678234532565164,finish=1557678235291754463,duration=759189299
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:18:48] 
[01:18:48] running 143 tests
[01:18:51] i..iii.....iii..iiii.....i......................i..i.................i.....i..........ii.i..i..i.ii. 100/143
[01:18:53] test result: ok. 113 passed; 0 failed; 30 ignored; 0 measured; 0 filtered out
[01:18:53] 
[01:18:53]  finished in 4.641
[01:18:53] travis_fold:end:test_codegen
---
travis_time:start:test_assembly
Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:18:55] 
[01:18:55] running 9 tests
[01:18:55] iiiiiiiii
[01:18:55] 
[01:18:55]  finished in 0.150
[01:18:55] travis_fold:end:test_assembly

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:19:10] 
[01:19:10] running 122 tests
[01:19:34] .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....i..........iiii..........i...ii...i.......ii.i 100/122
[01:19:39] .i.i......iii.i.....ii
[01:19:39] 
[01:19:39]  finished in 28.844
[01:19:39] travis_fold:end:test_debuginfo

---
[01:32:42] running 922 tests
[01:33:02] i................................................................................................... 100/922
[01:33:12] .................................iii......i......i...i......i....................................... 200/922
[01:33:16] .................................................................................................... 300/922
[01:33:23] .................................................i.i....................F...................iiii.... 400/922
[01:33:37] .................................................................................................... 600/922
[01:33:45] ............................................iiii.................................................... 700/922
[01:33:59] .................................................................................................... 800/922
[01:34:06] ....................................................................iiii............................ 900/922
---
[01:34:07]  --> keyword_docs.rs:567:9
[01:34:07]   |
[01:34:07] 1 | #![deny(warnings)]
[01:34:07]   |         ^^^^^^^^
[01:34:07]   = note: #[deny(while_true)] implied by #[deny(warnings)]
[01:34:07] error: aborting due to previous error
[01:34:07] 
[01:34:07] 
[01:34:07] thread 'keyword_docs.rs - while_keyword (line 569)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:319:13
[01:34:07] 
[01:34:07] 
[01:34:07] failures:
[01:34:07]     keyword_docs.rs - while_keyword (line 569)
[01:34:07]     keyword_docs.rs - while_keyword (line 569)
[01:34:07] 
[01:34:07] test result: FAILED. 897 passed; 1 failed; 24 ignored; 0 measured; 0 filtered out
[01:34:07] 
[01:34:07] error: test failed, to rerun pass '--doc'
[01:34:07] 
[01:34:07] 
[01:34:07] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "std" "--" "--quiet"
[01:34:07] 
[01:34:07] 
[01:34:07] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:34:07] Build completed unsuccessfully in 0:26:56
[01:34:07] Build completed unsuccessfully in 0:26:56
[01:34:07] make: *** [check] Error 1
[01:34:07] Makefile:48: recipe for target 'check' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:07e86172
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun May 12 17:58:13 UTC 2019
---
travis_time:end:02855c86:start=1557683895402201899,finish=1557683895453525527,duration=51323628
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:1e538a19
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:2d09cd0a
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

while keyword is used to define while loops in rust.

Fixes rust-lang#60736.
//
/// while loop
///
/// `while` is used to define while loops in Rust. It runs the code inside it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write this in a way that is not a tautology ("the while keyword is used to define a while loop"). It is true but not meaningful.

///
/// ```rust
/// let mut i = 0;
/// while i > 10 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is not > 10 so this loop would never run -- seems unintentional.

/// while loop
///
/// `while` is used to define while loops in Rust. It runs the code inside it
/// until the condition in the while loop becomes False or there the code uses
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalization: false is a lowercase noun. This looks like muscle memory from Python. ;)

Copy link
Contributor

@czipperz czipperz May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should also use an inline code block (back ticks) around false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"until the condition becomes false" is meaningful English without backticks. I think adding backticks would detract in this case.

///
/// `while` is used to define while loops in Rust. It runs the code inside it
/// until the condition in the while loop becomes False or there the code uses
/// `break`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

until [...] there the code uses break.

This "until there" part of the sentence sounds wrong to me. Not clear what "there" is referring to.

/// i += 1;
/// }
/// ```
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page should cover while let as well.

/// let mut i = 0;
/// while i > 10 {
/// println!("i is {}", i);
/// i += 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please come up with a different example where while is the best solution. The point of example code is usually not showing how to write something. The point is showing why you would want to write the thing. This code shows a while loop but if you were solving the problem that this code is solving then you would not want to use a while loop. That makes the example not compelling.

@dtolnay dtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 19, 2019
@hellow554
Copy link
Contributor

@Pulkit07 any progress so far? Are you having troubles? Do you need any help?

@Pulkit07
Copy link
Contributor Author

@Pulkit07 any progress so far? Are you having troubles? Do you need any help?

Hey, sorry for long silence. I have been mostly busy with work, so no progress. Feel free to close this PR or assign the issue to someone else.

Thanks!

@hellow554
Copy link
Contributor

@Pulkit07 any progress so far? Are you having troubles? Do you need any help?

Hey, sorry for long silence. I have been mostly busy with work, so no progress. Feel free to close this PR or assign the issue to someone else.

Thanks!

As long as you don't say, that you will surrender on this issue, it's yours. It's not critical, so take your time.

@Dylan-DPC-zz
Copy link

ping from triage @Pulkit07
Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! Thanks

@Dylan-DPC-zz Dylan-DPC-zz added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 24, 2019
Centril added a commit to Centril/rust that referenced this pull request Jul 8, 2019
Centril added a commit to Centril/rust that referenced this pull request Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing documentation for while keyword
7 participants