Skip to content

Commit 6810f52

Browse files
committed
Auto merge of #53793 - toidiu:ak-stabalize, r=nikomatsakis
stabilize outlives requirements #44493 r? @nikomatsakis
2 parents 8586ec6 + 731f4ef commit 6810f52

File tree

138 files changed

+802
-753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+802
-753
lines changed

src/doc/unstable-book/src/language-features/infer-outlives-requirements.md

-67
This file was deleted.

src/liballoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
#![cfg_attr(not(test), feature(fn_traits))]
7878
#![cfg_attr(not(test), feature(generator_trait))]
7979
#![cfg_attr(not(stage0), feature(nll))]
80-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
8180
#![cfg_attr(test, feature(test))]
8281

8382
#![feature(allocator_api)]

src/liballoc_jemalloc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#![feature(libc)]
1818
#![feature(linkage)]
1919
#![cfg_attr(not(stage0), feature(nll))]
20-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2120
#![feature(staged_api)]
2221
#![feature(rustc_attrs)]
2322
#![cfg_attr(dummy_jemalloc, allow(dead_code, unused_extern_crates))]

src/liballoc_system/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![feature(allocator_api)]
1919
#![feature(core_intrinsics)]
2020
#![cfg_attr(not(stage0), feature(nll))]
21-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2221
#![feature(staged_api)]
2322
#![feature(rustc_attrs)]
2423
#![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))]

src/libarena/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#![feature(core_intrinsics)]
2828
#![feature(dropck_eyepatch)]
2929
#![cfg_attr(not(stage0), feature(nll))]
30-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
3130
#![feature(raw_vec_internals)]
3231
#![cfg_attr(test, feature(test))]
3332

src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
#![feature(link_llvm_intrinsics)]
9393
#![feature(never_type)]
9494
#![cfg_attr(not(stage0), feature(nll))]
95-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
9695
#![feature(exhaustive_patterns)]
9796
#![feature(macro_at_most_once_rep)]
9897
#![feature(no_core)]

src/libfmt_macros/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
test(attr(deny(warnings))))]
2222

2323
#![cfg_attr(not(stage0), feature(nll))]
24-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2524

2625
pub use self::Piece::*;
2726
pub use self::Position::*;

src/libgraphviz/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@
289289
test(attr(allow(unused_variables), deny(warnings))))]
290290

291291
#![cfg_attr(not(stage0), feature(nll))]
292-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
293292
#![feature(str_escape)]
294293

295294
use self::LabelText::*;

src/libpanic_abort/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#![feature(core_intrinsics)]
2626
#![feature(libc)]
2727
#![cfg_attr(not(stage0), feature(nll))]
28-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2928
#![feature(panic_runtime)]
3029
#![feature(staged_api)]
3130
#![feature(rustc_attrs)]

src/libpanic_unwind/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(lang_items)]
3636
#![feature(libc)]
3737
#![cfg_attr(not(stage0), feature(nll))]
38-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
3938
#![feature(panic_unwind)]
4039
#![feature(raw)]
4140
#![feature(staged_api)]

src/libproc_macro/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
2929

3030
#![cfg_attr(not(stage0), feature(nll))]
31-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
3231
#![feature(rustc_private)]
3332
#![feature(staged_api)]
3433
#![feature(lang_items)]

src/libprofiler_builtins/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@
1616
issue = "0")]
1717
#![allow(unused_features)]
1818
#![cfg_attr(not(stage0), feature(nll))]
19-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2019
#![feature(staged_api)]

src/librustc/diagnostics.rs

+52-38
Original file line numberDiff line numberDiff line change
@@ -1232,41 +1232,54 @@ let x: i32 = "I am not a number!";
12321232
"##,
12331233

