Auto merge of #49458 - cramertj:stable-underscore-lt, r=nikomatsakis

Stabilize underscore lifetimes

r? @nikomatsakis
This commit is contained in:
bors 2018-03-29 00:41:15 +00:00
commit 1e652bda20
32 changed files with 27 additions and 82 deletions

View File

@ -68,7 +68,7 @@
#![feature(slice_patterns)] #![feature(slice_patterns)]
#![feature(specialization)] #![feature(specialization)]
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
#![feature(underscore_lifetimes)] #![cfg_attr(stage0, feature(underscore_lifetimes))]
#![cfg_attr(stage0, feature(universal_impl_trait))] #![cfg_attr(stage0, feature(universal_impl_trait))]
#![feature(trace_macros)] #![feature(trace_macros)]
#![feature(trusted_len)] #![feature(trusted_len)]

View File

@ -30,7 +30,7 @@
#![cfg_attr(stage0, feature(i128_type, i128))] #![cfg_attr(stage0, feature(i128_type, i128))]
#![feature(specialization)] #![feature(specialization)]
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(underscore_lifetimes)] #![cfg_attr(stage0, feature(underscore_lifetimes))]
#![feature(macro_vis_matcher)] #![feature(macro_vis_matcher)]
#![feature(allow_internal_unstable)] #![feature(allow_internal_unstable)]
#![cfg_attr(stage0, feature(universal_impl_trait))] #![cfg_attr(stage0, feature(universal_impl_trait))]

View File

@ -37,7 +37,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(placement_in_syntax)] #![feature(placement_in_syntax)]
#![feature(collection_placement)] #![feature(collection_placement)]
#![feature(nonzero)] #![feature(nonzero)]
#![feature(underscore_lifetimes)] #![cfg_attr(stage0, feature(underscore_lifetimes))]
#![cfg_attr(stage0, feature(never_type))] #![cfg_attr(stage0, feature(never_type))]
#![feature(inclusive_range_fields)] #![feature(inclusive_range_fields)]

View File

@ -15,7 +15,7 @@
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![cfg_attr(stage0, feature(match_default_bindings))] #![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(underscore_lifetimes)] #![cfg_attr(stage0, feature(underscore_lifetimes))]
#[macro_use] #[macro_use]
extern crate log; extern crate log;

View File

@ -385,6 +385,9 @@ declare_features! (
// allow `'_` placeholder lifetimes // allow `'_` placeholder lifetimes
(active, underscore_lifetimes, "1.22.0", Some(44524), None), (active, underscore_lifetimes, "1.22.0", Some(44524), None),
// Default match binding modes (RFC 2005)
(active, match_default_bindings, "1.22.0", Some(42640), None),
// Trait object syntax with `dyn` prefix // Trait object syntax with `dyn` prefix
(active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)), (active, dyn_trait, "1.22.0", Some(44662), Some(Edition::Edition2018)),
@ -562,6 +565,8 @@ declare_features! (
(accepted, i128_type, "1.26.0", Some(35118), None), (accepted, i128_type, "1.26.0", Some(35118), None),
// Default match binding modes (RFC 2005) // Default match binding modes (RFC 2005)
(accepted, match_default_bindings, "1.26.0", Some(42640), None), (accepted, match_default_bindings, "1.26.0", Some(42640), None),
// allow `'_` placeholder lifetimes
(accepted, underscore_lifetimes, "1.26.0", Some(44524), None),
); );
// If you change this, please modify src/doc/unstable-book as well. You must // If you change this, please modify src/doc/unstable-book as well. You must
@ -1792,14 +1797,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_generic_param(self, param) visit::walk_generic_param(self, param)
} }
fn visit_lifetime(&mut self, lt: &'a ast::Lifetime) {
if lt.ident.name == keywords::UnderscoreLifetime.name() {
gate_feature_post!(&self, underscore_lifetimes, lt.span,
"underscore lifetimes are unstable");
}
visit::walk_lifetime(self, lt)
}
} }
pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],

View File

