Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Stabilize #![feature(precise_capturing_in_traits)] #138128

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ ast_lowering_never_pattern_with_guard =

ast_lowering_no_precise_captures_on_apit = `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`

ast_lowering_no_precise_captures_on_rpitit = `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
.note = currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope

ast_lowering_previously_used_here = previously used here

ast_lowering_register1 = register `{$reg1_name}`
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,6 @@ pub(crate) struct NoPreciseCapturesOnApit {
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_no_precise_captures_on_rpitit)]
#[note]
pub(crate) struct NoPreciseCapturesOnRpitit {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_yield_in_closure)]
pub(crate) struct YieldInClosure {
Expand Down
22 changes: 0 additions & 22 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1438,28 +1438,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// frequently opened issues show.
let opaque_ty_span = self.mark_span_with_reason(DesugaringKind::OpaqueTy, span, None);

// Feature gate for RPITIT + use<..>
match origin {
rustc_hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl: Some(_), .. } => {
if !self.tcx.features().precise_capturing_in_traits()
&& let Some(span) = bounds.iter().find_map(|bound| match *bound {
ast::GenericBound::Use(_, span) => Some(span),
_ => None,
})
{
let mut diag =
self.tcx.dcx().create_err(errors::NoPreciseCapturesOnRpitit { span });
add_feature_diagnostics(
&mut diag,
self.tcx.sess,
sym::precise_capturing_in_traits,
);
diag.emit();
}
}
_ => {}
}

self.lower_opaque_inner(opaque_ty_node_id, origin, opaque_ty_span, |this| {
this.lower_param_bounds(bounds, itctx)
})
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ declare_features! (
(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, "1.82.0", Some(123432)),
/// Allows `use<..>` precise capturign on impl Trait in traits.
(accepted, precise_capturing_in_traits, "CURRENT_RUSTC_VERSION", Some(130044)),
/// Allows procedural macros in `proc-macro` crates.
(accepted, proc_macro, "1.29.0", Some(38356)),
/// Allows multi-segment paths in attributes and derives.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,8 +600,6 @@ declare_features! (
(incomplete, pin_ergonomics, "1.83.0", Some(130494)),
/// Allows postfix match `expr.match { ... }`
(unstable, postfix_match, "1.79.0", Some(121618)),
/// Allows `use<..>` precise capturign on impl Trait in traits.
(unstable, precise_capturing_in_traits, "1.83.0", Some(130044)),
/// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
/// Allows the use of raw-dylibs on ELF platforms
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/impl-trait/in-trait/dump.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ compile-flags: -Zverbose-internals

#![feature(precise_capturing_in_traits, rustc_attrs)]
#![feature(rustc_attrs)]
#![rustc_hidden_type_of_opaques]

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

trait LifetimeParam<'a> {
fn test() -> impl Sized;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/impl-trait/in-trait/refine-captures.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: impl trait in impl method captures fewer lifetimes than in trait
--> $DIR/refine-captures.rs:8:31
--> $DIR/refine-captures.rs:6:31
|
LL | fn test() -> impl Sized + use<> {}
| ^^^^^
Expand All @@ -13,7 +13,7 @@ LL | fn test() -> impl Sized + use<'a> {}
| ++

warning: impl trait in impl method captures fewer lifetimes than in trait
--> $DIR/refine-captures.rs:22:31
--> $DIR/refine-captures.rs:20:31
|
LL | fn test() -> impl Sized + use<> {}
| ^^^^^
Expand All @@ -26,7 +26,7 @@ LL | fn test() -> impl Sized + use<'a> {}
| ++

warning: impl trait in impl method captures fewer lifetimes than in trait
--> $DIR/refine-captures.rs:27:31
--> $DIR/refine-captures.rs:25:31
|
LL | fn test() -> impl Sized + use<'b> {}
| ^^^^^^^
Expand All @@ -39,7 +39,7 @@ LL | fn test() -> impl Sized + use<'a, 'b> {}
| ++++

error: `impl Trait` must mention all type parameters in scope in `use<...>`
--> $DIR/refine-captures.rs:32:18
--> $DIR/refine-captures.rs:30:18
|
LL | impl<T> TypeParam<T> for u64 {
| - type parameter is implicitly captured by this `impl Trait`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/in-trait/variance.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(rustc_attrs, precise_capturing_in_traits)]
#![feature(rustc_attrs)]
#![allow(internal_features)]
#![rustc_variance_of_opaques]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing_in_traits)]

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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<> {}
| - ^^^^^^^^^^^^^^^^^^
Expand All @@ -9,7 +9,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`
Expand Down
1 change: 0 additions & 1 deletion tests/ui/impl-trait/precise-capturing/redundant.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ edition: 2024