12341234
E0309: r##"
1235-
Types in type definitions have lifetimes associated with them that represent
1236-
how long the data stored within them is guaranteed to be live. This lifetime
1237-
must be as long as the data needs to be alive, and missing the constraint that
1238-
denotes this will cause this error.
1235+
The type definition contains some field whose type
1236+
requires an outlives annotation. Outlives annotations
1237+
(e.g., `T: 'a`) are used to guarantee that all the data in T is valid
1238+
for at least the lifetime `'a`. This scenario most commonly
1239+
arises when the type contains an associated type reference
1240+
like `<T as SomeTrait<'a>>::Output`, as shown in this example:
12391241
12401242
```compile_fail,E0309
1241-
// This won't compile because T is not constrained, meaning the data
1242-
// stored in it is not guaranteed to last as long as the reference
1243+
// This won't compile because the applicable impl of
1244+
// `SomeTrait` (below) requires that `T: 'a`, but the struct does
1245+
// not have a matching where-clause.
12431246
struct Foo<'a, T> {
1244-
foo: &'a T
1247+
foo: <T as SomeTrait<'a>>::Output,
12451248
}
1246-
```
12471249
1248-
This will compile, because it has the constraint on the type parameter:
1250+
trait SomeTrait<'a> {
1251+
type Output;
1252+
}
12491253
1250-
```
1251-
struct Foo<'a, T: 'a> {
1252-
foo: &'a T
1254+
impl<'a, T> SomeTrait<'a> for T
1255+
where
1256+
T: 'a,
1257+
{
1258+
type Output = u32;
12531259
}
12541260
```
12551261
1256-
To see why this is important, consider the case where `T` is itself a reference
1257-
(e.g., `T = &str`). If we don't include the restriction that `T: 'a`, the
1258-
following code would be perfectly legal:
1262+
Here, the where clause `T: 'a` that appears on the impl is not known to be
1263+
satisfied on the struct. To make this example compile, you have to add
1264+
a where-clause like `T: 'a` to the struct definition:
12591265
1260-
```compile_fail,E0309
1261-
struct Foo<'a, T> {
1262-
foo: &'a T
1266+
```
1267+
struct Foo<'a, T>
1268+
where
1269+
T: 'a,
1270+
{
1271+
foo: <T as SomeTrait<'a>>::Output
12631272
}
12641273
1265-
fn main() {
1266-
let v = "42".to_string();
1267-
let f = Foo{foo: &v};
1268-
drop(v);
1269-
println!("{}", f.foo); // but we've already dropped v!
1274+
trait SomeTrait<'a> {
1275+
type Output;
1276+
}
1277+
1278+
impl<'a, T> SomeTrait<'a> for T
1279+
where
1280+
T: 'a,
1281+
{
1282+
type Output = u32;
12701283
}
12711284
```
12721285
"##,
@@ -1465,30 +1478,31 @@ A reference has a longer lifetime than the data it references.
14651478
Erroneous code example:
14661479
14671480
```compile_fail,E0491
1468-
// struct containing a reference requires a lifetime parameter,
1469-
// because the data the reference points to must outlive the struct (see E0106)
1470-
struct Struct<'a> {
1471-
ref_i32: &'a i32,
1481+
trait SomeTrait<'a> {
1482+
type Output;
14721483
}
14731484
1474-
// However, a nested struct like this, the signature itself does not tell
1475-
// whether 'a outlives 'b or the other way around.
1476-
// So it could be possible that 'b of reference outlives 'a of the data.
1477-
struct Nested<'a, 'b> {
1478-
ref_struct: &'b Struct<'a>, // compile error E0491
1485+
impl<'a, T> SomeTrait<'a> for T {
1486+
type Output = &'a T; // compile error E0491
14791487
}
14801488
```
14811489
1482-
To fix this issue, you can specify a bound to the lifetime like below:
1490+
Here, the problem is that a reference type like `&'a T` is only valid
1491+
if all the data in T outlives the lifetime `'a`. But this impl as written
1492+
is applicable to any lifetime `'a` and any type `T` -- we have no guarantee
1493+
that `T` outlives `'a`. To fix this, you can add a where clause like
1494+
`where T: 'a`.
14831495
14841496
```
1485-
struct Struct<'a> {
1486-
ref_i32: &'a i32,
1497+
trait SomeTrait<'a> {
1498+
type Output;
14871499
}
14881500
1489-
// 'a: 'b means 'a outlives 'b
1490-
struct Nested<'a: 'b, 'b> {
1491-
ref_struct: &'b Struct<'a>,
1501+
impl<'a, T> SomeTrait<'a> for T
1502+
where
1503+
T: 'a,
1504+
{
1505+
type Output = &'a T; // compile error E0491
14921506
}
14931507
```
14941508
"##,

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#![feature(exhaustive_patterns)]
5353
#![feature(extern_types)]
5454
#![cfg_attr(not(stage0), feature(nll))]
55-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
5655
#![feature(non_exhaustive)]
5756
#![feature(proc_macro_internals)]
5857
#![feature(quote)]

src/librustc_allocator/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
#![cfg_attr(not(stage0), feature(nll))]
12-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1312
#![feature(rustc_private)]
1413

1514
#[macro_use] extern crate log;

src/librustc_apfloat/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#![forbid(unsafe_code)]
4747

4848
#![cfg_attr(not(stage0), feature(nll))]
49-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
5049
#![feature(try_from)]
5150
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
5251
#[allow(unused_extern_crates)]

src/librustc_asan/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![sanitizer_runtime]
1212
#![feature(alloc_system)]
1313
#![cfg_attr(not(stage0), feature(nll))]
14-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1514
#![feature(sanitizer_runtime)]
1615
#![feature(staged_api)]
1716
#![no_std]

src/librustc_borrowck/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![allow(non_camel_case_types)]
1616

1717
#![cfg_attr(not(stage0), feature(nll))]
18-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1918
#![feature(quote)]
2019

2120
#![recursion_limit="256"]

src/librustc_codegen_llvm/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#![allow(unused_attributes)]
2828
#![feature(libc)]
2929
#![cfg_attr(not(stage0), feature(nll))]
30-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
3130
#![feature(quote)]
3231
#![feature(range_contains)]
3332
#![feature(rustc_diagnostic_macros)]

src/librustc_codegen_utils/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![feature(box_syntax)]
2121
#![feature(custom_attribute)]
2222
#![cfg_attr(not(stage0), feature(nll))]
23-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2423
#![allow(unused_attributes)]
2524
#![feature(quote)]
2625
#![feature(rustc_diagnostic_macros)]

src/librustc_cratesio_shim/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![allow(unused_extern_crates)]
1313

1414
#![cfg_attr(not(stage0), feature(nll))]
15-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1615

1716
extern crate bitflags;
1817
extern crate log;

src/librustc_data_structures/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(optin_builtin_traits)]
3030
#![cfg_attr(stage0, feature(macro_vis_matcher))]
3131
#![cfg_attr(not(stage0), feature(nll))]
32-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
3332
#![feature(allow_internal_unstable)]
3433
#![feature(vec_resize_with)]
3534