@ -10,7 +10,6 @@
// must-compile-successfully // must-compile-successfully
#![feature(underscore_lifetimes)]
#![allow(warnings)] #![allow(warnings)]
type Different<'a, 'b> = &'a mut (&'a (), &'b ()); type Different<'a, 'b> = &'a mut (&'a (), &'b ());

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(underscore_lifetimes)]
fn with_closure_expecting_fn_with_free_region<F>(_: F) fn with_closure_expecting_fn_with_free_region<F>(_: F)
where F: for<'a> FnOnce(fn(&'a u32), &i32) where F: for<'a> FnOnce(fn(&'a u32), &i32)
{ {

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(underscore_lifetimes)]
struct Foo<'a>(&'a u8); struct Foo<'a>(&'a u8);
struct Baz<'a>(&'_ &'a u8); //~ ERROR missing lifetime specifier struct Baz<'a>(&'_ &'a u8); //~ ERROR missing lifetime specifier

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(underscore_lifetimes)]
fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } //~ ERROR lifetime mismatch fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } //~ ERROR lifetime mismatch
fn main() {} fn main() {}

View File

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(underscore_lifetimes)]
#![allow(warnings)] #![allow(warnings)]
use std::fmt::Debug; use std::fmt::Debug;

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(underscore_lifetimes)]
struct Foo<'a>(&'a u8); struct Foo<'a>(&'a u8);
fn foo(x: &u8) -> Foo<'_> { fn foo(x: &u8) -> Foo<'_> {

View File

@ -7,7 +7,6 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#![feature(underscore_lifetimes)]
struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_` struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_`
fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_` fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_`

View File

@ -1,17 +1,17 @@
error[E0637]: invalid lifetime bound name: `'_` error[E0637]: invalid lifetime bound name: `'_`
--> $DIR/E0637.rs:12:16 --> $DIR/E0637.rs:11:16
| |
LL | struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_` LL | struct Foo<'a: '_>(&'a u8); //~ ERROR invalid lifetime bound name: `'_`
| ^^ `'_` is a reserved lifetime name | ^^ `'_` is a reserved lifetime name
error[E0637]: invalid lifetime bound name: `'_` error[E0637]: invalid lifetime bound name: `'_`
--> $DIR/E0637.rs:13:12 --> $DIR/E0637.rs:12:12
| |
LL | fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_` LL | fn foo<'a: '_>(_: &'a u8) {} //~ ERROR invalid lifetime bound name: `'_`
| ^^ `'_` is a reserved lifetime name | ^^ `'_` is a reserved lifetime name
error[E0637]: invalid lifetime bound name: `'_` error[E0637]: invalid lifetime bound name: `'_`
--> $DIR/E0637.rs:16:10 --> $DIR/E0637.rs:15:10
| |
LL | impl<'a: '_> Bar<'a> { //~ ERROR invalid lifetime bound name: `'_` LL | impl<'a: '_> Bar<'a> { //~ ERROR invalid lifetime bound name: `'_`
| ^^ `'_` is a reserved lifetime name | ^^ `'_` is a reserved lifetime name

View File

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
#![allow(warnings)] #![allow(warnings)]
#![feature(underscore_lifetimes)]
trait MyTrait<'a> { } trait MyTrait<'a> { }

View File

@ -1,11 +1,11 @@
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/feature-gate-in_band_lifetimes-impl.rs:16:26 --> $DIR/feature-gate-in_band_lifetimes-impl.rs:15:26
| |
LL | impl<'a> MyTrait<'a> for &u32 { } LL | impl<'a> MyTrait<'a> for &u32 { }
| ^ expected lifetime parameter | ^ expected lifetime parameter
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/feature-gate-in_band_lifetimes-impl.rs:19:18 --> $DIR/feature-gate-in_band_lifetimes-impl.rs:18:18
| |
LL | impl<'a> MyTrait<'_> for &'a f32 { } LL | impl<'a> MyTrait<'_> for &'a f32 { }
| ^^ expected lifetime parameter | ^^ expected lifetime parameter

View File

@ -1,20 +0,0 @@
// 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);
}

View File