#![feature(precise_capturing_in_traits)]
#![deny(impl_trait_redundant_captures)]

fn hello<'a>() -> impl Sized + use<'a> {}
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/impl-trait/precise-capturing/redundant.stderr
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:6:19
--> $DIR/redundant.rs:5:19
|
LL | fn hello<'a>() -> impl Sized + use<'a> {}
| ^^^^^^^^^^^^^-------
| |
| help: remove the `use<...>` syntax
|
note: the lint level is defined here
--> $DIR/redundant.rs:4:9
--> $DIR/redundant.rs:3:9
|
LL | #![deny(impl_trait_redundant_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:11:27
--> $DIR/redundant.rs:10:27
|
LL | fn inherent(&self) -> impl Sized + use<'_> {}
| ^^^^^^^^^^^^^-------
| |
| help: remove the `use<...>` syntax

error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:16:22
--> $DIR/redundant.rs:15:22
|
LL | fn in_trait() -> impl Sized + use<'a, Self>;
| ^^^^^^^^^^^^^-------------
| |
| help: remove the `use<...>` syntax

error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:20:22
--> $DIR/redundant.rs:19:22
|
LL | fn in_trait() -> impl Sized + use<'a> {}
| ^^^^^^^^^^^^^-------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// trait definition, which is not allowed. Due to the default lifetime capture
// rules of RPITITs, this is only doable if we use precise capturing.

#![feature(precise_capturing_in_traits)]

pub trait Foo {
fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: return type captures more lifetimes than trait definition
--> $DIR/rpitit-captures-more-method-lifetimes.rs:12:40
--> $DIR/rpitit-captures-more-method-lifetimes.rs:10:40
|
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + use<'im> {}
| --- ^^^^^^^^^^^^^^^^^^^^^
| |
| this lifetime was captured
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/rpitit-captures-more-method-lifetimes.rs:8:40
--> $DIR/rpitit-captures-more-method-lifetimes.rs:6:40
|
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing_in_traits)]

struct Invariant<'a>(&'a mut &'a mut ());

trait Trait {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: return type captures more lifetimes than trait definition
--> $DIR/rpitit-impl-captures-too-much.rs:10:39
--> $DIR/rpitit-impl-captures-too-much.rs:8:39
|
LL | fn hello(self_: Invariant<'_>) -> impl Sized + use<Self>;
| -- this lifetime was captured
Expand All @@ -8,7 +8,7 @@ LL | fn hello(self_: Invariant<'_>) -> impl Sized + use<'_> {}
| ^^^^^^^^^^^^^^^^^^^^
|
note: hidden type must only reference lifetimes captured by this impl trait
--> $DIR/rpitit-impl-captures-too-much.rs:6:39
--> $DIR/rpitit-impl-captures-too-much.rs:4:39
|
LL | fn hello(self_: Invariant<'_>) -> impl Sized + use<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/rpitit-outlives-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

// Ensure that we skip uncaptured args from RPITITs when comptuing outlives.

#![feature(precise_capturing_in_traits)]

struct Invariant<T>(*mut T);

trait Foo {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/rpitit-outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// Ensure that we skip uncaptured args from RPITITs when collecting the regions
// to enforce member constraints in opaque type inference.

#![feature(precise_capturing_in_traits)]

struct Invariant<T>(*mut T);

trait Foo {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/rpitit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,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_in_traits)]

fn eq_types<T>(_: T, _: T) {}

trait TraitLt<'a: 'a> {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/impl-trait/precise-capturing/rpitit.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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 TraitLt<'a: 'a> {
| -- all lifetime parameters originating from a trait are captured implicitly
LL | fn hello() -> impl Sized + use<Self>;
| ^^^^^^^^^^^^^^^^^^^^^^

error: lifetime may not live long enough
--> $DIR/rpitit.rs:15:5
--> $DIR/rpitit.rs:13:5
|
LL | fn trait_lt<'a, 'b, T: for<'r> TraitLt<'r>> () {
| -- -- lifetime `'b` defined here
Expand All @@ -24,7 +24,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 trait_lt<'a, 'b, T: for<'r> TraitLt<'r>> () {
| -- -- lifetime `'b` defined here
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/self-capture.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(precise_capturing_in_traits)]

trait Foo {
fn bar<'a>() -> impl Sized + use<Self>;
}
Expand Down
Loading