src/librustc_driver/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#![feature(box_syntax)]
2222
#![cfg_attr(unix, feature(libc))]
2323
#![cfg_attr(not(stage0), feature(nll))]
24-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2524
#![feature(option_replace)]
2625
#![feature(quote)]
2726
#![feature(rustc_diagnostic_macros)]

src/librustc_errors/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#![feature(range_contains)]
1818
#![cfg_attr(unix, feature(libc))]
1919
#![cfg_attr(not(stage0), feature(nll))]
20-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
2120
#![feature(optin_builtin_traits)]
2221

2322
extern crate atty;

src/librustc_incremental/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
html_root_url = "https://doc.rust-lang.org/nightly/")]
1616

1717
#![cfg_attr(not(stage0), feature(nll))]
18-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1918
#![feature(specialization)]
2019

2120
#![recursion_limit="256"]

src/librustc_lint/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#![feature(box_syntax)]
2929
#![cfg_attr(stage0, feature(macro_vis_matcher))]
3030
#![cfg_attr(not(stage0), feature(nll))]
31-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
3231
#![feature(quote)]
3332
#![feature(rustc_diagnostic_macros)]
3433
#![feature(macro_at_most_once_rep)]

src/librustc_llvm/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
#![cfg_attr(not(stage0), feature(nll))]
12-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1312
#![feature(static_nobundle)]
1413

1514
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

src/librustc_lsan/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![sanitizer_runtime]
1212
#![feature(alloc_system)]
1313
#![cfg_attr(not(stage0), feature(nll))]
14-
#![cfg_attr(not(stage0), feature(infer_outlives_requirements))]
1514
#![feature(sanitizer_runtime)]
1615
#![feature(staged_api)]
1716
#![no_std]

0 commit comments

Comments
 (0)