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

Improve single-use and zero-use lifetime lints #50440

Merged
merged 6 commits into from May 11, 2018

Conversation

nikomatsakis
Copy link
Contributor

The code now correctly identifies when to lint -- or more correctly, anyhow -- but it doesn't yet offer suggestions for how to fix.

(I just remembered when writing this I had meant to go back over some of these cases around e.g. impl Trait and double check that everything is right...)

cc #44752

r? @cramertj

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 2018
@cramertj
Copy link
Member

cramertj commented May 4, 2018

@bors r+

I just remembered when writing this I had meant to go back over some of these cases around e.g. impl Trait and double check that everything is right...)

fn foo(x: impl Iterator<Item=&()>) { ... } is still an error-- you need to write fn foo<'a>(x: impl Iterator<Item = &'a ()>) {}. I think that this PR shouldn't affect this case since impl Trait isn't allowed impl impl headers currently.

@bors
Copy link
Contributor

bors commented May 4, 2018

📌 Commit 0a9dcaf has been approved by cramertj

@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 May 4, 2018
@bors
Copy link
Contributor

bors commented May 5, 2018

⌛ Testing commit 0a9dcaf with merge 5ffe9f96ef840b9ac2262cf86beab13336598b9b...

@bors
Copy link
Contributor

bors commented May 5, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 5, 2018
@kennytm kennytm 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 6, 2018
@kennytm
Copy link
Member

kennytm commented May 6, 2018

Unstable lint emission order.

---- [ui] ui\single-use-lifetime\one-use-in-fn-argument-in-band.rs stdout ----
	diff of stderr:
