mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Auto merge of #127672 - compiler-errors:precise-capturing, r=spastorino
Stabilize opaque type precise capturing (RFC 3617) This PR partially stabilizes opaque type *precise capturing*, which was specified in [RFC 3617](https://github.com/rust-lang/rfcs/pull/3617), and whose syntax was amended by FCP in [#125836](https://github.com/rust-lang/rust/issues/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](https://github.com/rust-lang/rfcs/pull/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 [#125836](https://github.com/rust-lang/rust/issues/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: - https://github.com/rust-lang/rust/pull/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. - https://github.com/dtolnay/syn/issues/1677 - https://github.com/dtolnay/syn/pull/1707 - [x] Look into `rustfmt` support. - https://github.com/rust-lang/rust/pull/126754 - [x] Look into `rust-analyzer` support. - https://github.com/rust-lang/rust-analyzer/issues/17598 - https://github.com/rust-lang/rust-analyzer/pull/17676 - [x] Look into `rustdoc` support. - https://github.com/rust-lang/rust/issues/127228 - https://github.com/rust-lang/rust/pull/127632 - https://github.com/rust-lang/rust/pull/127658 - [x] Suggest this feature to RfL (a known nightly user). - [x] Add a chapter to the edition guide. - https://github.com/rust-lang/edition-guide/pull/316 - [x] Update the Reference. - https://github.com/rust-lang/reference/pull/1577 ### (Selected) implementation history * https://github.com/rust-lang/rfcs/pull/3498 * https://github.com/rust-lang/rfcs/pull/3617 * https://github.com/rust-lang/rust/pull/123468 * https://github.com/rust-lang/rust/issues/125836 * https://github.com/rust-lang/rust/pull/126049 * https://github.com/rust-lang/rust/pull/126753 Closes #123432. cc `@rust-lang/lang` `@rust-lang/types` `@rustbot` labels +T-lang +I-lang-nominated +A-impl-trait +F-precise_capturing Tracking: - https://github.com/rust-lang/rust/issues/123432 ---- For the compiler reviewer, I'll leave some inline comments about diagnostics fallout :^) r? compiler
This commit is contained in:
commit
a971212545
@ -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");
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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![];
|
||||
@ -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>",
|
||||
@ -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 }
|
||||
/// ```
|
||||
@ -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!(
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
@ -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(_) => {
|
||||
|
@ -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\"
|
||||
|
@ -1,7 +1,6 @@
|
||||
//@ aux-build:precise-capturing.rs
|
||||
|
||||
#![crate_name = "foo"]
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
extern crate precise_capturing;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
fn hello() -> impl Sized + use<> {}
|
||||
//~^ ERROR precise captures on `impl Trait` are experimental
|
||||
|
||||
fn main() {}
|
@ -1,13 +0,0 @@
|
||||
error[E0658]: precise captures on `impl Trait` are experimental
|
||||
--> $DIR/feature-gate-precise-capturing.rs:1:28
|
||||
|
|
||||
LL | fn hello() -> impl Sized + use<> {}
|
||||
| ^^^
|
||||
|
|
||||
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information
|
||||
= help: add `#![feature(precise_capturing)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
| ^^^^^^^^
|
||||
|
@ -2,8 +2,6 @@
|
||||
//@[next] compile-flags: -Znext-solver
|
||||
//@[current] run-pass
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
trait Get {
|
||||
fn get(&mut self) -> u32;
|
||||
}
|
||||
|
@ -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
|
||||
@ -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
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn hello(_: impl Sized + use<>) {}
|
||||
//~^ ERROR `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
|
||||
|
||||
|
@ -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<>) {}
|
||||
| ^^^^^
|
||||
|
@ -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 `'_`
|
||||
|
@ -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
|
||||
@ -11,7 +11,7 @@ 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
|
||||
@ -19,13 +19,13 @@ LL | fn missing_lt() -> impl Sized + use<'missing> {}
|
||||
| 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> {}
|
||||
| ^^^^^^^
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn missing() -> impl Sized + use<T> {}
|
||||
//~^ ERROR cannot find type `T` in this scope
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0412]: cannot find type `T` in this scope
|
||||
--> $DIR/bad-params.rs:3:34
|
||||
--> $DIR/bad-params.rs:1:34
|
||||
|
|
||||
LL | fn missing() -> impl Sized + use<T> {}
|
||||
| ^ not found in this scope
|
||||
@ -10,7 +10,7 @@ LL | fn missing<T>() -> impl Sized + use<T> {}
|
||||
| +++
|
||||
|
||||
error[E0411]: cannot find type `Self` in this scope
|
||||
--> $DIR/bad-params.rs:6:39
|
||||
--> $DIR/bad-params.rs:4:39
|
||||
|
|
||||
LL | fn missing_self() -> impl Sized + use<Self> {}
|
||||
| ------------ ^^^^ `Self` is only available in impls, traits, and type definitions
|
||||
@ -18,7 +18,7 @@ LL | fn missing_self() -> impl Sized + use<Self> {}
|
||||
| `Self` not allowed in a function
|
||||
|
||||
error: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
|
||||
--> $DIR/bad-params.rs:11:48
|
||||
--> $DIR/bad-params.rs:9:48
|
||||
|
|
||||
LL | impl MyType {
|
||||
| ----------- `Self` is not a generic argument, but an alias to the type of the implementation
|
||||
@ -26,7 +26,7 @@ LL | fn self_is_not_param() -> impl Sized + use<Self> {}
|
||||
| ^^^^
|
||||
|
||||
error: expected type or const parameter in `use<...>` precise captures list, found function
|
||||
--> $DIR/bad-params.rs:15:32
|
||||
--> $DIR/bad-params.rs:13:32
|
||||
|
|
||||
LL | fn hello() -> impl Sized + use<hello> {}
|
||||
| ^^^^^
|
||||
|
@ -1,7 +1,5 @@
|
||||
//@ edition: 2021
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn polarity() -> impl Sized + ?use<> {}
|
||||
//~^ ERROR expected identifier, found keyword `use`
|
||||
//~| ERROR cannot find trait `r#use` in this scope
|
||||
|
@ -1,53 +1,53 @@
|
||||
error: expected identifier, found keyword `use`
|
||||
--> $DIR/bound-modifiers.rs:5:32
|
||||
--> $DIR/bound-modifiers.rs:3:32
|
||||
|
|
||||
LL | fn polarity() -> impl Sized + ?use<> {}
|
||||
| ^^^ expected identifier, found keyword
|
||||
|
||||
error: expected identifier, found keyword `use`
|
||||
--> $DIR/bound-modifiers.rs:11:38
|
||||
--> $DIR/bound-modifiers.rs:9:38
|
||||
|
|
||||
LL | fn asyncness() -> impl Sized + async use<> {}
|
||||
| ^^^ expected identifier, found keyword
|
||||
|
||||
error: expected identifier, found keyword `use`
|
||||
--> $DIR/bound-modifiers.rs:16:38
|
||||
--> $DIR/bound-modifiers.rs:14:38
|
||||
|
|
||||
LL | fn constness() -> impl Sized + const use<> {}
|
||||
| ^^^ expected identifier, found keyword
|
||||
|
||||
error: expected identifier, found keyword `use`
|
||||
--> $DIR/bound-modifiers.rs:21:37
|
||||
--> $DIR/bound-modifiers.rs:19:37
|
||||
|
|
||||
LL | fn binder() -> impl Sized + for<'a> use<> {}
|
||||
| ^^^ expected identifier, found keyword
|
||||
|
||||
error[E0405]: cannot find trait `r#use` in this scope
|
||||
--> $DIR/bound-modifiers.rs:5:32
|
||||
--> $DIR/bound-modifiers.rs:3:32
|
||||
|
|
||||
LL | fn polarity() -> impl Sized + ?use<> {}
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0405]: cannot find trait `r#use` in this scope
|
||||
--> $DIR/bound-modifiers.rs:11:38
|
||||
--> $DIR/bound-modifiers.rs:9:38
|
||||
|
|
||||
LL | fn asyncness() -> impl Sized + async use<> {}
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0405]: cannot find trait `r#use` in this scope
|
||||
--> $DIR/bound-modifiers.rs:16:38
|
||||
--> $DIR/bound-modifiers.rs:14:38
|
||||
|
|
||||
LL | fn constness() -> impl Sized + const use<> {}
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0405]: cannot find trait `r#use` in this scope
|
||||
--> $DIR/bound-modifiers.rs:21:37
|
||||
--> $DIR/bound-modifiers.rs:19:37
|
||||
|
|
||||
LL | fn binder() -> impl Sized + for<'a> use<> {}
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0658]: async closures are unstable
|
||||
--> $DIR/bound-modifiers.rs:11:32
|
||||
--> $DIR/bound-modifiers.rs:9:32
|
||||
|
|
||||
LL | fn asyncness() -> impl Sized + async use<> {}
|
||||
| ^^^^^
|
||||
@ -58,7 +58,7 @@ LL | fn asyncness() -> impl Sized + async use<> {}
|
||||
= help: to use an async block, remove the `||`: `async {`
|
||||
|
||||
error[E0658]: const trait impls are experimental
|
||||
--> $DIR/bound-modifiers.rs:16:32
|
||||
--> $DIR/bound-modifiers.rs:14:32
|
||||
|
|
||||
LL | fn constness() -> impl Sized + const use<> {}
|
||||
| ^^^^^
|
||||
@ -68,13 +68,13 @@ LL | fn constness() -> impl Sized + const use<> {}
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||
--> $DIR/bound-modifiers.rs:5:31
|
||||
--> $DIR/bound-modifiers.rs:3:31
|
||||
|
|
||||
LL | fn polarity() -> impl Sized + ?use<> {}
|
||||
| ^^^^^^
|
||||
|
||||
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
|
||||
--> $DIR/bound-modifiers.rs:5:31
|
||||
--> $DIR/bound-modifiers.rs:3:31
|
||||
|
|
||||
LL | fn polarity() -> impl Sized + ?use<> {}
|
||||
| ^^^^^^
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
trait Tr {
|
||||
type Assoc;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
|
||||
--> $DIR/capture-parent-arg.rs:27:31
|
||||
--> $DIR/capture-parent-arg.rs:25:31
|
||||
|
|
||||
LL | impl<'a> W<'a> {
|
||||
| -- this lifetime parameter is captured
|
||||
@ -7,7 +7,7 @@ LL | fn bad1() -> impl Into<<W<'a> as Tr>::Assoc> + use<> {}
|
||||
| -------------^^------------------------ lifetime captured due to being mentioned in the bounds of the `impl Trait`
|
||||
|
||||
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
|
||||
--> $DIR/capture-parent-arg.rs:33:18
|
||||
--> $DIR/capture-parent-arg.rs:31:18
|
||||
|
|
||||
LL | impl<'a> W<'a> {
|
||||
| -- this lifetime parameter is captured
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: duplicate `use<...>` precise capturing syntax
|
||||
--> $DIR/duplicated-use.rs:7:32
|
||||
--> $DIR/duplicated-use.rs:5:32
|
||||
|
|
||||
LL | fn hello<'a>() -> impl Sized + use<'a> + use<'a> {}
|
||||
| ^^^^^^^ ------- second `use<...>` here
|
||||
|
@ -1,8 +1,6 @@
|
||||
//@ revisions: real pre_expansion
|
||||
//@[pre_expansion] check-pass
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
#[cfg(real)]
|
||||
fn hello<'a>() -> impl Sized + use<'a> + use<'a> {}
|
||||
//[real]~^ ERROR duplicate `use<...>` precise capturing syntax
|
||||
|
@ -1,4 +1,2 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn dyn() -> &'static dyn use<> { &() }
|
||||
//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
|
||||
--> $DIR/dyn-use.rs:3:26
|
||||
--> $DIR/dyn-use.rs:1:26
|
||||
|
|
||||
LL | fn dyn() -> &'static dyn use<> { &() }
|
||||
| ^^^ expected one of `!`, `(`, `::`, `<`, `where`, or `{`
|
||||
|
@ -1,7 +1,5 @@
|
||||
//@ check-pass
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn elided(x: &()) -> impl Sized + use<'_> { x }
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn constant<const C: usize>() -> impl Sized + use<> {}
|
||||
//~^ ERROR `impl Trait` must mention all const parameters in scope
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `impl Trait` must mention all const parameters in scope in `use<...>`
|
||||
--> $DIR/forgot-to-capture-const.rs:3:34
|
||||
--> $DIR/forgot-to-capture-const.rs:1:34
|
||||
|
|
||||
LL | fn constant<const C: usize>() -> impl Sized + use<> {}
|
||||
| -------------- ^^^^^^^^^^^^^^^^^^
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn lifetime_in_bounds<'a>(x: &'a ()) -> impl Into<&'a ()> + use<> { x }
|
||||
//~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
|
||||
--> $DIR/forgot-to-capture-lifetime.rs:3:52
|
||||
--> $DIR/forgot-to-capture-lifetime.rs:1:52
|
||||
|
|
||||
LL | fn lifetime_in_bounds<'a>(x: &'a ()) -> impl Into<&'a ()> + use<> { x }
|
||||
| -- -----------^^------------
|
||||
@ -8,7 +8,7 @@ LL | fn lifetime_in_bounds<'a>(x: &'a ()) -> impl Into<&'a ()> + use<> { x }
|
||||
| this lifetime parameter is captured
|
||||
|
||||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
|
||||
--> $DIR/forgot-to-capture-lifetime.rs:6:62
|
||||
--> $DIR/forgot-to-capture-lifetime.rs:4:62
|
||||
|
|
||||
LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<> { x }
|
||||
| -- ------------------ ^
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn type_param<T>() -> impl Sized + use<> {}
|
||||
//~^ ERROR `impl Trait` must mention all type parameters in scope
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
|
||||
--> $DIR/forgot-to-capture-type.rs:7:30
|
||||
--> $DIR/forgot-to-capture-type.rs:5:30
|
||||
|
|
||||
LL | fn bar() -> impl Sized + use<>;
|
||||
| ^^^^^
|
||||
@ -7,7 +7,7 @@ LL | fn bar() -> impl Sized + use<>;
|
||||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
|
||||
|
||||
error: `impl Trait` must mention all type parameters in scope in `use<...>`
|
||||
--> $DIR/forgot-to-capture-type.rs:3:23
|
||||
--> $DIR/forgot-to-capture-type.rs:1:23
|
||||
|
|
||||
LL | fn type_param<T>() -> impl Sized + use<> {}
|
||||
| - ^^^^^^^^^^^^^^^^^^
|
||||
@ -17,7 +17,7 @@ LL | fn type_param<T>() -> impl Sized + use<> {}
|
||||
= note: currently, all type parameters are required to be mentioned in the precise captures list
|
||||
|
||||
error: `impl Trait` must mention the `Self` type of the trait in `use<...>`
|
||||
--> $DIR/forgot-to-capture-type.rs:7:17
|
||||
--> $DIR/forgot-to-capture-type.rs:5:17
|
||||
|
|
||||
LL | trait Foo {
|
||||
| --------- `Self` type parameter is implicitly captured by this `impl Trait`
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
|
||||
//~^ HELP add `'a` to the `use<...>` bound
|
||||
x
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-type-suggestion.rs:5:5
|
||||
--> $DIR/hidden-type-suggestion.rs:3:5
|
||||
|
|
||||
LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
|
||||
| -- -------------------- opaque type defined here
|
||||
@ -15,7 +15,7 @@ LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b, 'a> {
|
||||
| ++++
|
||||
|
||||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-type-suggestion.rs:11:5
|
||||
--> $DIR/hidden-type-suggestion.rs:9:5
|
||||
|
|
||||
LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<T> {
|
||||
| -- ------------------- opaque type defined here
|
||||
@ -31,7 +31,7 @@ LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<'a, T> {
|
||||
| +++
|
||||
|
||||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-type-suggestion.rs:17:5
|
||||
--> $DIR/hidden-type-suggestion.rs:15:5
|
||||
|
|
||||
LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<> {
|
||||
| -- ------------------ opaque type defined here
|
||||
@ -47,7 +47,7 @@ LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<'a> {
|
||||
| ++
|
||||
|
||||
error[E0700]: hidden type for `impl Captures<'captured>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-type-suggestion.rs:26:5
|
||||
--> $DIR/hidden-type-suggestion.rs:24:5
|
||||
|
|
||||
LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> {
|
||||
| -- ------------------------ opaque type defined here
|
||||
@ -63,7 +63,7 @@ LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captu
|
||||
| ++++++++++++++++++++++++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-type-suggestion.rs:32:5
|
||||
--> $DIR/hidden-type-suggestion.rs:30:5
|
||||
|
|
||||
LL | fn no_params_yet(_: impl Sized, y: &()) -> impl Sized {
|
||||
| --- ---------- opaque type defined here
|
||||
@ -74,7 +74,7 @@ LL | y
|
||||
| ^
|
||||
|
|
||||
note: you could use a `use<...>` bound to explicitly capture `'_`, but argument-position `impl Trait`s are not nameable
|
||||
--> $DIR/hidden-type-suggestion.rs:30:21
|
||||
--> $DIR/hidden-type-suggestion.rs:28:21
|
||||
|
|
||||
LL | fn no_params_yet(_: impl Sized, y: &()) -> impl Sized {
|
||||
| ^^^^^^^^^^
|
||||
@ -84,7 +84,7 @@ LL | fn no_params_yet<T: Sized>(_: T, y: &()) -> impl Sized + use<'_, T> {
|
||||
| ++++++++++ ~ ++++++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
|
||||
--> $DIR/hidden-type-suggestion.rs:38:5
|
||||
--> $DIR/hidden-type-suggestion.rs:36:5
|
||||
|
|
||||
LL | fn yes_params_yet<'a, T>(_: impl Sized, y: &'a ()) -> impl Sized {
|
||||
| -- ---------- opaque type defined here
|
||||
@ -95,7 +95,7 @@ LL | y
|
||||
| ^
|
||||
|
|
||||
note: you could use a `use<...>` bound to explicitly capture `'a`, but argument-position `impl Trait`s are not nameable
|
||||
--> $DIR/hidden-type-suggestion.rs:36:29
|
||||
--> $DIR/hidden-type-suggestion.rs:34:29
|
||||
|
|
||||
LL | fn yes_params_yet<'a, T>(_: impl Sized, y: &'a ()) -> impl Sized {
|
||||
| ^^^^^^^^^^
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
// Show how precise captures allow us to skip capturing a higher-ranked lifetime
|
||||
|
||||
#![feature(lifetime_capture_rules_2024, precise_capturing)]
|
||||
#![feature(lifetime_capture_rules_2024)]
|
||||
|
||||
trait Trait<'a> {
|
||||
type Item;
|
||||
|
@ -1,53 +1,53 @@
|
||||
error: `use<...>` precise capturing syntax not allowed in supertrait bounds
|
||||
--> $DIR/illegal-positions.rs:8:12
|
||||
--> $DIR/illegal-positions.rs:6:12
|
||||
|
|
||||
LL | trait Foo: use<> {
|
||||
| ^^^^^
|
||||
|
||||
error: `use<...>` precise capturing syntax not allowed in bounds
|
||||
--> $DIR/illegal-positions.rs:10:33
|
||||
--> $DIR/illegal-positions.rs:8:33
|
||||
|
|
||||
LL | type Assoc: use<> where (): use<>;
|
||||
| ^^^^^
|
||||
|
||||
error: `use<...>` precise capturing syntax not allowed in bounds
|
||||
--> $DIR/illegal-positions.rs:10:17
|
||||
--> $DIR/illegal-positions.rs:8:17
|
||||
|
|
||||
LL | type Assoc: use<> where (): use<>;
|
||||
| ^^^^^
|
||||
|
||||
error: `use<...>` precise capturing syntax not allowed in bounds
|
||||
--> $DIR/illegal-positions.rs:16:11
|
||||
--> $DIR/illegal-positions.rs:14:11
|
||||
|
|
||||
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
|
||||
| ^^^^^
|
||||
|
||||
error: `use<...>` precise capturing syntax not allowed in bounds
|
||||
--> $DIR/illegal-positions.rs:16:43
|
||||
--> $DIR/illegal-positions.rs:14:43
|
||||
|
|
||||
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
|
||||
| ^^^^^
|
||||
|
||||
error: at least one trait must be specified
|
||||
--> $DIR/illegal-positions.rs:16:21
|
||||
--> $DIR/illegal-positions.rs:14:21
|
||||
|
|
||||
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: `use<...>` precise capturing syntax not allowed in `dyn` trait object bounds
|
||||
--> $DIR/illegal-positions.rs:23:25
|
||||
--> $DIR/illegal-positions.rs:21:25
|
||||
|
|
||||
LL | fn dynamic() -> Box<dyn use<>> {}
|
||||
| ^^^^^
|
||||
|
||||
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
|
||||
--> $DIR/illegal-positions.rs:16:26
|
||||
--> $DIR/illegal-positions.rs:14:26
|
||||
|
|
||||
LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
|
||||
| ^^^^^
|
||||
|
||||
error[E0224]: at least one trait is required for an object type
|
||||
--> $DIR/illegal-positions.rs:23:21
|
||||
--> $DIR/illegal-positions.rs:21:21
|
||||
|
|
||||
LL | fn dynamic() -> Box<dyn use<>> {}
|
||||
| ^^^^^^^^^
|
||||
|
@ -2,8 +2,6 @@
|
||||
//@[pre_expansion] check-pass
|
||||
//@ edition: 2021
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
#[cfg(real)]
|
||||
trait Foo: use<> {
|
||||
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn lt<'a>() -> impl Sized + use<'a, 'a> {}
|
||||
//~^ ERROR cannot capture parameter `'a` twice
|
||||
|
||||
|
@ -1,23 +1,23 @@
|
||||
error: cannot capture parameter `'a` twice
|
||||
--> $DIR/ordering.rs:3:33
|
||||
--> $DIR/ordering.rs:1:33
|
||||
|
|
||||
LL | fn lt<'a>() -> impl Sized + use<'a, 'a> {}
|
||||
| ^^ -- parameter captured again here
|
||||
|
||||
error: cannot capture parameter `T` twice
|
||||
--> $DIR/ordering.rs:6:32
|
||||
--> $DIR/ordering.rs:4:32
|
||||
|
|
||||
LL | fn ty<T>() -> impl Sized + use<T, T> {}
|
||||
| ^ - parameter captured again here
|
||||
|
||||
error: cannot capture parameter `N` twice
|
||||
--> $DIR/ordering.rs:9:45
|
||||
--> $DIR/ordering.rs:7:45
|
||||
|
|
||||
LL | fn ct<const N: usize>() -> impl Sized + use<N, N> {}
|
||||
| ^ - parameter captured again here
|
||||
|
||||
error: lifetime parameter `'a` must be listed before non-lifetime parameters
|
||||
--> $DIR/ordering.rs:12:45
|
||||
--> $DIR/ordering.rs:10:45
|
||||
|
|
||||
LL | fn ordering<'a, T>() -> impl Sized + use<T, 'a> {}
|
||||
| - ^^
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
// Show that precise captures allow us to skip a lifetime param for outlives
|
||||
|
||||
#![feature(lifetime_capture_rules_2024, precise_capturing)]
|
||||
#![feature(lifetime_capture_rules_2024)]
|
||||
|
||||
fn hello<'a: 'a, 'b: 'b>() -> impl Sized + use<'a> { }
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
//@ run-rustfix
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
#![allow(unused, incomplete_features)]
|
||||
#![allow(unused)]
|
||||
#![deny(impl_trait_overcaptures)]
|
||||
|
||||
fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
|
||||
|
@ -1,7 +1,6 @@
|
||||
//@ run-rustfix
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
#![allow(unused, incomplete_features)]
|
||||
#![allow(unused)]
|
||||
#![deny(impl_trait_overcaptures)]
|
||||
|
||||
fn named<'a>(x: &'a i32) -> impl Sized { *x }
|
||||
|
@ -1,17 +1,17 @@
|
||||
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
|
||||
--> $DIR/overcaptures-2024.rs:7:29
|
||||
--> $DIR/overcaptures-2024.rs:6:29
|
||||
|
|
||||
LL | fn named<'a>(x: &'a i32) -> impl Sized { *x }
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
|
||||
--> $DIR/overcaptures-2024.rs:7:10
|
||||
--> $DIR/overcaptures-2024.rs:6:10
|
||||
|
|
||||
LL | fn named<'a>(x: &'a i32) -> impl Sized { *x }
|
||||
| ^^
|
||||
= note: all lifetimes in scope will be captured by `impl Trait`s in edition 2024
|
||||
note: the lint level is defined here
|
||||
--> $DIR/overcaptures-2024.rs:5:9
|
||||
--> $DIR/overcaptures-2024.rs:4:9
|
||||
|
|
||||
LL | #![deny(impl_trait_overcaptures)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -21,13 +21,13 @@ LL | fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }
|
||||
| +++++++
|
||||
|
||||
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
|
||||
--> $DIR/overcaptures-2024.rs:10:25
|
||||
--> $DIR/overcaptures-2024.rs:9:25
|
||||
|
|
||||
LL | fn implicit(x: &i32) -> impl Sized { *x }
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
|
||||
--> $DIR/overcaptures-2024.rs:10:16
|
||||
--> $DIR/overcaptures-2024.rs:9:16
|
||||
|
|
||||
LL | fn implicit(x: &i32) -> impl Sized { *x }
|
||||
| ^
|
||||
@ -38,13 +38,13 @@ LL | fn implicit(x: &i32) -> impl Sized + use<> { *x }
|
||||
| +++++++
|
||||
|
||||
error: `impl Sized + '_` will capture more lifetimes than possibly intended in edition 2024
|
||||
--> $DIR/overcaptures-2024.rs:15:33
|
||||
--> $DIR/overcaptures-2024.rs:14:33
|
||||
|
|
||||
LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
|
||||
--> $DIR/overcaptures-2024.rs:15:24
|
||||
--> $DIR/overcaptures-2024.rs:14:24
|
||||
|
|
||||
LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
|
||||
| ^
|
||||
@ -55,13 +55,13 @@ LL | fn hello(&self, x: &i32) -> impl Sized + '_ + use<'_> { self }
|
||||
| +++++++++
|
||||
|
||||
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024
|
||||
--> $DIR/overcaptures-2024.rs:26:47
|
||||
--> $DIR/overcaptures-2024.rs:25:47
|
||||
|
|
||||
LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: specifically, this lifetime is in scope but not mentioned in the type's bounds
|
||||
--> $DIR/overcaptures-2024.rs:26:23
|
||||
--> $DIR/overcaptures-2024.rs:25:23
|
||||
|
|
||||
LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
|
||||
| ^^
|
||||
|
@ -1,5 +1,5 @@
|
||||
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
|
||||
--> $DIR/redundant.rs:7:19
|
||||
--> $DIR/redundant.rs:5:19
|
||||
|
|
||||
LL | fn hello<'a>() -> impl Sized + use<'a> {}
|
||||
| ^^^^^^^^^^^^^-------
|
||||
@ -9,7 +9,7 @@ LL | fn hello<'a>() -> impl Sized + use<'a> {}
|
||||
= note: `#[warn(impl_trait_redundant_captures)]` on by default
|
||||
|
||||
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
|
||||
--> $DIR/redundant.rs:12:27
|
||||
--> $DIR/redundant.rs:10:27
|
||||
|
|
||||
LL | fn inherent(&self) -> impl Sized + use<'_> {}
|
||||
| ^^^^^^^^^^^^^-------
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
|
||||
--> $DIR/redundant.rs:18:35
|
||||
--> $DIR/redundant.rs:16:35
|
||||
|
|
||||
LL | fn in_trait() -> impl Sized + use<'a, Self>;
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -7,7 +7,7 @@ LL | fn in_trait() -> impl Sized + use<'a, Self>;
|
||||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
|
||||
|
||||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
|
||||
--> $DIR/redundant.rs:23:35
|
||||
--> $DIR/redundant.rs:21:35
|
||||
|
|
||||
LL | fn in_trait() -> impl Sized + use<'a> {}
|
||||
| ^^^^^^^
|
||||
|
@ -2,8 +2,6 @@
|
||||
//@ revisions: normal rpitit
|
||||
//@[normal] check-pass
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
fn hello<'a>() -> impl Sized + use<'a> {}
|
||||
//[normal]~^ WARN all possible in-scope parameters are already captured
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
// To fix this soundly, we need to make sure that all the trait header args
|
||||
// remain captured, since they affect trait selection.
|
||||
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
trait Foo<'a> {
|
||||
fn hello() -> impl PartialEq + use<Self>;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
|
||||
--> $DIR/rpitit.rs:11:36
|
||||
--> $DIR/rpitit.rs:9:36
|
||||
|
|
||||
LL | fn hello() -> impl PartialEq + use<Self>;
|
||||
| ^^^^^^^^^
|
||||
@ -7,7 +7,7 @@ LL | fn hello() -> impl PartialEq + use<Self>;
|
||||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
|
||||
|
||||
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
|
||||
--> $DIR/rpitit.rs:11:19
|
||||
--> $DIR/rpitit.rs:9:19
|
||||
|
|
||||
LL | trait Foo<'a> {
|
||||
| -- this lifetime parameter is captured
|
||||
@ -15,7 +15,7 @@ LL | fn hello() -> impl PartialEq + use<Self>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait`
|
||||
|
||||
error: lifetime may not live long enough
|
||||
--> $DIR/rpitit.rs:15:5
|
||||
--> $DIR/rpitit.rs:13:5
|
||||
|
|
||||
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
@ -30,7 +30,7 @@ LL | | );
|
||||
= help: consider adding the following bound: `'a: 'b`
|
||||
|
||||
error: lifetime may not live long enough
|
||||
--> $DIR/rpitit.rs:15:5
|
||||
--> $DIR/rpitit.rs:13:5
|
||||
|
|
||||
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
|
||||
| -- -- lifetime `'b` defined here
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(precise_capturing)]
|
||||
|
||||
trait Foo {
|
||||
fn bar<'a>() -> impl Sized + use<Self>;
|
||||
//~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
|
||||
--> $DIR/self-capture.rs:4:34
|
||||
--> $DIR/self-capture.rs:2:34
|
||||
|
|
||||
LL | fn bar<'a>() -> impl Sized + use<Self>;
|
||||
| ^^^^^^^^^
|
||||
|
@ -9,10 +9,10 @@ LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y>
|
||||
LL | x
|
||||
| ^
|
||||
|
|
||||
help: to declare that `impl Trait<'y>` captures `'x`, you can add an explicit `'x` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'x`
|
||||
|
|
||||
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + 'x
|
||||
| ++++
|
||||
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + use<'y, 'x>
|
||||
| +++++++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -8,10 +8,10 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
|
||||
LL | self.x.iter().map(|a| a.0)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl Iterator<Item = u32>` captures `'_`, you can add an explicit `'_` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
|
||||
| ++++
|
||||
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + use<'_> {
|
||||
| +++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Iterator<Item = u32>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/static-return-lifetime-infered.rs:11:9
|
||||
@ -23,10 +23,10 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
|
||||
LL | self.x.iter().map(|a| a.0)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl Iterator<Item = u32>` captures `'a`, you can add an explicit `'a` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'a`
|
||||
|
|
||||
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
|
||||
| ++++
|
||||
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + use<'a> {
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Regression test for issue #105227.
|
||||
|
||||
//@ run-rustfix
|
||||
#![allow(warnings)]
|
||||
fn chars0<'a>(v :(&'a str, &'a str)) -> impl Iterator<Item = char> + 'a {
|
||||
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
||||
v.0.chars().chain(v.1.chars())
|
||||
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
|
||||
}
|
||||
|
||||
fn chars1<'a>(v0 : &'a str, v1 : &'a str) -> impl Iterator<Item = char> + 'a {
|
||||
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
||||
v0.chars().chain(v1.chars())
|
||||
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bound
|
||||
}
|
||||
|
||||
fn chars2<'b>(v0 : &'b str, v1 : &'b str, v2 : &'b str) ->
|
||||
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can use the named lifetime parameter `'b`
|
||||
(impl Iterator<Item = char> + 'b , &'b str)
|
||||
{
|
||||
(v0.chars().chain(v1.chars()), v2)
|
||||
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bound
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
@ -1,23 +1,23 @@
|
||||
// Regression test for issue #105227.
|
||||
|
||||
//@ run-rustfix
|
||||
#![allow(warnings)]
|
||||
// FIXME(precise_capturing): Add rustfix here after dealing w/ elided lifetimes
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
fn chars0(v :(& str, &str)) -> impl Iterator<Item = char> {
|
||||
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
||||
//~^ HELP add a `use<...>` bound
|
||||
v.0.chars().chain(v.1.chars())
|
||||
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
|
||||
}
|
||||
|
||||
fn chars1(v0 : & str, v1 : &str) -> impl Iterator<Item = char> {
|
||||
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
||||
//~^ HELP add a `use<...>` bound
|
||||
v0.chars().chain(v1.chars())
|
||||
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bound
|
||||
}
|
||||
|
||||
fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) ->
|
||||
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can use the named lifetime parameter `'b`
|
||||
(impl Iterator<Item = char>, &'b str)
|
||||
{
|
||||
fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) -> (impl Iterator<Item = char>, &'b str) {
|
||||
//~^ HELP add a `use<...>` bound
|
||||
(v0.chars().chain(v1.chars()), v2)
|
||||
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bound
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0700]: hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/issue-105227.rs:7:5
|
||||
--> $DIR/issue-105227.rs:9:5
|
||||
|
|
||||
LL | fn chars0(v :(& str, &str)) -> impl Iterator<Item = char> {
|
||||
| ----- -------------------------- opaque type defined here
|
||||
@ -9,13 +9,13 @@ LL |
|
||||
LL | v.0.chars().chain(v.1.chars())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | fn chars0<'a>(v :(&'a str, &'a str)) -> impl Iterator<Item = char> + 'a {
|
||||
| ++++ ++ ++ ++++
|
||||
LL | fn chars0(v :(& str, &str)) -> impl Iterator<Item = char> + use<'_> {
|
||||
| +++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/issue-105227.rs:13:5
|
||||
--> $DIR/issue-105227.rs:15:5
|
||||
|
|
||||
LL | fn chars1(v0 : & str, v1 : &str) -> impl Iterator<Item = char> {
|
||||
| ----- -------------------------- opaque type defined here
|
||||
@ -25,29 +25,26 @@ LL |
|
||||
LL | v0.chars().chain(v1.chars())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | fn chars1<'a>(v0 : &'a str, v1 : &'a str) -> impl Iterator<Item = char> + 'a {
|
||||
| ++++ ++ ++ ++++
|
||||
LL | fn chars1(v0 : & str, v1 : &str) -> impl Iterator<Item = char> + use<'_> {
|
||||
| +++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/issue-105227.rs:21:5
|
||||
|
|
||||
LL | fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) ->
|
||||
| ---- hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here
|
||||
LL | fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) -> (impl Iterator<Item = char>, &'b str) {
|
||||
| ---- -------------------------- opaque type defined here
|
||||
| |
|
||||
| hidden type `std::iter::Chain<Chars<'_>, Chars<'_>>` captures the anonymous lifetime defined here
|
||||
LL |
|
||||
LL | (impl Iterator<Item = char>, &'b str)
|
||||
| -------------------------- opaque type defined here
|
||||
LL | {
|
||||
LL | (v0.chars().chain(v1.chars()), v2)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl Iterator<Item = char>` captures `'_`, you can use the named lifetime parameter `'b`
|
||||
|
|
||||
LL ~ fn chars2<'b>(v0 : &'b str, v1 : &'b str, v2 : &'b str) ->
|
||||
LL |
|
||||
LL ~ (impl Iterator<Item = char> + 'b , &'b str)
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) -> (impl Iterator<Item = char> + use<'_>, &'b str) {
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -7,6 +7,11 @@ LL | fn make_it(&self) -> impl Iterator<Item = u8> {
|
||||
| ------------------------ opaque type defined here
|
||||
LL | self.0.iter().copied()
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a `use<...>` bound to explicitly capture `'a`
|
||||
|
|
||||
LL | fn make_it(&self) -> impl Iterator<Item = u8> + use<'a> {
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -37,10 +37,10 @@ LL | fn test_ambiguous<'a, 'b, 'c>(s: &'a u8) -> impl Cap<'b> + Cap<'c>
|
||||
LL | s
|
||||
| ^
|
||||
|
|
||||
help: to declare that `impl Cap<'b> + Cap<'c>` captures `'a`, you can add an explicit `'a` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'a`
|
||||
|
|
||||
LL | fn test_ambiguous<'a, 'b, 'c>(s: &'a u8) -> impl Cap<'b> + Cap<'c> + 'a
|
||||
| ++++
|
||||
LL | fn test_ambiguous<'a, 'b, 'c>(s: &'a u8) -> impl Cap<'b> + Cap<'c> + use<'b, 'c, 'a>
|
||||
| +++++++++++++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -9,14 +9,10 @@ LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl
|
||||
LL | [a]
|
||||
| ^^^
|
||||
|
|
||||
help: to declare that `impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'s`
|
||||
|
|
||||
LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> + 's
|
||||
| ++++
|
||||
help: to declare that `impl Cap<'a> + Cap<'b>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
|
|
||||
LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b> + 's>
|
||||
| ++++
|
||||
LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> + use<'a, 'b, 's>
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Cap<'a> + Cap<'b>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/nested-impl-trait-fail.rs:17:5
|
||||
@ -29,14 +25,10 @@ LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl
|
||||
LL | [a]
|
||||
| ^^^
|
||||
|
|
||||
help: to declare that `impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'s`
|
||||
|
|
||||
LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> + 's
|
||||
| ++++
|
||||
help: to declare that `impl Cap<'a> + Cap<'b>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
|
|
||||
LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b> + 's>
|
||||
| ++++
|
||||
LL | fn fail_early_bound<'s, 'a, 'b>(a: &'s u8) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b> + use<'a, 'b, 's>>
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/nested-impl-trait-fail.rs:28:5
|
||||
@ -49,14 +41,10 @@ LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> {
|
||||
LL | [a]
|
||||
| ^^^
|
||||
|
|
||||
help: to declare that `impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'s`
|
||||
|
|
||||
LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> + 's {
|
||||
| ++++
|
||||
help: to declare that `impl Cap<'a> + Cap<'b>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
|
|
||||
LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b> + 's> {
|
||||
| ++++
|
||||
LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> + use<'a, 'b, 's> {
|
||||
| +++++++++++++++++
|
||||
|
||||
error[E0700]: hidden type for `impl Cap<'a> + Cap<'b>` captures lifetime that does not appear in bounds
|
||||
--> $DIR/nested-impl-trait-fail.rs:28:5
|
||||
@ -69,14 +57,10 @@ LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> {
|
||||
LL | [a]
|
||||
| ^^^
|
||||
|
|
||||
help: to declare that `impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'s`
|
||||
|
|
||||
LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> + 's {
|
||||
| ++++
|
||||
help: to declare that `impl Cap<'a> + Cap<'b>` captures `'s`, you can add an explicit `'s` lifetime bound
|
||||
|
|
||||
LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b> + 's> {
|
||||
| ++++
|
||||
LL | ) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b> + use<'a, 'b, 's>> {
|
||||
| +++++++++++++++++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -25,10 +25,10 @@ LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne {
|
||||
LL | <&mut i32 as Callable>::call(y)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl PlusOne` captures `'a`, you can add an explicit `'a` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'a`
|
||||
|
|
||||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + 'a {
|
||||
| ++++
|
||||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + use<'a> {
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -25,10 +25,10 @@ LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne {
|
||||
LL | <&mut i32 as Callable>::call(y)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl PlusOne` captures `'a`, you can add an explicit `'a` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'a`
|
||||
|
|
||||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + 'a {
|
||||
| ++++
|
||||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + use<'a> {
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -8,10 +8,10 @@ LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> {
|
||||
LL | x
|
||||
| ^
|
||||
|
|
||||
help: to declare that `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), ['a/#0, T, 'a/#2])` captures `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))`, you can add an explicit `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_))`
|
||||
|
|
||||
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)) {
|
||||
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
LL | fn foo<'a, T>(x: &T) -> impl Foo<'a> + use<'a, ReLateParam(DefId(0:8 ~ impl_trait_captures[aeb9]::foo), BrNamed(DefId(0:12 ~ impl_trait_captures[aeb9]::foo::'_), '_)), T> {
|
||||
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -7,10 +7,10 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
|
||||
| | opaque type defined here
|
||||
| hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
|
||||
|
|
||||
help: to declare that `impl Clone` captures `'_`, you can add an explicit `'_` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
|
||||
| ++++
|
||||
LL | async fn f(self: Pin<&Self>) -> impl Clone + use<'_> { self }
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -7,10 +7,10 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self }
|
||||
| | opaque type defined here
|
||||
| hidden type `Pin<&Foo>` captures the anonymous lifetime defined here
|
||||
|
|
||||
help: to declare that `impl Clone` captures `'_`, you can add an explicit `'_` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
|
||||
| ++++
|
||||
LL | fn f(self: Pin<&Self>) -> impl Clone + use<'_> { self }
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -20,10 +20,10 @@ LL | | *dest = g.get();
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
help: to declare that `impl FnOnce()` captures `'_`, you can add an explicit `'_` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'_`
|
||||
|
|
||||
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
|
||||
| ++++
|
||||
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + use<'_, G, T>
|
||||
| +++++++++++++++
|
||||
|
||||
error[E0311]: the parameter type `G` may not live long enough
|
||||
--> $DIR/missing-lifetimes-in-signature.rs:30:5
|
||||
|
@ -9,11 +9,6 @@ LL | fn get_one<'a>(a: *mut &'a str) -> impl IntoIterator<Item = Opaque<'a>> {
|
||||
...
|
||||
LL | None::<Opaque<'static>>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl IntoIterator<Item = Opaque<'a>>` captures `'a`, you can add an explicit `'a` lifetime bound
|
||||
|
|
||||
LL | fn get_one<'a>(a: *mut &'a str) -> impl IntoIterator<Item = Opaque<'a>> + 'a {
|
||||
| ++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -8,10 +8,10 @@ LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne {
|
||||
LL | <&'a mut i32 as Callable>::call(y)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: to declare that `impl PlusOne` captures `'a`, you can add an explicit `'a` lifetime bound
|
||||
help: add a `use<...>` bound to explicitly capture `'a`
|
||||
|
|
||||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + 'a {
|
||||
| ++++
|
||||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + use<'a> {
|
||||
| +++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user