Skip to content

Commit eae5b5c

Browse files
Stabilize opaque type precise capturing
1 parent c6f81a4 commit eae5b5c

Some content is hidden

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

49 files changed

+70
-134
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
557557
gate_all!(fn_delegation, "functions delegation is not yet fully implemented");
558558
gate_all!(postfix_match, "postfix match is experimental");
559559
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
560-
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
561560
gate_all!(global_registration, "global registration is experimental");
562561
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
563562
gate_all!(return_type_notation, "return type notation is experimental");

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ declare_features! (
309309
(accepted, param_attrs, "1.39.0", Some(60406)),
310310
/// Allows parentheses in patterns.
311311
(accepted, pattern_parentheses, "1.31.0", Some(51087)),
312+
/// Allows `use<'a, 'b, A, B>` in `impl Trait + use<...>` for precise capture of generic args.
313+
(accepted, precise_capturing, "CURRENT_RUSTC_VERSION", Some(123432)),
312314
/// Allows procedural macros in `proc-macro` crates.
313315
(accepted, proc_macro, "1.29.0", Some(38356)),
314316
/// Allows multi-segment paths in attributes and derives.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ declare_features! (
561561
(unstable, patchable_function_entry, "1.81.0", Some(123115)),
562562
/// Allows postfix match `expr.match { ... }`
563563
(unstable, postfix_match, "1.79.0", Some(121618)),
564-
/// Allows `use<'a, 'b, A, B>` in `impl Trait + use<...>` for precise capture of generic args.
565-
(unstable, precise_capturing, "1.79.0", Some(123432)),
566564
/// Allows macro attributes on expressions, statements and non-inline modules.
567565
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
568566
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.

compiler/rustc_hir/src/hir.rs

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

compiler/rustc_lint/src/impl_trait_overcaptures.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ declare_lint! {
2727
/// ### Example
2828
///
2929
/// ```rust,compile_fail
30-
/// # #![feature(precise_capturing)]
31-
/// # #![allow(incomplete_features)]
3230
/// # #![deny(impl_trait_overcaptures)]
3331
/// # use std::fmt::Display;
3432
/// let mut x = vec![];
@@ -56,7 +54,6 @@ declare_lint! {
5654
pub IMPL_TRAIT_OVERCAPTURES,
5755
Allow,
5856
"`impl Trait` will capture more lifetimes than possibly intended in edition 2024",
59-
@feature_gate = precise_capturing;
6057
//@future_incompatible = FutureIncompatibleInfo {
6158
// reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
6259
// reference: "<FIXME>",
@@ -75,8 +72,7 @@ declare_lint! {
7572
/// ### Example
7673
///
7774
/// ```rust,compile_fail
78-
/// # #![feature(precise_capturing, lifetime_capture_rules_2024)]
79-
/// # #![allow(incomplete_features)]
75+
/// # #![feature(lifetime_capture_rules_2024)]
8076
/// # #![deny(impl_trait_redundant_captures)]
8177
/// fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x }
8278
/// ```
@@ -90,7 +86,6 @@ declare_lint! {
9086
pub IMPL_TRAIT_REDUNDANT_CAPTURES,
9187
Warn,
9288
"redundant precise-capturing `use<...>` syntax on an `impl Trait`",
93-
@feature_gate = precise_capturing;
9489
}
9590

9691
declare_lint_pass!(

compiler/rustc_parse/src/parser/ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ impl<'a> Parser<'a> {
851851
// lifetimes and ident params (including SelfUpper). These are validated later
852852
// for order, duplication, and whether they actually reference params.
853853
let use_span = self.prev_token.span;
854-
self.psess.gated_spans.gate(sym::precise_capturing, use_span);
855854
let (args, args_span) = self.parse_precise_capturing_args()?;
856855
GenericBound::Use(args, use_span.to(args_span))
857856
} else {

tests/rustdoc-json/impl-trait-precise-capturing.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(precise_capturing)]
2-
31
//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[0]" \"\'a\"
42
//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[1]" \"T\"
53
//@ is "$.index[*][?(@.name=='hello')].inner.function.decl.output.impl_trait[1].use[2]" \"N\"

tests/rustdoc/impl-trait-precise-capturing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ aux-build:precise-capturing.rs
22

33
#![crate_name = "foo"]
4-
#![feature(precise_capturing)]
54

65
extern crate precise_capturing;
76

tests/ui/feature-gates/feature-gate-precise-capturing.rs

-4
This file was deleted.

tests/ui/feature-gates/feature-gate-precise-capturing.stderr

-13
This file was deleted.

tests/ui/impl-trait/call_method_ambiguous.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/call_method_ambiguous.rs:28:13
2+
--> $DIR/call_method_ambiguous.rs:26:13
33
|
44
LL | let mut iter = foo(n - 1, m);
55
| ^^^^^^^^

tests/ui/impl-trait/call_method_ambiguous.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//@[next] compile-flags: -Znext-solver
33
//@[current] run-pass
44

5-
#![feature(precise_capturing)]
6-
75
trait Get {
86
fn get(&mut self) -> u32;
97
}

tests/ui/impl-trait/precise-capturing/apit.rs

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

tests/ui/impl-trait/precise-capturing/apit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `use<...>` precise capturing syntax not allowed in argument-position `impl Trait`
2-
--> $DIR/apit.rs:3:26
2+
--> $DIR/apit.rs:1:26
33
|
44
LL | fn hello(_: impl Sized + use<>) {}
55
| ^^^^^

tests/ui/impl-trait/precise-capturing/bad-lifetimes.rs

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

tests/ui/impl-trait/precise-capturing/bad-lifetimes.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0106]: missing lifetime specifier
2-
--> $DIR/bad-lifetimes.rs:3:39
2+
--> $DIR/bad-lifetimes.rs:1:39
33
|
44
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
55
| ^^ expected named lifetime parameter
@@ -11,21 +11,21 @@ LL | fn no_elided_lt() -> impl Sized + use<'static> {}
1111
| ~~~~~~~
1212

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

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

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

tests/ui/impl-trait/precise-capturing/bad-params.rs

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

tests/ui/impl-trait/precise-capturing/bad-params.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `T` in this scope
2-
--> $DIR/bad-params.rs:3:34
2+
--> $DIR/bad-params.rs:1:34
33
|
44
LL | fn missing() -> impl Sized + use<T> {}
55
| ^ not found in this scope
@@ -10,23 +10,23 @@ LL | fn missing<T>() -> impl Sized + use<T> {}
1010
| +++
1111

1212
error[E0411]: cannot find type `Self` in this scope
13-
--> $DIR/bad-params.rs:6:39
13+
--> $DIR/bad-params.rs:4:39
1414
|
1515
LL | fn missing_self() -> impl Sized + use<Self> {}
1616
| ------------ ^^^^ `Self` is only available in impls, traits, and type definitions
1717
| |
1818
| `Self` not allowed in a function
1919

2020
error: `Self` can't be captured in `use<...>` precise captures list, since it is an alias
21-
--> $DIR/bad-params.rs:11:48
21+
--> $DIR/bad-params.rs:9:48
2222
|
2323
LL | impl MyType {
2424
| ----------- `Self` is not a generic argument, but an alias to the type of the implementation
2525
LL | fn self_is_not_param() -> impl Sized + use<Self> {}
2626
| ^^^^
2727

2828
error: expected type or const parameter in `use<...>` precise captures list, found function
29-
--> $DIR/bad-params.rs:15:32
29+
--> $DIR/bad-params.rs:13:32
3030
|
3131
LL | fn hello() -> impl Sized + use<hello> {}
3232
| ^^^^^

tests/ui/impl-trait/precise-capturing/bound-modifiers.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ edition: 2021
22

3-
#![feature(precise_capturing)]
4-
53
fn polarity() -> impl Sized + ?use<> {}
64
//~^ ERROR expected identifier, found keyword `use`
75
//~| ERROR cannot find trait `r#use` in this scope

tests/ui/impl-trait/precise-capturing/bound-modifiers.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
error: expected identifier, found keyword `use`
2-
--> $DIR/bound-modifiers.rs:5:32
2+
--> $DIR/bound-modifiers.rs:3:32
33
|
44
LL | fn polarity() -> impl Sized + ?use<> {}
55
| ^^^ expected identifier, found keyword
66

77
error: expected identifier, found keyword `use`
8-
--> $DIR/bound-modifiers.rs:11:38
8+
--> $DIR/bound-modifiers.rs:9:38
99
|
1010
LL | fn asyncness() -> impl Sized + async use<> {}
1111
| ^^^ expected identifier, found keyword
1212

1313
error: expected identifier, found keyword `use`
14-
--> $DIR/bound-modifiers.rs:16:38
14+
--> $DIR/bound-modifiers.rs:14:38
1515
|
1616
LL | fn constness() -> impl Sized + const use<> {}
1717
| ^^^ expected identifier, found keyword
1818

1919
error: expected identifier, found keyword `use`
20-
--> $DIR/bound-modifiers.rs:21:37
20+
--> $DIR/bound-modifiers.rs:19:37
2121
|
2222
LL | fn binder() -> impl Sized + for<'a> use<> {}
2323
| ^^^ expected identifier, found keyword
2424

2525
error[E0405]: cannot find trait `r#use` in this scope
26-
--> $DIR/bound-modifiers.rs:5:32
26+
--> $DIR/bound-modifiers.rs:3:32
2727
|
2828
LL | fn polarity() -> impl Sized + ?use<> {}
2929
| ^^^ not found in this scope
3030

3131
error[E0405]: cannot find trait `r#use` in this scope
32-
--> $DIR/bound-modifiers.rs:11:38
32+
--> $DIR/bound-modifiers.rs:9:38
3333
|
3434
LL | fn asyncness() -> impl Sized + async use<> {}
3535
| ^^^ not found in this scope
3636

3737
error[E0405]: cannot find trait `r#use` in this scope
38-
--> $DIR/bound-modifiers.rs:16:38
38+
--> $DIR/bound-modifiers.rs:14:38
3939
|
4040
LL | fn constness() -> impl Sized + const use<> {}
4141
| ^^^ not found in this scope
4242

4343
error[E0405]: cannot find trait `r#use` in this scope
44-
--> $DIR/bound-modifiers.rs:21:37
44+
--> $DIR/bound-modifiers.rs:19:37
4545
|
4646
LL | fn binder() -> impl Sized + for<'a> use<> {}
4747
| ^^^ not found in this scope
4848

4949
error[E0658]: async closures are unstable
50-
--> $DIR/bound-modifiers.rs:11:32
50+
--> $DIR/bound-modifiers.rs:9:32
5151
|
5252
LL | fn asyncness() -> impl Sized + async use<> {}
5353
| ^^^^^
@@ -58,7 +58,7 @@ LL | fn asyncness() -> impl Sized + async use<> {}
5858
= help: to use an async block, remove the `||`: `async {`
5959

6060
error[E0658]: const trait impls are experimental
61-
--> $DIR/bound-modifiers.rs:16:32
61+
--> $DIR/bound-modifiers.rs:14:32
6262
|
6363
LL | fn constness() -> impl Sized + const use<> {}
6464
| ^^^^^
@@ -68,13 +68,13 @@ LL | fn constness() -> impl Sized + const use<> {}
6868
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6969

7070
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
71-
--> $DIR/bound-modifiers.rs:5:31
71+
--> $DIR/bound-modifiers.rs:3:31
7272
|
7373
LL | fn polarity() -> impl Sized + ?use<> {}
7474
| ^^^^^^
7575

7676
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
77-
--> $DIR/bound-modifiers.rs:5:31
77+
--> $DIR/bound-modifiers.rs:3:31
7878
|
7979
LL | fn polarity() -> impl Sized + ?use<> {}
8080
| ^^^^^^

tests/ui/impl-trait/precise-capturing/capture-parent-arg.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(precise_capturing)]
2-
31
trait Tr {
42
type Assoc;
53
}

tests/ui/impl-trait/precise-capturing/capture-parent-arg.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
2-
--> $DIR/capture-parent-arg.rs:27:31
2+
--> $DIR/capture-parent-arg.rs:25:31
33
|
44
LL | impl<'a> W<'a> {
55
| -- this lifetime parameter is captured
66
LL | fn bad1() -> impl Into<<W<'a> as Tr>::Assoc> + use<> {}
77
| -------------^^------------------------ lifetime captured due to being mentioned in the bounds of the `impl Trait`
88

99
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
10-
--> $DIR/capture-parent-arg.rs:33:18
10+
--> $DIR/capture-parent-arg.rs:31:18
1111
|
1212
LL | impl<'a> W<'a> {
1313
| -- this lifetime parameter is captured

tests/ui/impl-trait/precise-capturing/duplicated-use.real.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: duplicate `use<...>` precise capturing syntax
2-
--> $DIR/duplicated-use.rs:7:32
2+
--> $DIR/duplicated-use.rs:5:32
33
|
44
LL | fn hello<'a>() -> impl Sized + use<'a> + use<'a> {}
55
| ^^^^^^^ ------- second `use<...>` here

tests/ui/impl-trait/precise-capturing/duplicated-use.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ revisions: real pre_expansion
22
//@[pre_expansion] check-pass
33

4-
#![feature(precise_capturing)]
5-
64
#[cfg(real)]
75
fn hello<'a>() -> impl Sized + use<'a> + use<'a> {}
86
//[real]~^ ERROR duplicate `use<...>` precise capturing syntax
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
#![feature(precise_capturing)]
2-
31
fn dyn() -> &'static dyn use<> { &() }
42
//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`

tests/ui/impl-trait/precise-capturing/dyn-use.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
2-
--> $DIR/dyn-use.rs:3:26
2+
--> $DIR/dyn-use.rs:1:26
33
|
44
LL | fn dyn() -> &'static dyn use<> { &() }
55
| ^^^ expected one of `!`, `(`, `::`, `<`, `where`, or `{`
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(precise_capturing)]
4-
53
fn elided(x: &()) -> impl Sized + use<'_> { x }
64

75
fn main() {}

tests/ui/impl-trait/precise-capturing/forgot-to-capture-const.rs

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

tests/ui/impl-trait/precise-capturing/forgot-to-capture-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `impl Trait` must mention all const parameters in scope in `use<...>`
2-
--> $DIR/forgot-to-capture-const.rs:3:34
2+
--> $DIR/forgot-to-capture-const.rs:1:34
33
|
44
LL | fn constant<const C: usize>() -> impl Sized + use<> {}
55
| -------------- ^^^^^^^^^^^^^^^^^^

tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(precise_capturing)]
2-
31
fn lifetime_in_bounds<'a>(x: &'a ()) -> impl Into<&'a ()> + use<> { x }
42
//~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
53

0 commit comments

Comments
 (0)