forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
structured suggestions for single-use lifetime lint on fns and methods
It would be nice to demonstrate the shining correctness here with more run-rustfix tests than this, but unfortunately, that doesn't work with multipart suggestions yet (rust-lang#53934). While we're here, reword the zero-use lifetime suggestion to "elide the unused lifetime" instead of "remove it". (It's classier.)
- Loading branch information
1 parent
1982f18
commit fd28753
Showing
14 changed files
with
168 additions
and
36 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
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