forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#131033 - compiler-errors:precise-capturing-…
…in-traits, r=spastorino Precise capturing in traits This PR begins to implement `feature(precise_capturing_in_traits)`, which enables using the `impl Trait + use<..>` syntax for RPITITs. It implements this by giving the desugared GATs variance, and representing the uncaptured lifetimes as bivariant, like how opaque captures work. Right now, I've left out implementing a necessary extension to the `refining_impl_trait` lint, and also I've made it so that all RPITITs always capture the parameters that come from the trait, because I'm not totally yet convinced that it's sound to not capture these args. It's certainly required to capture the type and const parameters from the trait (e.g. Self), or else users could bivariantly relate two RPITIT args that come from different impls, but region parameters don't affect trait selection in the same way, so it *may* be possible to relax this in the future. Let's stay conservative for now, though. I'm not totally sure what tests could be added on top of the ones I already added, since we really don't need to exercise the `precise_capturing` feature but simply what makes it special for RPITITs. r? types Tracking issue: * rust-lang#130044
- Loading branch information
Showing
30 changed files
with
309 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
trait Foo { | ||
fn test() -> impl Sized + use<Self>; | ||
//~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position | ||
} | ||
|
||
fn main() {} |
13 changes: 13 additions & 0 deletions
13
tests/ui/feature-gates/feature-gate-precise_capturing_in_traits.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
--> $DIR/feature-gate-precise_capturing_in_traits.rs:2:31 | ||
| | ||
LL | fn test() -> impl Sized + use<Self>; | ||
| ^^^^^^^^^ | ||
| | ||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope | ||
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information | ||
= help: add `#![feature(precise_capturing_in_traits)]` 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
#![feature(rustc_attrs)] | ||
#![feature(rustc_attrs, precise_capturing_in_traits)] | ||
#![allow(internal_features)] | ||
#![rustc_variance_of_opaques] | ||
|
||
trait Captures<'a> {} | ||
impl<T> Captures<'_> for T {} | ||
|
||
trait Foo<'i> { | ||
fn implicit_capture_early<'a: 'a>() -> impl Sized {} | ||
//~^ [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] | ||
//~^ [Self: o, 'i: o, 'a: *, 'a: o, 'i: o] | ||
|
||
fn explicit_capture_early<'a: 'a>() -> impl Sized + use<'i, 'a, Self> {} | ||
//~^ [Self: o, 'i: o, 'a: *, 'i: o, 'a: o] | ||
|
||
fn explicit_capture_early<'a: 'a>() -> impl Sized + Captures<'a> {} | ||
//~^ [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] | ||
fn not_captured_early<'a: 'a>() -> impl Sized + use<'i, Self> {} | ||
//~^ [Self: o, 'i: o, 'a: *, 'i: o] | ||
|
||
fn implicit_capture_late<'a>(_: &'a ()) -> impl Sized {} | ||
//~^ [Self: o, 'i: *, 'a: o, 'i: o] | ||
//~^ [Self: o, 'i: o, 'a: o, 'i: o] | ||
|
||
fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + use<'i, 'a, Self> {} | ||
//~^ [Self: o, 'i: o, 'i: o, 'a: o] | ||
|
||
fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} | ||
//~^ [Self: o, 'i: *, 'a: o, 'i: o] | ||
fn not_cpatured_late<'a>(_: &'a ()) -> impl Sized + use<'i, Self> {} | ||
//~^ [Self: o, 'i: o, 'i: o] | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
error: [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] | ||
--> $DIR/variance.rs:9:44 | ||
error: [Self: o, 'i: o, 'a: *, 'a: o, 'i: o] | ||
--> $DIR/variance.rs:6:44 | ||
| | ||
LL | fn implicit_capture_early<'a: 'a>() -> impl Sized {} | ||
| ^^^^^^^^^^ | ||
|
||
error: [Self: o, 'i: *, 'a: *, 'a: o, 'i: o] | ||
--> $DIR/variance.rs:12:44 | ||
error: [Self: o, 'i: o, 'a: *, 'i: o, 'a: o] | ||
--> $DIR/variance.rs:9:44 | ||
| | ||
LL | fn explicit_capture_early<'a: 'a>() -> impl Sized + use<'i, 'a, Self> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: [Self: o, 'i: o, 'a: *, 'i: o] | ||
--> $DIR/variance.rs:12:40 | ||
| | ||
LL | fn explicit_capture_early<'a: 'a>() -> impl Sized + Captures<'a> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | fn not_captured_early<'a: 'a>() -> impl Sized + use<'i, Self> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: [Self: o, 'i: *, 'a: o, 'i: o] | ||
error: [Self: o, 'i: o, 'a: o, 'i: o] | ||
--> $DIR/variance.rs:15:48 | ||
| | ||
LL | fn implicit_capture_late<'a>(_: &'a ()) -> impl Sized {} | ||
| ^^^^^^^^^^ | ||
|
||
error: [Self: o, 'i: *, 'a: o, 'i: o] | ||
error: [Self: o, 'i: o, 'i: o, 'a: o] | ||
--> $DIR/variance.rs:18:48 | ||
| | ||
LL | fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + Captures<'a> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | fn explicit_capture_late<'a>(_: &'a ()) -> impl Sized + use<'i, 'a, Self> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: [Self: o, 'i: o, 'i: o] | ||
--> $DIR/variance.rs:21:44 | ||
| | ||
LL | fn not_cpatured_late<'a>(_: &'a ()) -> impl Sized + use<'i, Self> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
error: aborting due to 6 previous errors | ||
|
3 changes: 2 additions & 1 deletion
3
tests/ui/impl-trait/precise-capturing/forgot-to-capture-type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
#![feature(precise_capturing_in_traits)] | ||
|
||
fn type_param<T>() -> impl Sized + use<> {} | ||
//~^ ERROR `impl Trait` must mention all type parameters in scope | ||
|
||
trait Foo { | ||
fn bar() -> impl Sized + use<>; | ||
//~^ ERROR `impl Trait` must mention the `Self` type of the trait | ||
//~| ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.