Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest appropriate syntax on missing lifetime specifier in return type
Suggest using `'static` when a lifetime is missing in the return type with a structured suggestion instead of a note.
- Loading branch information
Showing
13 changed files
with
146 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2017 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 | ||
|
||
extern "C" { | ||
pub fn g(_: &u8) -> &u8; // OK | ||
pub fn f() -> &'static u8; //~ ERROR missing lifetime specifier | ||
} | ||
|
||
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
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
10 changes: 10 additions & 0 deletions
10
src/test/ui/lifetimes/lifetime-elision-return-type-trait.rs
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,10 @@ | ||
trait Future { | ||
type Item; | ||
type Error; | ||
} | ||
|
||
use std::error::Error; | ||
|
||
fn foo() -> impl Future<Item=(), Error=Box<Error>> { | ||
Ok(()) | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/lifetimes/lifetime-elision-return-type-trait.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0601]: `main` function not found in crate `lifetime_elision_return_type_trait` | ||
| | ||
= note: consider adding a `main` function to `$DIR/lifetime-elision-return-type-trait.rs` | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/lifetime-elision-return-type-trait.rs:8:44 | ||
| | ||
LL | fn foo() -> impl Future<Item=(), Error=Box<Error>> { | ||
| ^^^^^ | ||
| | | ||
| expected lifetime parameter | ||
| help: consider giving it a 'static lifetime: `Error + 'static` | ||
| | ||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors occurred: E0106, E0601. | ||
For more information about an error, try `rustc --explain E0106`. |
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