Skip to content

Commit

Permalink
Stabilize opaque type precise capturing
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 17, 2024
1 parent c6f81a4 commit eae5b5c
Show file tree
Hide file tree
Showing 49 changed files with 70 additions and 134 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(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!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
gate_all!(return_type_notation, "return type notation is experimental");
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ declare_features! (
(accepted, param_attrs, "1.39.0", Some(60406)),
/// Allows parentheses in patterns.
(accepted, pattern_parentheses, "1.31.0", Some(51087)),
/// Allows `use<'a, 'b, A, B>` in `impl Trait + use<...>` for precise capture of generic args.
(accepted, precise_capturing, "CURRENT_RUSTC_VERSION", Some(123432)),
/// Allows procedural macros in `proc-macro` crates.
(accepted, proc_macro, "1.29.0", Some(38356)),
/// Allows multi-segment paths in attributes and derives.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,6 @@ declare_features! (
(unstable, patchable_function_entry, "1.81.0", Some(123115)),
/// Allows postfix match `expr.match { ... }`
(unstable, postfix_match, "1.79.0", Some(121618)),
/// Allows `use<'a, 'b, A, B>` in `impl Trait + use<...>` for precise capture of generic args.
(unstable, precise_capturing, "1.79.0", Some(123432)),
/// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,6 @@ impl PreciseCapturingArg<'_> {
/// resolution to. Lifetimes don't have this problem, and for them, it's actually
/// kind of detrimental to use a custom node type versus just using [`Lifetime`],
/// since resolve_bound_vars operates on `Lifetime`s.
// FIXME(precise_capturing): Investigate storing this as a path instead?
#[derive(Debug, Clone, Copy, HashStable_Generic)]
pub struct PreciseCapturingNonLifetimeArg {
pub hir_id: HirId,
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_lint/src/impl_trait_overcaptures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(precise_capturing)]
/// # #![allow(incomplete_features)]
/// # #![deny(impl_trait_overcaptures)]
/// # use std::fmt::Display;
/// let mut x = vec![];
Expand Down Expand Up @@ -56,7 +54,6 @@ declare_lint! {
pub IMPL_TRAIT_OVERCAPTURES,
Allow,
"`impl Trait` will capture more lifetimes than possibly intended in edition 2024",
@feature_gate = precise_capturing;
//@future_incompatible = FutureIncompatibleInfo {
// reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
// reference: "<FIXME>",
Expand All @@ -75,8 +72,7 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// # #![feature(precise_capturing, lifetime_capture_rules_2024)]
/// # #![allow(incomplete_features)]
/// # #![feature(lifetime_capture_rules_2024)]
/// # #![deny(impl_trait_redundant_captures)]
/// fn test<'a>(x: &'a i32) -> impl Sized + use<'a> { x }
/// ```
Expand All @@ -90,7 +86,6 @@ declare_lint! {
pub IMPL_TRAIT_REDUNDANT_CAPTURES,
Warn,
"redundant precise-capturing `use<...>` syntax on an `impl Trait`",
@feature_gate = precise_capturing;
}

declare_lint_pass!(
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ impl<'a> Parser<'a> {
// lifetimes and ident params (including SelfUpper). These are validated later
// for order, duplication, and whether they actually reference params.
let use_span = self.prev_token.span;
self.psess.gated_spans.gate(sym::precise_capturing, use_span);
let (args, args_span) = self.parse_precise_capturing_args()?;
GenericBound::Use(args, use_span.to(args_span))
} else {
Expand Down
2 changes: 0 additions & 2 deletions tests/rustdoc-json/impl-trait-precise-capturing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

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

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

extern crate precise_capturing;

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

This file was deleted.

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

This file was deleted.

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

#![feature(precise_capturing)]

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

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

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

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

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

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

error: expected lifetime parameter in `use<...>` precise captures list, found `'static`
--> $DIR/bad-lifetimes.rs:7:36
--> $DIR/bad-lifetimes.rs:5:36
|
LL | fn static_lt() -> impl Sized + use<'static> {}
| ^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/bad-params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

fn missing() -> impl Sized + use<T> {}
//~^ ERROR cannot find type `T` in this scope

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/impl-trait/precise-capturing/bad-params.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,23 +10,23 @@ 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
| |
| `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
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> {}
| ^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/bound-modifiers.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/impl-trait/precise-capturing/bound-modifiers.stderr
Original file line number Diff line number Diff line change
@@ -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<> {}
| ^^^^^
Expand All @@ -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<> {}
| ^^^^^
Expand All @@ -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<> {}
| ^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/capture-parent-arg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

trait Tr {
type Assoc;
}
Expand Down
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/capture-parent-arg.rs:27:31
--> $DIR/capture-parent-arg.rs:25:31
|
LL | impl<'a> W<'a> {
| -- this lifetime parameter is captured
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/duplicated-use.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/dyn-use.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#![feature(precise_capturing)]

fn dyn() -> &'static dyn use<> { &() }
//~^ ERROR expected one of `!`, `(`, `::`, `<`, `where`, or `{`, found keyword `use`
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/precise-capturing/dyn-use.stderr
Original file line number Diff line number Diff line change
@@ -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 `{`
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/precise-capturing/elided.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(precise_capturing)]

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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<> {}
| -------------- ^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading

0 comments on commit eae5b5c

Please sign in to comment.