-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #55432 - zackmdavis:single_life, r=nikomatsakis
single life * structured ~~autofixable~~ (well, pending #53934 and rust-lang/rustfix#141) suggestions for the single-use-lifetimes lint in the case of function and method reference args * don't consider the anonymous lifetime `'_` as "single-use" (it's intended for exactly this sort of thing)  r? @nikomatsakis
- Loading branch information
Showing
16 changed files
with
181 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// run-rustfix | ||
|
||
#![feature(in_band_lifetimes)] | ||
#![deny(single_use_lifetimes)] | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
// Test that we DO warn when lifetime name is used only | ||
// once in a fn argument, even with in band lifetimes. | ||
|
||
fn a(x: &u32, y: &u32) { | ||
//~^ ERROR `'a` only used once | ||
//~| ERROR `'b` only used once | ||
//~| HELP elide the single-use lifetime | ||
//~| HELP elide the single-use lifetime | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
error: lifetime parameter `'a` only used once | ||
--> $DIR/one-use-in-fn-argument-in-band.rs:19:10 | ||
--> $DIR/one-use-in-fn-argument-in-band.rs:21:10 | ||
| | ||
LL | fn a(x: &'a u32, y: &'b u32) { | ||
| ^^ | ||
| ^^- | ||
| | | ||
| this lifetime... | ||
| ...is used only here | ||
| this lifetime is only used here | ||
| help: elide the single-use lifetime | ||
| | ||
note: lint level defined here | ||
--> $DIR/one-use-in-fn-argument-in-band.rs:12:9 | ||
--> $DIR/one-use-in-fn-argument-in-band.rs:14:9 | ||
| | ||
LL | #![deny(single_use_lifetimes)] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: lifetime parameter `'b` only used once | ||
--> $DIR/one-use-in-fn-argument-in-band.rs:19:22 | ||
--> $DIR/one-use-in-fn-argument-in-band.rs:21:22 | ||
| | ||
LL | fn a(x: &'a u32, y: &'b u32) { | ||
| ^^ | ||
| ^^- | ||
| | | ||
| this lifetime... | ||
| ...is used only here | ||
| this lifetime is only used here | ||
| help: elide the single-use lifetime | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.