@ -1,11 +0,0 @@
error[E0658]: underscore lifetimes are unstable (see issue #44524)
--> $DIR/feature-gate-underscore-lifetimes.rs:13:23
|
LL | fn foo(x: &u8) -> Foo<'_> { //~ ERROR underscore lifetimes are unstable
| ^^
|
= help: add #![feature(underscore_lifetimes)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -14,7 +14,6 @@
#![allow(warnings)] #![allow(warnings)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
trait MyTrait { trait MyTrait {
type Output; type Output;

View File

@ -1,11 +1,11 @@
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/assoc-type.rs:24:19 --> $DIR/assoc-type.rs:23:19
| |
LL | type Output = &i32; LL | type Output = &i32;
| ^ expected lifetime parameter | ^ expected lifetime parameter
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/assoc-type.rs:29:20 --> $DIR/assoc-type.rs:28:20
| |
LL | type Output = &'_ i32; LL | type Output = &'_ i32;
| ^^ expected lifetime parameter | ^^ expected lifetime parameter

View File

@ -15,7 +15,6 @@
#![feature(dyn_trait)] #![feature(dyn_trait)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
use std::fmt::Debug; use std::fmt::Debug;

View File

@ -1,11 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/dyn-trait.rs:34:16 --> $DIR/dyn-trait.rs:33:16
| |
LL | static_val(x); //~ ERROR cannot infer LL | static_val(x); //~ ERROR cannot infer
| ^ | ^
| |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 33:1... note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 32:1...
--> $DIR/dyn-trait.rs:33:1 --> $DIR/dyn-trait.rs:32:1
| |
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) { LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -10,7 +10,6 @@
#![allow(warnings)] #![allow(warnings)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
trait MyTrait { } trait MyTrait { }

View File

@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/path-elided.rs:19:18 --> $DIR/path-elided.rs:18:18
| |
LL | impl MyTrait for Foo { LL | impl MyTrait for Foo {
| ^^^ expected lifetime parameter | ^^^ expected lifetime parameter

View File

@ -15,7 +15,6 @@
#![allow(warnings)] #![allow(warnings)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
trait MyTrait { } trait MyTrait { }

View File

@ -15,7 +15,6 @@
#![allow(warnings)] #![allow(warnings)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
trait MyTrait { } trait MyTrait { }

View File

@ -10,7 +10,6 @@
#![allow(warnings)] #![allow(warnings)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
trait MyTrait<'a> { } trait MyTrait<'a> { }

View File

@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/trait-elided.rs:17:6 --> $DIR/trait-elided.rs:16:6
| |
LL | impl MyTrait for u32 { LL | impl MyTrait for u32 {
| ^^^^^^^ expected lifetime parameter | ^^^^^^^ expected lifetime parameter

View File

@ -16,7 +16,6 @@
#![allow(warnings)] #![allow(warnings)]
#![feature(in_band_lifetimes)] #![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]
trait MyTrait<'a> { } trait MyTrait<'a> { }

View File

@ -14,7 +14,6 @@
// cc #48468 // cc #48468
#![feature(dyn_trait)] #![feature(dyn_trait)]
#![feature(underscore_lifetimes)]
use std::fmt::Debug; use std::fmt::Debug;

View File

@ -1,11 +1,11 @@
error[E0106]: missing lifetime specifier error[E0106]: missing lifetime specifier
--> $DIR/dyn-trait-underscore-in-struct.rs:22:24 --> $DIR/dyn-trait-underscore-in-struct.rs:21:24
| |
LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier
| ^^ expected lifetime parameter | ^^ expected lifetime parameter
error[E0228]: the lifetime bound for this object type cannot be deduced from context; please supply an explicit bound error[E0228]: the lifetime bound for this object type cannot be deduced from context; please supply an explicit bound
--> $DIR/dyn-trait-underscore-in-struct.rs:22:12 --> $DIR/dyn-trait-underscore-in-struct.rs:21:12
| |
LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier LL | x: Box<dyn Debug + '_>, //~ ERROR missing lifetime specifier
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^

View File

@ -14,7 +14,6 @@
// cc #48468 // cc #48468
#![feature(dyn_trait)] #![feature(dyn_trait)]
#![feature(underscore_lifetimes)]
fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> { fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
// ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static` // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`

View File

@ -1,11 +1,11 @@
error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
--> $DIR/dyn-trait-underscore.rs:21:20 --> $DIR/dyn-trait-underscore.rs:20:20
| |
LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
| ^^^^ | ^^^^
| |
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 19:1... note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 18:1...
--> $DIR/dyn-trait-underscore.rs:19:1 --> $DIR/dyn-trait-underscore.rs:18:1
| |
LL | / fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> { LL | / fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
LL | | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static` LL | | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
@ -13,7 +13,7 @@ LL | | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
LL | | } LL | | }
| |_^ | |_^
note: ...so that reference does not outlive borrowed content note: ...so that reference does not outlive borrowed content
--> $DIR/dyn-trait-underscore.rs:21:14 --> $DIR/dyn-trait-underscore.rs:20:14
| |
LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
| ^^^^^ | ^^^^^