Auto merge of #44691 - cramertj:underscore-lifetimes, r=nikomatsakis
Implement underscore lifetimes Part of https://github.com/rust-lang/rust/issues/44524
This commit is contained in:
commit
3eb19bf9b1
21 changed files with 259 additions and 62 deletions
20
src/test/compile-fail/E0637.rs
Normal file
20
src/test/compile-fail/E0637.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// 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.
|
||||
#![feature(underscore_lifetimes)]
|
||||
|
||||
struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_`
|
||||
fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_`
|
||||
|
||||
struct Bar<'a>(&'a u8);
|
||||
impl<'a: '_> Bar<'a> { //~ ERROR invalid lifetime bound name: `'_`
|
||||
fn bar() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
20
src/test/compile-fail/feature-gate-underscore-lifetimes.rs
Normal file
20
src/test/compile-fail/feature-gate-underscore-lifetimes.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// 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.
|
||||
|
||||
struct Foo<'a>(&'a u8);
|
||||
|
||||
fn foo(x: &u8) -> Foo<'_> { //~ ERROR underscore lifetimes are unstable
|
||||
Foo(x)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 5;
|
||||
let _ = foo(&x);
|
||||
}
|
||||
|
|
@ -8,12 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn _f<'_>() //~ ERROR invalid lifetime name `'_`
|
||||
-> &'_ u8 //~ ERROR invalid lifetime name `'_`
|
||||
{
|
||||
panic!();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
'_: loop { //~ ERROR invalid label name `'_`
|
||||
break '_ //~ ERROR invalid label name `'_`
|
||||
39
src/test/compile-fail/underscore-lifetime-binders.rs
Normal file
39
src/test/compile-fail/underscore-lifetime-binders.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// 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.
|
||||
|
||||
#![feature(underscore_lifetimes)]
|
||||
|
||||
struct Foo<'a>(&'a u8);
|
||||
struct Baz<'a>(&'_ &'a u8); //~ ERROR missing lifetime specifier
|
||||
|
||||
impl Foo<'_> { //~ ERROR missing lifetime specifier
|
||||
fn x() {}
|
||||
}
|
||||
|
||||
fn foo<'_> //~ ERROR invalid lifetime parameter name: `'_`
|
||||
(_: Foo<'_>) {}
|
||||
|
||||
trait Meh<'a> {}
|
||||
impl<'a> Meh<'a> for u8 {}
|
||||
|
||||
fn meh() -> Box<for<'_> Meh<'_>> //~ ERROR invalid lifetime parameter name: `'_`
|
||||
//~^ ERROR missing lifetime specifier
|
||||
//~^^ ERROR missing lifetime specifier
|
||||
{
|
||||
Box::new(5u8)
|
||||
}
|
||||
|
||||
fn foo2(_: &'_ u8, y: &'_ u8) -> &'_ u8 { y } //~ ERROR missing lifetime specifier
|
||||
|
||||
fn main() {
|
||||
let x = 5;
|
||||
foo(Foo(&x));
|
||||
let _ = meh();
|
||||
}
|
||||
15
src/test/compile-fail/underscore-lifetime-elison-mismatch.rs
Normal file
15
src/test/compile-fail/underscore-lifetime-elison-mismatch.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// 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.
|
||||
|
||||
#![feature(underscore_lifetimes)]
|
||||
|
||||
fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } //~ ERROR lifetime mismatch
|
||||
|
||||
fn main() {}
|
||||
47
src/test/run-pass/underscore-lifetimes.rs
Normal file
47
src/test/run-pass/underscore-lifetimes.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// 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.
|
||||
|
||||
#![feature(underscore_lifetimes)]
|
||||
|
||||
struct Foo<'a>(&'a u8);
|
||||
|
||||
fn foo(x: &u8) -> Foo<'_> {
|
||||
Foo(x)
|
||||
}
|
||||
|
||||
fn foo2(x: &'_ u8) -> Foo<'_> {
|
||||
Foo(x)
|
||||
}
|
||||
|
||||
fn foo3(x: &'_ u8) -> Foo {
|
||||
Foo(x)
|
||||
}
|
||||
|
||||
fn foo4(_: Foo<'_>) {}
|
||||
|
||||
struct Foo2<'a, 'b> {
|
||||
a: &'a u8,
|
||||
b: &'b u8,
|
||||
}
|
||||
fn foo5<'b>(foo: Foo2<'_, 'b>) -> &'b u8 {
|
||||
foo.b
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = &5;
|
||||
let _ = foo(x);
|
||||
let _ = foo2(x);
|
||||
let _ = foo3(x);
|
||||
foo4(Foo(x));
|
||||
let _ = foo5(Foo2 {
|
||||
a: x,
|
||||
b: &6,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue