Rollup merge of #55173 - estebank:suggest-static, r=oli-obk
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. Fix #55170.
This commit is contained in:
commit
f50e285e30
13 changed files with 106 additions and 48 deletions
|
|
@ -2,10 +2,9 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/bound-lifetime-in-binding-only.rs:62:23
|
||||
|
|
||||
LL | fn elision<T: Fn() -> &i32>() {
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it a 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/bound-lifetime-in-return-only.rs:44:23
|
||||
|
|
||||
LL | fn elision(_: fn() -> &i32) {
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it a 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
18
src/test/ui/foreign-fn-return-lifetime.fixed
Normal file
18
src/test/ui/foreign-fn-return-lifetime.fixed
Normal file
|
|
@ -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() {}
|
||||
|
|
@ -8,9 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// run-rustfix
|
||||
|
||||
extern "C" {
|
||||
fn g(_: &u8) -> &u8; // OK
|
||||
fn f() -> &u8; //~ ERROR missing lifetime specifier
|
||||
pub fn g(_: &u8) -> &u8; // OK
|
||||
pub fn f() -> &u8; //~ ERROR missing lifetime specifier
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/foreign-fn-return-lifetime.rs:13:15
|
||||
--> $DIR/foreign-fn-return-lifetime.rs:15:19
|
||||
|
|
||||
LL | fn f() -> &u8; //~ ERROR missing lifetime specifier
|
||||
| ^ expected lifetime parameter
|
||||
LL | pub fn f() -> &u8; //~ ERROR missing lifetime specifier
|
||||
| ^ help: consider giving it a 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/issue-13497.rs:12:5
|
||||
|
|
||||
LL | &str //~ ERROR missing lifetime specifier
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it a 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -10,19 +10,17 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/issue-26638.rs:14:40
|
||||
|
|
||||
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it an explicit bounded or 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
= help: consider giving it an explicit bounded or 'static lifetime
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/issue-26638.rs:17:22
|
||||
|
|
||||
LL | fn parse_type_3() -> &str { unimplemented!() }
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it a 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:12:11
|
||||
|
|
||||
LL | fn f() -> &isize { //~ ERROR missing lifetime specifier
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it a 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:17:33
|
||||
|
|
@ -27,28 +26,25 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:31:20
|
||||
|
|
||||
LL | fn i(_x: isize) -> &isize { //~ ERROR missing lifetime specifier
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it an explicit bounded or 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
= help: consider giving it an explicit bounded or 'static lifetime
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:44:24
|
||||
|
|
||||
LL | fn j(_x: StaticStr) -> &isize { //~ ERROR missing lifetime specifier
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it an explicit bounded or 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
= help: consider giving it an explicit bounded or 'static lifetime
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:50:49
|
||||
|
|
||||
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
|
||||
| ^ expected lifetime parameter
|
||||
| ^ help: consider giving it an explicit bounded or 'static lifetime: `&'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
= help: consider giving it an explicit bounded or 'static lifetime
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
12
src/test/ui/lifetimes/lifetime-elision-return-type-trait.rs
Normal file
12
src/test/ui/lifetimes/lifetime-elision-return-type-trait.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
trait Future {
|
||||
type Item;
|
||||
type Error;
|
||||
}
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
fn foo() -> impl Future<Item=(), Error=Box<Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/lifetime-elision-return-type-trait.rs:8:44
|
||||
|
|
||||
LL | fn foo() -> impl Future<Item=(), Error=Box<Error>> {
|
||||
| ^^^^^ 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 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0106`.
|
||||
|
|
@ -20,10 +20,9 @@ error[E0106]: missing lifetime specifier
|
|||
--> $DIR/underscore-lifetime-binders.rs:20:29
|
||||
|
|
||||
LL | fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR cannot be used here
|
||||
| ^^ expected lifetime parameter
|
||||
| ^^ help: consider giving it a 'static lifetime: `'static`
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
= help: consider giving it a 'static lifetime
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/underscore-lifetime-binders.rs:26:35
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue