Stabilize opaque type precise capturing

This commit is contained in:
Michael Goulet 2024-07-12 06:12:24 -04:00
parent c6f81a452e
commit eae5b5c6e7
49 changed files with 70 additions and 134 deletions

View File

@ -557,7 +557,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!(fn_delegation, "functions delegation is not yet fully implemented");
gate_all!(postfix_match, "postfix match is experimental"); gate_all!(postfix_match, "postfix match is experimental");
gate_all!(mut_ref, "mutable by-reference bindings are 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!(global_registration, "global registration is experimental");
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental"); gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
gate_all!(return_type_notation, "return type notation is experimental"); gate_all!(return_type_notation, "return type notation is experimental");

View File

@ -309,6 +309,8 @@ declare_features! (
(accepted, param_attrs, "1.39.0", Some(60406)), (accepted, param_attrs, "1.39.0", Some(60406)),
/// Allows parentheses in patterns. /// Allows parentheses in patterns.
(accepted, pattern_parentheses, "1.31.0", Some(51087)), (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. /// Allows procedural macros in `proc-macro` crates.
(accepted, proc_macro, "1.29.0", Some(38356)), (accepted, proc_macro, "1.29.0", Some(38356)),
/// Allows multi-segment paths in attributes and derives. /// Allows multi-segment paths in attributes and derives.

View File

@ -561,8 +561,6 @@ declare_features! (
(unstable, patchable_function_entry, "1.81.0", Some(123115)), (unstable, patchable_function_entry, "1.81.0", Some(123115)),
/// Allows postfix match `expr.match { ... }` /// Allows postfix match `expr.match { ... }`
(unstable, postfix_match, "1.79.0", Some(121618)), (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. /// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)), (unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.

View File

@ -2773,7 +2773,6 @@ impl PreciseCapturingArg<'_> {
/// resolution to. Lifetimes don't have this problem, and for them, it's actually /// 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`], /// kind of detrimental to use a custom node type versus just using [`Lifetime`],
/// since resolve_bound_vars operates on `Lifetime`s. /// since resolve_bound_vars operates on `Lifetime`s.
// FIXME(precise_capturing): Investigate storing this as a path instead?
#[derive(Debug, Clone, Copy, HashStable_Generic)] #[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct PreciseCapturingNonLifetimeArg { pub struct PreciseCapturingNonLifetimeArg {
pub hir_id: HirId, pub hir_id: HirId,

View File

@ -27,8 +27,6 @@ declare_lint! {
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```rust,compile_fail
/// # #![feature(precise_capturing)]
/// # #![allow(incomplete_features)]
/// # #![deny(impl_trait_overcaptures)] /// # #![deny(impl_trait_overcaptures)]
/// # use std::fmt::Display; /// # use std::fmt::Display;
/// let mut x = vec![]; /// let mut x = vec![];
@ -56,7 +54,6 @@ declare_lint! {
pub IMPL_TRAIT_OVERCAPTURES, pub IMPL_TRAIT_OVERCAPTURES,
Allow, Allow,
"`impl Trait` will capture more lifetimes than possibly intended in edition 2024", "`impl Trait` will capture more lifetimes than possibly intended in edition 2024",
@feature_gate = precise_capturing;
//@future_incompatible = FutureIncompatibleInfo { //@future_incompatible = FutureIncompatibleInfo {
// reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024), // reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
// reference: "<FIXME>", // reference: "<FIXME>",
@ -75,8 +72,7 @@ declare_lint! {
/// ### Example /// ### Example
/// ///
/// ```rust,compile_fail /// ```rust,compile_fail
/// # #![feature(precise_capturing, lifetime_capture_rules_2024)] /// # #![feature(lifetime_capture_rules_2024)]
/// # #![allow(incomplete_features)]
/// # #![deny(impl_trait_redundant_captures)] /// # #![deny(impl_trait_redundant_captures)]
/// fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x } /// fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x }
/// ``` /// ```
@ -90,7 +86,6 @@ declare_lint! {
pub IMPL_TRAIT_REDUNDANT_CAPTURES, pub IMPL_TRAIT_REDUNDANT_CAPTURES,
Warn, Warn,
"redundant precise-capturing `use<...>` syntax on an `impl Trait`", "redundant precise-capturing `use<...>` syntax on an `impl Trait`",
@feature_gate = precise_capturing;
} }
declare_lint_pass!( declare_lint_pass!(

View File

@ -851,7 +851,6 @@ impl<'a> Parser<'a> {
// lifetimes and ident params (including SelfUpper). These are validated later // lifetimes and ident params (including SelfUpper). These are validated later
// for order, duplication, and whether they actually reference params. // for order, duplication, and whether they actually reference params.
let use_span = self.prev_token.span; 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()?; let (args, args_span) = self.parse_precise_capturing_args()?;
GenericBound::Use(args, use_span.to(args_span)) GenericBound::Use(args, use_span.to(args_span))
} else { } else {

View File

@ -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[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[1]" \"T\"
//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[2]" \"N\" //@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[2]" \"N\"

View File

@ -1,7 +1,6 @@
//@ aux-build:precise-capturing.rs //@ aux-build:precise-capturing.rs
#![crate_name = "foo"] #![crate_name = "foo"]
#![feature(precise_capturing)]
extern crate precise_capturing; extern crate precise_capturing;

View File

@ -1,4 +0,0 @@
fn hello() -> impl Sized + use<> {}
//~^ ERROR precise captures on `impl Trait` are experimental
fn main() {}

View File

@ -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`.

View File

@ -1,5 +1,5 @@
error[E0282]: type annotations needed 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); LL | let mut iter = foo(n - 1, m);
| ^^^^^^^^ | ^^^^^^^^

View File

@ -2,8 +2,6 @@
//@[next] compile-flags: -Znext-solver //@[next] compile-flags: -Znext-solver
//@[current] run-pass //@[current] run-pass
#![feature(precise_capturing)]
trait Get { trait Get {
fn get(&mut self) -> u32; fn get(&mut self) -> u32;
} }

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn hello(_: impl Sized + use<>) {} fn hello(_: impl Sized + use<>) {}
//~^ ERROR `use<...>` precise capturing syntax not allowed in argument-position `impl Trait` //~^ ERROR `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`

View File

@ -1,5 +1,5 @@
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait` 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<>) {} LL | fn hello(_: impl Sized + use<>) {}
| ^^^^^ | ^^^^^

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn no_elided_lt() -> impl Sized + use<'_> {} fn no_elided_lt() -> impl Sized + use<'_> {}
//~^ ERROR missing lifetime specifier //~^ ERROR missing lifetime specifier
//~| ERROR expected lifetime parameter in `use<...>` precise captures list, found `'_` //~| ERROR expected lifetime parameter in `use<...>` precise captures list, found `'_`

View File

@ -1,5 +1,5 @@
error[E0106]: missing lifetime specifier 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<'_> {} LL | fn no_elided_lt() -> impl Sized + use<'_> {}
| ^^ expected named lifetime parameter | ^^ 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` 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> {} LL | fn missing_lt() -> impl Sized + use<'missing> {}
| - ^^^^^^^^ undeclared lifetime | - ^^^^^^^^ undeclared lifetime
@ -19,13 +19,13 @@ LL | fn missing_lt() -> impl Sized + use<'missing> {}
| help: consider introducing lifetime `'missing` here: `<'missing>` | help: consider introducing lifetime `'missing` here: `<'missing>`
error: expected lifetime parameter in `use<...>` precise captures list, found `'_` 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<'_> {} LL | fn no_elided_lt() -> impl Sized + use<'_> {}
| ^^ | ^^
error: expected lifetime parameter in `use<...>` precise captures list, found `'static` 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> {} LL | fn static_lt() -> impl Sized + use<'static> {}
| ^^^^^^^ | ^^^^^^^

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn missing() -> impl Sized + use<T> {} fn missing() -> impl Sized + use<T> {}
//~^ ERROR cannot find type `T` in this scope //~^ ERROR cannot find type `T` in this scope

View File

@ -1,5 +1,5 @@
error[E0412]: cannot find type `T` in this scope 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> {} LL | fn missing() -> impl Sized + use<T> {}
| ^ not found in this scope | ^ 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 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> {} LL | fn missing_self() -> impl Sized + use<Self> {}
| ------------ ^^^^ `Self` is only available in impls, traits, and type definitions | ------------ ^^^^ `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 | `Self` not allowed in a function
error: `Self` can't be captured in `use<...>` precise captures list, since it is an alias 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 { LL | impl MyType {
| ----------- `Self` is not a generic argument, but an alias to the type of the implementation | ----------- `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 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> {} LL | fn hello() -> impl Sized + use<hello> {}
| ^^^^^ | ^^^^^

View File

@ -1,7 +1,5 @@
//@ edition: 2021 //@ edition: 2021
#![feature(precise_capturing)]
fn polarity() -> impl Sized + ?use<> {} fn polarity() -> impl Sized + ?use<> {}
//~^ ERROR expected identifier, found keyword `use` //~^ ERROR expected identifier, found keyword `use`
//~| ERROR cannot find trait `r#use` in this scope //~| ERROR cannot find trait `r#use` in this scope

View File

@ -1,53 +1,53 @@
error: expected identifier, found keyword `use` error: expected identifier, found keyword `use`
--> $DIR/bound-modifiers.rs:5:32 --> $DIR/bound-modifiers.rs:3:32
| |
LL | fn polarity() -> impl Sized + ?use<> {} LL | fn polarity() -> impl Sized + ?use<> {}
| ^^^ expected identifier, found keyword | ^^^ expected identifier, found keyword
error: expected identifier, found keyword `use` 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<> {} LL | fn asyncness() -> impl Sized + async use<> {}
| ^^^ expected identifier, found keyword | ^^^ expected identifier, found keyword
error: expected identifier, found keyword `use` 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<> {} LL | fn constness() -> impl Sized + const use<> {}
| ^^^ expected identifier, found keyword | ^^^ expected identifier, found keyword
error: expected identifier, found keyword `use` 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<> {} LL | fn binder() -> impl Sized + for<'a> use<> {}
| ^^^ expected identifier, found keyword | ^^^ expected identifier, found keyword
error[E0405]: cannot find trait `r#use` in this scope 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<> {} LL | fn polarity() -> impl Sized + ?use<> {}
| ^^^ not found in this scope | ^^^ not found in this scope
error[E0405]: cannot find trait `r#use` 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<> {} LL | fn asyncness() -> impl Sized + async use<> {}
| ^^^ not found in this scope | ^^^ not found in this scope
error[E0405]: cannot find trait `r#use` 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<> {} LL | fn constness() -> impl Sized + const use<> {}
| ^^^ not found in this scope | ^^^ not found in this scope
error[E0405]: cannot find trait `r#use` 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<> {} LL | fn binder() -> impl Sized + for<'a> use<> {}
| ^^^ not found in this scope | ^^^ not found in this scope
error[E0658]: async closures are unstable 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<> {} 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 {` = help: to use an async block, remove the `||`: `async {`
error[E0658]: const trait impls are experimental 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<> {} 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 = 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 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<> {} LL | fn polarity() -> impl Sized + ?use<> {}
| ^^^^^^ | ^^^^^^
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default 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<> {} LL | fn polarity() -> impl Sized + ?use<> {}
| ^^^^^^ | ^^^^^^

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
trait Tr { trait Tr {
type Assoc; type Assoc;
} }

View File

@ -1,5 +1,5 @@
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list 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> { LL | impl<'a> W<'a> {
| -- this lifetime parameter is captured | -- 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` | -------------^^------------------------ 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 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> { LL | impl<'a> W<'a> {
| -- this lifetime parameter is captured | -- this lifetime parameter is captured

View File

@ -1,5 +1,5 @@
error: duplicate `use<...>` precise capturing syntax 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> {} LL | fn hello<'a>() -> impl Sized + use<'a> + use<'a> {}
| ^^^^^^^ ------- second `use<...>` here | ^^^^^^^ ------- second `use<...>` here

View File

@ -1,8 +1,6 @@
//@ revisions: real pre_expansion //@ revisions: real pre_expansion
//@[pre_expansion] check-pass //@[pre_expansion] check-pass
#![feature(precise_capturing)]
#[cfg(real)] #[cfg(real)]
fn hello<'a>() -> impl Sized + use<'a> + use<'a> {} fn hello<'a>() -> impl Sized + use<'a> + use<'a> {}
//[real]~^ ERROR duplicate `use<...>` precise capturing syntax //[real]~^ ERROR duplicate `use<...>` precise capturing syntax

View File

@ -1,4 +1,2 @@
#![feature(precise_capturing)]
fn dyn() -> &'static dyn use<> { &() } fn dyn() -> &'static dyn use<> { &() }
//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use` //~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`

View File

@ -1,5 +1,5 @@
error: expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use` 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<> { &() } LL | fn dyn() -> &'static dyn use<> { &() }
| ^^^ expected one of `!`, `(`, `::`, `<`, `where`, or `{` | ^^^ expected one of `!`, `(`, `::`, `<`, `where`, or `{`

View File

@ -1,7 +1,5 @@
//@ check-pass //@ check-pass
#![feature(precise_capturing)]
fn elided(x: &()) -> impl Sized + use<'_> { x } fn elided(x: &()) -> impl Sized + use<'_> { x }
fn main() {} fn main() {}

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn constant<const C: usize>() -> impl Sized + use<> {} fn constant<const C: usize>() -> impl Sized + use<> {}
//~^ ERROR `impl Trait` must mention all const parameters in scope //~^ ERROR `impl Trait` must mention all const parameters in scope

View File

@ -1,5 +1,5 @@
error: `impl Trait` must mention all const parameters in scope in `use<...>` 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<> {} LL | fn constant<const C: usize>() -> impl Sized + use<> {}
| -------------- ^^^^^^^^^^^^^^^^^^ | -------------- ^^^^^^^^^^^^^^^^^^

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn lifetime_in_bounds<'a>(x: &'a ()) -> impl Into<&'a ()> + use<> { x } 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 //~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list

View File

@ -1,5 +1,5 @@
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list 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 } 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 | this lifetime parameter is captured
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds 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 } LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<> { x }
| -- ------------------ ^ | -- ------------------ ^

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn type_param<T>() -> impl Sized + use<> {} fn type_param<T>() -> impl Sized + use<> {}
//~^ ERROR `impl Trait` must mention all type parameters in scope //~^ ERROR `impl Trait` must mention all type parameters in scope

View File

@ -1,5 +1,5 @@
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits 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<>; 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 = 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<...>` 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<> {} 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 = 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<...>` 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 { LL | trait Foo {
| --------- `Self` type parameter is implicitly captured by this `impl Trait` | --------- `Self` type parameter is implicitly captured by this `impl Trait`

View File

@ -2,7 +2,7 @@
// Show how precise captures allow us to skip capturing a higher-ranked lifetime // 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> { trait Trait<'a> {
type Item; type Item;

View File

@ -1,53 +1,53 @@
error: `use<...>` precise capturing syntax not allowed in supertrait bounds 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<> { LL | trait Foo: use<> {
| ^^^^^ | ^^^^^
error: `use<...>` precise capturing syntax not allowed in bounds 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<>; LL | type Assoc: use<> where (): use<>;
| ^^^^^ | ^^^^^
error: `use<...>` precise capturing syntax not allowed in bounds 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<>; LL | type Assoc: use<> where (): use<>;
| ^^^^^ | ^^^^^
error: `use<...>` precise capturing syntax not allowed in bounds 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<> {} LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^ | ^^^^^
error: `use<...>` precise capturing syntax not allowed in bounds 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<> {} LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^ | ^^^^^
error: at least one trait must be specified 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<> {} LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
error: `use<...>` precise capturing syntax not allowed in `dyn` trait object bounds 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<>> {} LL | fn dynamic() -> Box<dyn use<>> {}
| ^^^^^ | ^^^^^
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait` 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<> {} LL | fn fun<T: use<>>(_: impl use<>) where (): use<> {}
| ^^^^^ | ^^^^^
error[E0224]: at least one trait is required for an object type 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<>> {} LL | fn dynamic() -> Box<dyn use<>> {}
| ^^^^^^^^^ | ^^^^^^^^^

View File

@ -2,8 +2,6 @@
//@[pre_expansion] check-pass //@[pre_expansion] check-pass
//@ edition: 2021 //@ edition: 2021
#![feature(precise_capturing)]
#[cfg(real)] #[cfg(real)]
trait Foo: use<> { trait Foo: use<> {
//[real]~^ ERROR `use<...>` precise capturing syntax not allowed //[real]~^ ERROR `use<...>` precise capturing syntax not allowed

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
fn lt<'a>() -> impl Sized + use<'a, 'a> {} fn lt<'a>() -> impl Sized + use<'a, 'a> {}
//~^ ERROR cannot capture parameter `'a` twice //~^ ERROR cannot capture parameter `'a` twice

View File

@ -1,23 +1,23 @@
error: cannot capture parameter `'a` twice 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> {} LL | fn lt<'a>() -> impl Sized + use<'a, 'a> {}
| ^^ -- parameter captured again here | ^^ -- parameter captured again here
error: cannot capture parameter `T` twice 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> {} LL | fn ty<T>() -> impl Sized + use<T, T> {}
| ^ - parameter captured again here | ^ - parameter captured again here
error: cannot capture parameter `N` twice 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> {} LL | fn ct<const N: usize>() -> impl Sized + use<N, N> {}
| ^ - parameter captured again here | ^ - parameter captured again here
error: lifetime parameter `'a` must be listed before non-lifetime parameters 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> {} LL | fn ordering<'a, T>() -> impl Sized + use<T, 'a> {}
| - ^^ | - ^^

View File

@ -2,7 +2,7 @@
// Show that precise captures allow us to skip a lifetime param for outlives // 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> { } fn hello<'a: 'a, 'b: 'b>() -> impl Sized + use<'a> { }

View File

@ -1,7 +1,6 @@
//@ run-rustfix //@ run-rustfix
#![feature(precise_capturing)] #![allow(unused)]
#![allow(unused, incomplete_features)]
#![deny(impl_trait_overcaptures)] #![deny(impl_trait_overcaptures)]
fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x } fn named<'a>(x: &'a i32) -> impl Sized + use<> { *x }

View File

@ -1,7 +1,6 @@
//@ run-rustfix //@ run-rustfix
#![feature(precise_capturing)] #![allow(unused)]
#![allow(unused, incomplete_features)]
#![deny(impl_trait_overcaptures)] #![deny(impl_trait_overcaptures)]
fn named<'a>(x: &'a i32) -> impl Sized { *x } fn named<'a>(x: &'a i32) -> impl Sized { *x }

View File

@ -1,17 +1,17 @@
error: `impl Sized` will capture more lifetimes than possibly intended in edition 2024 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 } 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 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 } 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: all lifetimes in scope will be captured by `impl Trait`s in edition 2024
note: the lint level is defined here note: the lint level is defined here
--> $DIR/overcaptures-2024.rs:5:9 --> $DIR/overcaptures-2024.rs:4:9
| |
LL | #![deny(impl_trait_overcaptures)] 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 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 } LL | fn implicit(x: &i32) -> impl Sized { *x }
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
note: specifically, this lifetime is in scope but not mentioned in the type's bounds 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 } 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 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 } LL | fn hello(&self, x: &i32) -> impl Sized + '_ { self }
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
| |
note: specifically, this lifetime is in scope but not mentioned in the type's bounds 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 } 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 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> {} 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 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> {} LL | fn hrtb() -> impl for<'a> Higher<'a, Output = impl Sized> {}
| ^^ | ^^

View File

@ -1,5 +1,5 @@
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant 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> {} 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 = note: `#[warn(impl_trait_redundant_captures)]` on by default
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant 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<'_> {} LL | fn inherent(&self) -> impl Sized + use<'_> {}
| ^^^^^^^^^^^^^------- | ^^^^^^^^^^^^^-------

View File

@ -1,5 +1,5 @@
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits 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>; 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 = 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 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> {} LL | fn in_trait() -> impl Sized + use<'a> {}
| ^^^^^^^ | ^^^^^^^

View File

@ -2,8 +2,6 @@
//@ revisions: normal rpitit //@ revisions: normal rpitit
//@[normal] check-pass //@[normal] check-pass
#![feature(precise_capturing)]
fn hello<'a>() -> impl Sized + use<'a> {} fn hello<'a>() -> impl Sized + use<'a> {}
//[normal]~^ WARN all possible in-scope parameters are already captured //[normal]~^ WARN all possible in-scope parameters are already captured

View File

@ -5,8 +5,6 @@
// To fix this soundly, we need to make sure that all the trait header args // To fix this soundly, we need to make sure that all the trait header args
// remain captured, since they affect trait selection. // remain captured, since they affect trait selection.
#![feature(precise_capturing)]
trait Foo<'a> { trait Foo<'a> {
fn hello() -> impl PartialEq + use<Self>; fn hello() -> impl PartialEq + use<Self>;
} }

View File

@ -1,5 +1,5 @@
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits 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>; 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 = 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 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> { LL | trait Foo<'a> {
| -- this lifetime parameter is captured | -- 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` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait`
error: lifetime may not live long enough 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>>() { LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
| -- -- lifetime `'b` defined here | -- -- lifetime `'b` defined here
@ -30,7 +30,7 @@ LL | | );
= help: consider adding the following bound: `'a: 'b` = help: consider adding the following bound: `'a: 'b`
error: lifetime may not live long enough 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>>() { LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() {
| -- -- lifetime `'b` defined here | -- -- lifetime `'b` defined here

View File

@ -1,5 +1,3 @@
#![feature(precise_capturing)]
trait Foo { trait Foo {
fn bar<'a>() -> impl Sized + use<Self>; fn bar<'a>() -> impl Sized + use<Self>;
//~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits //~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits

View File

@ -1,5 +1,5 @@
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits 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>; LL | fn bar<'a>() -> impl Sized + use<Self>;
| ^^^^^^^^^ | ^^^^^^^^^