Skip to content

Stabilize underscore lifetimes #49458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@
#![feature(slice_patterns)]
#![feature(specialization)]
#![feature(unboxed_closures)]
#![feature(underscore_lifetimes)]
#![cfg_attr(stage0, feature(underscore_lifetimes))]
#![cfg_attr(stage0, feature(universal_impl_trait))]
#![feature(trace_macros)]
#![feature(trusted_len)]
2 changes: 1 addition & 1 deletion src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
#![cfg_attr(stage0, feature(i128_type, i128))]
#![feature(specialization)]
#![feature(optin_builtin_traits)]
#![feature(underscore_lifetimes)]
#![cfg_attr(stage0, feature(underscore_lifetimes))]
#![feature(macro_vis_matcher)]
#![feature(allow_internal_unstable)]
#![cfg_attr(stage0, feature(universal_impl_trait))]
2 changes: 1 addition & 1 deletion src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(placement_in_syntax)]
#![feature(collection_placement)]
#![feature(nonzero)]
#![feature(underscore_lifetimes)]
#![cfg_attr(stage0, feature(underscore_lifetimes))]
#![cfg_attr(stage0, feature(never_type))]
#![feature(inclusive_range_fields)]

2 changes: 1 addition & 1 deletion src/librustc_traits/lib.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

#![feature(crate_visibility_modifier)]
#![cfg_attr(stage0, feature(match_default_bindings))]
#![feature(underscore_lifetimes)]
#![cfg_attr(stage0, feature(underscore_lifetimes))]

#[macro_use]
extern crate log;
13 changes: 5 additions & 8 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -385,6 +385,9 @@ declare_features! (
// allow `'_` placeholder lifetimes
(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
(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),
// Default match binding modes (RFC 2005)
(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
@@ -1792,14 +1797,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {

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],
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@

// must-compile-successfully

#![feature(underscore_lifetimes)]
#![allow(warnings)]

type Different<'a, 'b> = &'a mut (&'a (), &'b ());
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(underscore_lifetimes)]

fn with_closure_expecting_fn_with_free_region<F>(_: F)
where F: for<'a> FnOnce(fn(&'a u32), &i32)
{
2 changes: 0 additions & 2 deletions src/test/compile-fail/underscore-lifetime-binders.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
// 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

2 changes: 0 additions & 2 deletions src/test/compile-fail/underscore-lifetime-elison-mismatch.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
// 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() {}
1 change: 0 additions & 1 deletion src/test/run-pass/impl-trait/lifetimes.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(underscore_lifetimes)]
#![allow(warnings)]

use std::fmt::Debug;
2 changes: 0 additions & 2 deletions src/test/run-pass/underscore-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -8,8 +8,6 @@
// 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<'_> {
1 change: 0 additions & 1 deletion src/test/ui/error-codes/E0637.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
// <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: `'_`
6 changes: 3 additions & 3 deletions src/test/ui/error-codes/E0637.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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: `'_`
| ^^ `'_` is a reserved lifetime 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: `'_`
| ^^ `'_` is a reserved lifetime 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: `'_`
| ^^ `'_` is a reserved lifetime name
1 change: 0 additions & 1 deletion src/test/ui/feature-gate-in_band_lifetimes-impl.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
// except according to those terms.

#![allow(warnings)]
#![feature(underscore_lifetimes)]

trait MyTrait<'a> { }

4 changes: 2 additions & 2 deletions src/test/ui/feature-gate-in_band_lifetimes-impl.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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 { }
| ^ expected lifetime parameter

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 { }
| ^^ expected lifetime parameter
20 changes: 0 additions & 20 deletions src/test/ui/feature-gate-underscore-lifetimes.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/feature-gate-underscore-lifetimes.stderr

This file was deleted.

1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/assoc-type.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
#![allow(warnings)]

#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

trait MyTrait {
type Output;
4 changes: 2 additions & 2 deletions src/test/ui/in-band-lifetimes/impl/assoc-type.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0106]: missing lifetime specifier
--> $DIR/assoc-type.rs:24:19
--> $DIR/assoc-type.rs:23:19
|
LL | type Output = &i32;
| ^ expected lifetime parameter

error[E0106]: missing lifetime specifier
--> $DIR/assoc-type.rs:29:20
--> $DIR/assoc-type.rs:28:20
|
LL | type Output = &'_ i32;
| ^^ expected lifetime parameter
1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/dyn-trait.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@

#![feature(dyn_trait)]
#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

use std::fmt::Debug;

6 changes: 3 additions & 3 deletions src/test/ui/in-band-lifetimes/impl/dyn-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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
| ^
|
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 33:1...
--> $DIR/dyn-trait.rs:33:1
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 32:1...
--> $DIR/dyn-trait.rs:32:1
|
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/path-elided.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
#![allow(warnings)]

#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

trait MyTrait { }

2 changes: 1 addition & 1 deletion src/test/ui/in-band-lifetimes/impl/path-elided.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier
--> $DIR/path-elided.rs:19:18
--> $DIR/path-elided.rs:18:18
|
LL | impl MyTrait for Foo {
| ^^^ expected lifetime parameter
1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/path-underscore.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
#![allow(warnings)]

#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

trait MyTrait { }

1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/ref-underscore.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
#![allow(warnings)]

#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

trait MyTrait { }

1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/trait-elided.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
#![allow(warnings)]

#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

trait MyTrait<'a> { }

2 changes: 1 addition & 1 deletion src/test/ui/in-band-lifetimes/impl/trait-elided.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier
--> $DIR/trait-elided.rs:17:6
--> $DIR/trait-elided.rs:16:6
|
LL | impl MyTrait for u32 {
| ^^^^^^^ expected lifetime parameter
1 change: 0 additions & 1 deletion src/test/ui/in-band-lifetimes/impl/trait-underscore.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
#![allow(warnings)]

#![feature(in_band_lifetimes)]
#![feature(underscore_lifetimes)]

trait MyTrait<'a> { }

Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
// cc #48468

#![feature(dyn_trait)]
#![feature(underscore_lifetimes)]

use std::fmt::Debug;

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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
| ^^ expected lifetime parameter

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
| ^^^^^^^^^^^^^^
1 change: 0 additions & 1 deletion src/test/ui/underscore-lifetime/dyn-trait-underscore.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
// cc #48468

#![feature(dyn_trait)]
#![feature(underscore_lifetimes)]

fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
// ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
8 changes: 4 additions & 4 deletions src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
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
| ^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the function body at 19:1...
--> $DIR/dyn-trait-underscore.rs: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:18:1
|
LL | / fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
LL | | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
LL | | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
LL | | }
| |_^
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
| ^^^^^