-	error: lifetime parameter `'b` only used once
-	  --> $DIR/one-use-in-fn-argument-in-band.rs:19:22
+	error: lifetime parameter `'a` only used once
+	  --> $DIR/one-use-in-fn-argument-in-band.rs:19:10
3	   |
4	LL | fn a(x: &'a u32, y: &'b u32) {
-	   |                      ^^
+	   |          ^^
6	   |
7	note: lint level defined here
8	  --> $DIR/one-use-in-fn-argument-in-band.rs:12:9
10	LL | #![deny(single_use_lifetime)]
11	   |         ^^^^^^^^^^^^^^^^^^^
12	
-	error: lifetime parameter `'a` only used once
-	  --> $DIR/one-use-in-fn-argument-in-band.rs:19:10
+	error: lifetime parameter `'b` only used once
+	  --> $DIR/one-use-in-fn-argument-in-band.rs:19:22
15	   |
16	LL | fn a(x: &'a u32, y: &'b u32) {
-	   |          ^^
+	   |                      ^^
18	
19	error: aborting due to 2 previous errors
20	

@nikomatsakis nikomatsakis force-pushed the single-use-lifetimes branch 3 times, most recently from d4ac8bf to c0105be Compare May 10, 2018 23:10
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 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.
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading https://files.pythonhosted.org/packages/18/61/4e0f977cfe063188d73622a91cab8b8b409b662f422303fc687f362d941f/awscli-1.15.18-py2.py3-none-any.whl (1.3MB)
    0% |▎                               | 10kB 10.0MB/s eta 0:00:01
    1% |▌                               | 20kB 1.7MB/s eta 0:00:01
    2% |▉                               | 30kB 1.9MB/s eta 0:00:01
    3% |█                               | 40kB 1.9MB/s eta 0:00:01
---
[00:05:37]    Compiling arena v0.0.0 (file:///checkout/src/libarena)
[00:05:45]    Compiling rustc_errors v0.0.0 (file:///checkout/src/librustc_errors)
[00:07:15]    Compiling proc_macro v0.0.0 (file:///checkout/src/libproc_macro)
[00:07:31]    Compiling syntax_ext v0.0.0 (file:///checkout/src/libsyntax_ext)
[00:08:44] error[E0596]: cannot borrow immutable local variable `def_ids` as mutable
[00:08:44]     --> librustc/middle/resolve_lifetime.rs:1320:9
[00:08:44]      |
[00:08:44] 1309 |         let def_ids: Vec<_> = defined_by.values()
[00:08:44]      |             ------- consider changing this to `mut def_ids`
[00:08:44] ...
[00:08:44] 1320 |         def_ids.sort_by_key(|&def_id| self.tcx.def_path_hash(def_id));
[00:08:44]      |         ^^^^^^^ cannot borrow mutably
[00:08:48] error: aborting due to previous error
[00:08:48] 
[00:08:48] For more information about this error, try `rustc --explain E0596`.
[00:08:48] error: Could not compile `rustc`.
[00:08:48] error: Could not compile `rustc`.
[00:08:48] 
[00:08:48] Caused by:
[00:08:48]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name rustc librustc/lib.rs --color always --error-format json --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C opt-level=3 -C metadata=dec7324c263ceb0f -C extra-filename=-dec7324c263ceb0f --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps --extern fmt_macros=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libfmt_macros-33787dcdac3a4dd2.so --extern rustc_apfloat=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_apfloat-b7c66a9cab3ff5a6.rlib --extern backtrace=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libbacktrace-24d411fab3d9dcf5.rlib --extern rustc_errors=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_errors-b789a86e1ab64d11.so --extern serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-946eff7380f27f57.so --extern serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-946eff7380f27f57.rlib --extern graphviz=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libgraphviz-21ce4bd19908f0cc.so --extern flate2=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libflate2-d0ff1c27bea11ea7.rlib --extern lazy_static=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblazy_static-fbe97ade1df6b749.rlib --extern bitflags=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libbitflags-401bddd0d1809e53.rlib --extern proc_macro=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libproc_macro-8d928be2ff984c7f.so --extern rustc_data_structures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_data_structures-f456f53371aa074c.so --extern arena=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libarena-16776be762f4e8c2.so --extern jobserver=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libjobserver-dd375c0772cf1a0d.rlib --extern rustc_target=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_target-aed9d8ab86b35123.so --extern syntax=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax-566a8d95e6a18781.so --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-4f0866e958f59455.rlib --extern syntax_pos=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_pos-b9901acb1e9e6766.so --extern tempdir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libtempdir-ee923a086d887011.rlib --extern byteorder=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libbyteorder-c0908caf79d2e3f2.rlib -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/backtrace-sys-ffd9dcc5ce13143f/out/.libs -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/miniz-sys-41d448831c9d08f1/out` (exit code: 101)
[00:08:48] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:08:48] expected success, got: exit code: 101
[00:08:48] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1091:9
[00:08:48] travis_fold:end:stage0-rustc

[00:08:48] travis_time:end:stage0-rustc:start=1525994255724930212,finish=1525994486492290376,duration=230767360164


[00:08:48] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:08:48] Build completed unsuccessfully in 0:04:04
[00:08:48] Makefile:28: recipe for target 'all' failed
[00:08:48] make: *** [all] Error 1
47168 ./src/test
46812 ./obj/build/x86_64-unknown-linux-gnu/stage0-std/release
46352 ./src/llvm/test/MC
44444 ./obj/build/x86_64-unknown-linux-gnu/stage0-std/release/build

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)

@nikomatsakis
Copy link
Contributor Author

@bors r=cramertj

@bors
Copy link
Contributor

bors commented May 10, 2018

📌 Commit 6f98ee9 has been approved by cramertj

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 10, 2018
@bors
Copy link
Contributor

bors commented May 11, 2018

⌛ Testing commit 6f98ee9 with merge 4e5a155...

bors added a commit that referenced this pull request May 11, 2018
Improve single-use and zero-use lifetime lints

The code now correctly identifies *when* to lint -- or more correctly, anyhow -- but it doesn't yet offer suggestions for how to fix.

(I just remembered when writing this I had meant to go back over some of these cases around e.g. impl Trait and double check that everything is right...)

cc #44752

r? @cramertj
@bors
Copy link
Contributor

bors commented May 11, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: cramertj
Pushing 4e5a155 to master...

@bors bors merged commit 6f98ee9 into rust-lang:master May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants