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

unwrap_or lint corrected #78825

Merged
merged 1 commit into from
Nov 11, 2020
Merged

Conversation

Nicholas-Baron
Copy link
Contributor

#78814 (comment)

This pull request fixes the lint from clippy where unwrap_or could be better done as a unwrap_or_else or a unwrap_or_default.

@rust-highfive
Copy link
Collaborator

Some changes occurred in intra-doc-links.

cc @jyn514

@rust-highfive
Copy link
Collaborator

r? @lcnr

(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 Nov 6, 2020
@Nicholas-Baron Nicholas-Baron changed the title Unwrap or corrected unwrap_or lint corrected Nov 6, 2020
@Mark-Simulacrum
Copy link
Member

@bors try @rust-timer queue

It seems plausible that gating the method call could actually hurt in some cases (since it changes operation order somewhat). Probably doesn't matter in practice, though.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Nov 6, 2020

⌛ Trying commit 1c7498c3e57e25363d0b7d3a716f7e1234604c4f with merge 3de0a1b5392ebbbfc1249710da2f62232983e9a9...

@bors
Copy link
Contributor

bors commented Nov 7, 2020

☀️ Try build successful - checks-actions
Build commit: 3de0a1b5392ebbbfc1249710da2f62232983e9a9 (3de0a1b5392ebbbfc1249710da2f62232983e9a9)

@rust-timer
Copy link
Collaborator

Queued 3de0a1b5392ebbbfc1249710da2f62232983e9a9 with parent a601302, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (3de0a1b5392ebbbfc1249710da2f62232983e9a9): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot modify labels: +S-waiting-on-review -S-waiting-on-perf

Copy link
Contributor Author

@Nicholas-Baron Nicholas-Baron left a comment

Choose a reason for hiding this comment

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

The following changes are reversions of unwrap_or_else to unwrap_or.

compiler/rustc_ast/src/attr/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/llvm_asm.rs Outdated Show resolved Hide resolved
compiler/rustc_codegen_llvm/src/intrinsic.rs Show resolved Hide resolved
src/librustdoc/passes/collect_intra_doc_links.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/doc_test_lints.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/doc_test_lints.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/html_tags.rs Outdated Show resolved Hide resolved
src/librustdoc/passes/non_autolinks.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2020
@the8472
Copy link
Member

the8472 commented Nov 7, 2020

Git does support bundling changes for multiple files into a single commit.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check of your PR failed (pretty log, 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.
[command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :
[command]/usr/bin/git config --local http.https://github.com/.extraheader AUTHORIZATION: basic ***
##[endgroup]
##[group]Fetching the repository
[command]/usr/bin/git -c protocol.version=2 fetch --no-tags --prune --progress --no-recurse-submodules --depth=2 origin +a1480fe8dc3999b78d2d46fc4b19d21261056ff3:refs/remotes/pull/78825/merge
---
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
skip untracked path cpu-usage.csv during rustfmt invocations
skip untracked path src/doc/book/ during rustfmt invocations
skip untracked path src/doc/rust-by-example/ during rustfmt invocations
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/compiler/rustc_codegen_llvm/src/intrinsic.rs at line 1724:
 // stuffs.
 fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
     match ty.kind() {
-        ty::Int(t) => Some((
-            t.bit_width().unwrap_or(u64::from(cx.tcx.sess.target.pointer_width)),
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2018" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_codegen_llvm/src/intrinsic.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
-        )),
-        )),
-        ty::Uint(t) => Some((
-            t.bit_width().unwrap_or(u64::from(cx.tcx.sess.target.pointer_width)),
-        )),
-        )),
+        ty::Int(t) => {
+            Some((t.bit_width().unwrap_or(u64::from(cx.tcx.sess.target.pointer_width)), true))
+        }
+        ty::Uint(t) => {
+            Some((t.bit_width().unwrap_or(u64::from(cx.tcx.sess.target.pointer_width)), false))
         _ => None,
     }
 }
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --stage 2 src/tools/tidy
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test --stage 2 src/tools/tidy
Build completed unsuccessfully in 0:00:14
== clock drift check ==
  local time: Sat Nov  7 21:01:25 UTC 2020
  network time: Sat, 07 Nov 2020 00:15:56 GMT
== end clock drift check ==
##[error]Process completed with exit code 1.
[command]/usr/bin/git version
git version 2.29.2
[command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
[command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :

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 @rust-lang/infra. (Feature Requests)

@Nicholas-Baron
Copy link
Contributor Author

@the8472 I rolled up all 20 of my changes into one revert commit. Yes, I have wasted my time with 20 one line commits and I really should learn from that.

@lcnr
Copy link
Contributor

lcnr commented Nov 10, 2020

LGTM. I do however think 14 commits is a bit too much for this PR, r=me after you did some squashing here

@Nicholas-Baron Nicholas-Baron force-pushed the unwrap_or_corrected branch 3 times, most recently from 2cae639 to d29869c Compare November 10, 2020 23:13
@Nicholas-Baron
Copy link
Contributor Author

@lcnr Squashed this PR down to 4 commits and rebased it onto the latest master.

@Mark-Simulacrum
Copy link
Member

Last 3 commits look like they'd just be noise in the commit log? Is there a reason why they were kept?

@Nicholas-Baron
Copy link
Contributor Author

Last 3 commits look like they'd just be noise in the commit log? Is there a reason why they were kept?

The 2nd commit is a revert explaining why. I could merge the last 3 into one commit.

@Mark-Simulacrum
Copy link
Member

I do not think there should be more than 1 commit here, personally. I think it is useful to have standalone commits if they have distinct contents from other commits in the PR, which is not the case here. Generally in-PR reverts just don't make sense for preserving indefinitely.

@Nicholas-Baron
Copy link
Contributor Author

I do not think there should be more than 1 commit here, personally. I think it is useful to have standalone commits if they have distinct contents from other commits in the PR, which is not the case here. Generally in-PR reverts just don't make sense for preserving indefinitely.

Ok, squashing into 1 commit

The discussion seems to have resolved that this lint is a bit "noisy" in
that applying it in all places would result in a reduction in
readability.

A few of the trivial functions (like `Path::new`) are fine to leave
outside of closures.

The general rule seems to be that anything that is obviously an
allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it
is a 0-sized allocation.
@lcnr
Copy link
Contributor

lcnr commented Nov 11, 2020

Thanks 👍

@bors r+

@bors
Copy link
Contributor

bors commented Nov 11, 2020

📌 Commit 261ca04 has been approved by lcnr

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 11, 2020

@Nicholas-Baron btw, there were recently a bunch of clippy bugs fixed, so I would expect x.py clippy --fix to have low-hanging fruit (previously clippy would error out while applying suggestions).

@bors
Copy link
Contributor

bors commented Nov 11, 2020

⌛ Testing commit 261ca04 with merge d4ea0b3...

@bors
Copy link
Contributor

bors commented Nov 11, 2020

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing d4ea0b3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 11, 2020
@bors bors merged commit d4ea0b3 into rust-lang:master Nov 11, 2020
@rustbot rustbot added this to the 1.49.0 milestone Nov 11, 2020
@Nicholas-Baron Nicholas-Baron deleted the unwrap_or_corrected branch November 11, 2020 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.