Skip to content

Commit

Permalink
Auto merge of rust-lang#127672 - compiler-errors:precise-capturing, r…
Browse files Browse the repository at this point in the history
…=spastorino

Stabilize opaque type precise capturing (RFC 3617)

This PR partially stabilizes opaque type *precise capturing*, which was specified in [RFC 3617](rust-lang/rfcs#3617), and whose syntax was amended by FCP in [rust-lang#125836](rust-lang#125836).

This feature, as stabilized here, gives us a way to explicitly specify the generic lifetime parameters that an RPIT-like opaque type captures.  This solves the problem of overcapturing, for lifetime parameters in these opaque types, and will allow the Lifetime Capture Rules 2024 ([RFC 3498](rust-lang/rfcs#3498)) to be fully stabilized for RPIT in Rust 2024.

### What are we stabilizing?

This PR stabilizes the use of a `use<'a, T>` bound in return-position impl Trait opaque types.  Such a bound fully specifies the set of generic parameters captured by the RPIT opaque type, entirely overriding the implicit default behavior.  E.g.:

```rust
fn does_not_capture<'a, 'b>() -> impl Sized + use<'a> {}
//                               ~~~~~~~~~~~~~~~~~~~~
//                This RPIT opaque type does not capture `'b`.
```

The way we would suggest thinking of `impl Trait` types *without* an explicit `use<..>` bound is that the `use<..>` bound has been *elided*, and that the bound is filled in automatically by the compiler according to the edition-specific capture rules.

All non-`'static` lifetime parameters, named (i.e. non-APIT) type parameters, and const parameters in scope are valid to name, including an elided lifetime if such a lifetime would also be valid in an outlives bound, e.g.:

```rust
fn elided(x: &u8) -> impl Sized + use<'_> { x }
```

Lifetimes must be listed before type and const parameters, but otherwise the ordering is not relevant to the `use<..>` bound.  Captured parameters may not be duplicated.  For now, only one `use<..>` bound may appear in a bounds list.  It may appear anywhere within the bounds list.

### How does this differ from the RFC?

This stabilization differs from the RFC in one respect: the RFC originally specified `use<'a, T>` as syntactically part of the RPIT type itself, e.g.:

```rust
fn capture<'a>() -> impl use<'a> Sized {}
```

However, settling on the final syntax was left as an open question.  T-lang later decided via FCP in [rust-lang#125836](rust-lang#125836) to treat `use<..>` as a syntactic bound instead, e.g.:

```rust
fn capture<'a>() -> impl Sized + use<'a> {}
```

### What aren't we stabilizing?

The key goal of this PR is to stabilize the parts of *precise capturing* that are needed to enable the migration to Rust 2024.

There are some capabilities of *precise capturing* that the RFC specifies but that we're not stabilizing here, as these require further work on the type system.  We hope to lift these limitations later.

The limitations that are part of this PR were specified in the [RFC's stabilization strategy](https://rust-lang.github.io/rfcs/3617-precise-capturing.html#stabilization-strategy).

#### Not capturing type or const parameters

The RFC addresses the overcapturing of type and const parameters; that is, it allows for them to not be captured in opaque types.  We're not stabilizing that in this PR.  Since all in scope generic type and const parameters are implicitly captured in all editions, this is not needed for the migration to Rust 2024.

For now, when using `use<..>`, all in scope type and const parameters must be nameable (i.e., APIT cannot be used) and included as arguments.  For example, this is an error because `T` is in scope and not included as an argument:

```rust
fn test<T>() -> impl Sized + use<> {}
//~^ ERROR `impl Trait` must mention all type parameters in scope in `use<...>`
```

This is due to certain current limitations in the type system related to how generic parameters are represented as captured (i.e. bivariance) and how inference operates.

We hope to relax this in the future, and this stabilization is forward compatible with doing so.

#### Precise capturing for return-position impl Trait **in trait** (RPITIT)

The RFC specifies precise capturing for RPITIT.  We're not stabilizing that in this PR.  Since RPITIT already adheres to the Lifetime Capture Rules 2024, this isn't needed for the migration to Rust 2024.

The effect of this is that the anonymous associated types created by RPITITs must continue to capture all of the lifetime parameters in scope, e.g.:

```rust
trait Foo<'a> {
    fn test() -> impl Sized + use<Self>;
    //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
}
```

To allow this involves a meaningful amount of type system work related to adding variance to GATs or reworking how generics are represented in RPITITs.  We plan to do this work separately from the stabilization.  See:

- rust-lang#124029

Supporting precise capturing for RPITIT will also require us to implement a new algorithm for detecting refining capture behavior.  This may involve looking through type parameters to detect cases where the impl Trait type in an implementation captures fewer lifetimes than the corresponding RPITIT in the trait definition, e.g.:

```rust
trait Foo {
    fn rpit() -> impl Sized + use<Self>;
}

impl<'a> Foo for &'a () {
    // This is "refining" due to not capturing `'a` which
    // is implied by the trait's `use<Self>`.
    fn rpit() -> impl Sized + use<>;

    // This is not "refining".
    fn rpit() -> impl Sized + use<'a>;
}
```

This stabilization is forward compatible with adding support for this later.

### The technical details

This bound is purely syntactical and does not lower to a [`Clause`](https://doc.rust-lang.org/1.79.0/nightly-rustc/rustc_middle/ty/type.ClauseKind.html) in the type system.  For the purposes of the type system (and for the types team's curiosity regarding this stabilization), we have no current need to represent this as a `ClauseKind`.

Since opaques already capture a variable set of lifetimes depending on edition and their syntactical position (e.g. RPIT vs RPITIT), a `use<..>` bound is just a way to explicitly rather than implicitly specify that set of lifetimes, and this only affects opaque type lowering from AST to HIR.

### FCP plan

While there's much discussion of the type system here, the feature in this PR is implemented internally as a transformation that happens before lowering to the type system layer.  We already support impl Trait types partially capturing the in scope lifetimes; we just currently only expose that implicitly.

So, in my (errs's) view as a types team member, there's nothing for types to weigh in on here with respect to the implementation being stabilized, and I'd suggest a lang-only proposed FCP (though we'll of course CC the team below).

### Authorship and acknowledgments

This stabilization report was coauthored by compiler-errors and TC.

TC would like to acknowledge the outstanding and speedy work that compiler-errors has done to make this feature happen.

compiler-errors thanks TC for authoring the RFC, for all of his involvement in this feature's development, and pushing the Rust 2024 edition forward.

### Open items

We're doing some things in parallel here.  In signaling the intention to stabilize, we want to uncover any latent issues so we can be sure they get addressed.  We want to give the maximum time for discussion here to happen by starting it while other remaining miscellaneous work proceeds.  That work includes:

- [x] Look into `syn` support.
  - dtolnay/syn#1677
  - dtolnay/syn#1707
- [x] Look into `rustfmt` support.
  - rust-lang#126754
- [x] Look into `rust-analyzer` support.
  - rust-lang/rust-analyzer#17598
  - rust-lang/rust-analyzer#17676
- [x] Look into `rustdoc` support.
  - rust-lang#127228
  - rust-lang#127632
  - rust-lang#127658
- [x] Suggest this feature to RfL (a known nightly user).
- [x] Add a chapter to the edition guide.
  - rust-lang/edition-guide#316
- [x] Update the Reference.
  - rust-lang/reference#1577

### (Selected) implementation history

* rust-lang/rfcs#3498
* rust-lang/rfcs#3617
* rust-lang#123468
* rust-lang#125836
* rust-lang#126049
* rust-lang#126753

Closes rust-lang#123432.

cc `@rust-lang/lang` `@rust-lang/types`

`@rustbot` labels +T-lang +I-lang-nominated +A-impl-trait +F-precise_capturing

Tracking:

- rust-lang#123432

----

For the compiler reviewer, I'll leave some inline comments about diagnostics fallout :^)

r? compiler
  • Loading branch information
bors committed Aug 20, 2024
2 parents fdf61d4 + 84044cd commit a971212
Show file tree
Hide file tree
Showing 79 changed files with 194 additions and 320 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
gate_all!(fn_delegation, "functions delegation is not yet fully implemented");
gate_all!(postfix_match, "postfix match is experimental");
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
gate_all!(global_registration, "global registration is experimental");
gate_all!(return_type_notation, "return type notation is experimental");

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ declare_features! (
(accepted, param_attrs, "1.39.0", Some(60406)),
/// Allows parentheses in patterns.
(accepted, pattern_parentheses, "1.31.0", Some(51087)),
/// Allows `use<'a, 'b, A, B>` in `impl Trait + use<...>` for precise capture of generic args.
(accepted, precise_capturing, "CURRENT_RUSTC_VERSION", Some(123432)),
/// Allows procedural macros in `proc-macro` crates.
(accepted, proc_macro, "1.29.0", Some(38356)),
/// Allows multi-segment paths in attributes and derives.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,6 @@ declare_features! (
(unstable, patchable_function_entry, "1.81.0", Some(123115)),
/// Allows postfix match `expr.match { ... }`
(unstable, postfix_match, "1.79.0", Some(121618)),
/// Allows `use<'a, 'b, A, B>` in `impl Trait + use<...>` for precise capture of generic args.
(unstable, precise_capturing, "1.79.0", Some(123432)),
/// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,6 @@ impl PreciseCapturingArg<'_> {
/// resolution to. Lifetimes don't have this problem, and for them, it's actually
/// kind of detrimental to use a custom node type versus just using [`Lifetime`],
/// since resolve_bound_vars operates on `Lifetime`s.
// FIXME(precise_capturing): Investigate storing this as a path instead?
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct PreciseCapturingNonLifetimeArg {
pub hir_id: HirId,
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_lint/src/impl_trait_overcaptures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(precise_capturing)]
/// # #![allow(incomplete_features)]
/// # #![deny(impl_trait_overcaptures)]
/// # use std::fmt::Display;
/// let mut x = vec![];
Expand Down Expand Up @@ -56,7 +54,6 @@ declare_lint! {
pub IMPL_TRAIT_OVERCAPTURES,
Allow,
"`impl Trait` will capture more lifetimes than possibly intended in edition 2024",
@feature_gate = precise_capturing;
//@future_incompatible = FutureIncompatibleInfo {
// reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
// reference: "<FIXME>",
Expand All @@ -75,8 +72,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(precise_capturing, lifetime_capture_rules_2024)]
/// # #![allow(incomplete_features)]
/// # #![feature(lifetime_capture_rules_2024)]
/// # #![deny(impl_trait_redundant_captures)]
/// fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x }
/// ```
Expand All @@ -90,7 +86,6 @@ declare_lint! {
pub IMPL_TRAIT_REDUNDANT_CAPTURES,
Warn,
"redundant precise-capturing `use<...>` syntax on an `impl Trait`",
@feature_gate = precise_capturing;
}

declare_lint_pass!(
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ impl<'a> Parser<'a> {
// lifetimes and ident params (including SelfUpper). These are validated later
// for order, duplication, and whether they actually reference params.
let use_span = self.prev_token.span;
self.psess.gated_spans.gate(sym::precise_capturing, use_span);
let (args, args_span) = self.parse_precise_capturing_args()?;
GenericBound::Use(args, use_span.to(args_span))
} else {
Expand Down
22 changes: 4 additions & 18 deletions compiler/rustc_trait_selection/src/error_reporting/infer/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use rustc_span::{BytePos, ErrorGuaranteed, Span, Symbol};
use rustc_type_ir::Upcast as _;

use super::nice_region_error::find_anon_type;
use super::{nice_region_error, ObligationCauseAsDiagArg};
use crate::error_reporting::infer::ObligationCauseExt as _;
use super::ObligationCauseAsDiagArg;
use crate::error_reporting::infer::ObligationCauseExt;
use crate::error_reporting::TypeErrCtxt;
use crate::errors::{
self, note_and_explain, FulfillReqLifetime, LfBoundNotSatisfied, OutlivesBound,
Expand Down Expand Up @@ -1212,22 +1212,8 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
hidden_region,
"",
);
if let Some(reg_info) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
if infcx.tcx.features().precise_capturing {
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
} else {
let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id);
nice_region_error::suggest_new_region_bound(
tcx,
&mut err,
fn_returns,
hidden_region.to_string(),
None,
format!("captures `{hidden_region}`"),
None,
Some(reg_info.def_id),
)
}
if let Some(_) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
}
}
ty::RePlaceholder(_) => {
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/impl-trait-precise-capturing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[0]" \"\'a\"
//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[1]" \"T\"
//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[2]" \"N\"
Expand Down
1 change: 0 additions & 1 deletion tests/rustdoc/impl-trait-precise-capturing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@ aux-build:precise-capturing.rs

#![crate_name = "foo"]
#![feature(precise_capturing)]

extern crate precise_capturing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ LL | | (a, b)
LL | | }
| |_^
|
help: to declare that `impl Trait<'a>` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
| ++++
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + use<'a, 'b> {
| +++++++++++++

error: aborting due to 2 previous errors

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/borrowck/alias-liveness/opaque-type-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static {
| hidden type `impl Trait + 'static` captures the lifetime `'a` as defined here
LL | bar(s)
| ^^^^^^
|
help: add a `use<...>` bound to explicitly capture `'a`
|
LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static + use<'a> {
| +++++++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ LL | fn a(&self) -> impl Iterator {
LL | self.0.iter_mut()
| ^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Iterator` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn a(&self) -> impl Iterator + '_ {
| ++++
LL | fn a(&self) -> impl Iterator + use<'_> {
| +++++++++

error: aborting due to 3 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn foo(x: &Vec<i32>) -> impl Sized {
LL | x
| ^
|
help: to declare that `impl Sized` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn foo(x: &Vec<i32>) -> impl Sized + '_ {
| ++++
LL | fn foo(x: &Vec<i32>) -> impl Sized + use<'_> {
| +++++++++

error: aborting due to 1 previous error

Expand Down
4 changes: 0 additions & 4 deletions tests/ui/feature-gates/feature-gate-precise-capturing.rs

This file was deleted.

13 changes: 0 additions & 13 deletions tests/ui/feature-gates/feature-gate-precise-capturing.stderr

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a {
LL | step1::<'a, 'b>()
| ^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Sized + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a + 'b {
| ++++
LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a + use<'a, 'b> {
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
LL | x
| ^
|
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + 'b {
| ++++
LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + use<'a, 'b, T> {
| ++++++++++++++++

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/call_method_ambiguous.next.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/call_method_ambiguous.rs:28:13
--> $DIR/call_method_ambiguous.rs:26:13
|
LL | let mut iter = foo(n - 1, m);
| ^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/call_method_ambiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//@[next] compile-flags: -Znext-solver
//@[current] run-pass

#![feature(precise_capturing)]

trait Get {
fn get(&mut self) -> u32;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/impl-trait/hidden-lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
LL | x
| ^
|
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b {
| ++++
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + use<'a, 'b, T> {
| ++++++++++++++++

error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds
--> $DIR/hidden-lifetimes.rs:46:5
Expand All @@ -23,10 +23,10 @@ LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl S
LL | x
| ^
|
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + 'b {
| ++++
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + use<'a, 'b, T> {
| ++++++++++++++++

error: aborting due to 2 previous errors

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/in-trait/cannot-capture-intersection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

use std::future::Future;
use std::pin::Pin;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0700]: hidden type for `impl Future<Output = i32>` captures lifetime that does not appear in bounds
--> $DIR/cannot-capture-intersection.rs:24:9
--> $DIR/cannot-capture-intersection.rs:22:9
|
LL | fn foo<'a, 'b>(&'a self, x: &'b i32) -> impl Future<Output = i32> {
| ------------------------- opaque type defined here
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ LL | fn elided(x: &i32) -> impl Copy { x }
| | opaque type defined here
| hidden type `&i32` captures the anonymous lifetime defined here
|
help: to declare that `impl Copy` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ++++
LL | fn elided(x: &i32) -> impl Copy + use<'_> { x }
| +++++++++

error[E0700]: hidden type for `impl Copy` captures lifetime that does not appear in bounds
--> $DIR/must_outlive_least_region_or_bound.rs:6:44
Expand All @@ -21,10 +21,10 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| | opaque type defined here
| hidden type `&'a i32` captures the lifetime `'a` as defined here
|
help: to declare that `impl Copy` captures `'a`, you can add an explicit `'a` lifetime bound
help: add a `use<...>` bound to explicitly capture `'a`
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ++++
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + use<'a> { x }
| +++++++++

error: lifetime may not live long enough
--> $DIR/must_outlive_least_region_or_bound.rs:9:46
Expand Down Expand Up @@ -108,10 +108,10 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32
LL | move |_| println!("{}", y)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Fn(&'a u32)` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
| ++++
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + use<'a, 'b> {
| +++++++++++++

error[E0310]: the parameter type `T` may not live long enough
--> $DIR/must_outlive_least_region_or_bound.rs:47:5
Expand Down
10 changes: 3 additions & 7 deletions tests/ui/impl-trait/nested-return-type4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized
LL | async move { let _s = s; }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Future<Output = impl Sized>` captures `'s`, you can add an explicit `'s` lifetime bound
help: add a `use<...>` bound to explicitly capture `'s`
|
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized> + 's {
| ++++
help: to declare that `impl Sized` captures `'s`, you can add an explicit `'s` lifetime bound
|
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized + 's> {
| ++++
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized> + use<'s> {
| +++++++++

error: aborting due to 1 previous error

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/apit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

fn hello(_: impl Sized + use<>) {}
//~^ ERROR `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/precise-capturing/apit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
--> $DIR/apit.rs:3:26
--> $DIR/apit.rs:1:26
|
LL | fn hello(_: impl Sized + use<>) {}
| ^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/bad-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

fn no_elided_lt() -> impl Sized + use<'_> {}
//~^ ERROR missing lifetime specifier
//~| ERROR expected lifetime parameter in `use<...>` precise captures list, found `'_`
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/impl-trait/precise-capturing/bad-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier
--> $DIR/bad-lifetimes.rs:3:39
--> $DIR/bad-lifetimes.rs:1:39
|
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
| ^^ expected named lifetime parameter
Expand All @@ -11,21 +11,21 @@ LL | fn no_elided_lt() -> impl Sized + use<'static> {}
| ~~~~~~~

error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/bad-lifetimes.rs:10:37
--> $DIR/bad-lifetimes.rs:8:37
|
LL | fn missing_lt() -> impl Sized + use<'missing> {}
| - ^^^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'missing` here: `<'missing>`

error: expected lifetime parameter in `use<...>` precise captures list, found `'_`
--> $DIR/bad-lifetimes.rs:3:39
--> $DIR/bad-lifetimes.rs:1:39
|
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
| ^^

error: expected lifetime parameter in `use<...>` precise captures list, found `'static`
--> $DIR/bad-lifetimes.rs:7:36
--> $DIR/bad-lifetimes.rs:5:36
|
LL | fn static_lt() -> impl Sized + use<'static> {}
| ^^^^^^^
Expand Down
Loading

0 comments on commit a971212

Please sign in to comment.