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#126746 - compiler-errors:no-rpitit, r=oli-obk
Deny `use<>` for RPITITs Precise capturing `use<>` syntax is currently a no-op on RPITITs, since GATs have no variance, so all captured lifetimes are captured invariantly. We don't currently *need* to support `use<>` on RPITITs, since `use<>` is initially intended for migrating RPIT *overcaptures* from edition 2021->2024, but since RPITITs currently capture all in-scope lifetimes, we'll never need to write `use<>` on an RPITIT. Eventually, though, it would be desirable to support precise capturing on RPITITs, since RPITITs overcapturing by default can be annoying to some folks. But let's separate that (which will likely require some delicate types team work for adding variances to GATs and adjusting the refinement rules) from the stabilization of the feature for edition 2024. r? oli-obk cc `@traviscross` Tracking: - rust-lang#123432
- Loading branch information
Showing
13 changed files
with
169 additions
and
44 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
20 changes: 20 additions & 0 deletions
20
tests/ui/impl-trait/precise-capturing/redundant.normal.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,20 @@ | ||
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant | ||
--> $DIR/redundant.rs:7:19 | ||
| | ||
LL | fn hello<'a>() -> impl Sized + use<'a> {} | ||
| ^^^^^^^^^^^^^------- | ||
| | | ||
| help: remove the `use<...>` syntax | ||
| | ||
= note: `#[warn(impl_trait_redundant_captures)]` on by default | ||
|
||
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant | ||
--> $DIR/redundant.rs:12:27 | ||
| | ||
LL | fn inherent(&self) -> impl Sized + use<'_> {} | ||
| ^^^^^^^^^^^^^------- | ||
| | | ||
| help: remove the `use<...>` syntax | ||
|
||
warning: 2 warnings emitted | ||
|
18 changes: 18 additions & 0 deletions
18
tests/ui/impl-trait/precise-capturing/redundant.rpitit.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,18 @@ | ||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
--> $DIR/redundant.rs:18:35 | ||
| | ||
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 | ||
|
||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
--> $DIR/redundant.rs:23:35 | ||
| | ||
LL | fn in_trait() -> impl Sized + use<'a> {} | ||
| ^^^^^^^ | ||
| | ||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope | ||
|
||
error: aborting due to 2 previous errors | ||
|
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,24 +1,27 @@ | ||
//@ compile-flags: -Zunstable-options --edition=2024 | ||
//@ check-pass | ||
//@ revisions: normal rpitit | ||
//@[normal] check-pass | ||
|
||
#![feature(precise_capturing)] | ||
|
||
fn hello<'a>() -> impl Sized + use<'a> {} | ||
//~^ WARN all possible in-scope parameters are already captured | ||
//[normal]~^ WARN all possible in-scope parameters are already captured | ||
|
||
struct Inherent; | ||
impl Inherent { | ||
fn inherent(&self) -> impl Sized + use<'_> {} | ||
//~^ WARN all possible in-scope parameters are already captured | ||
//[normal]~^ WARN all possible in-scope parameters are already captured | ||
} | ||
|
||
#[cfg(rpitit)] | ||
trait Test<'a> { | ||
fn in_trait() -> impl Sized + use<'a, Self>; | ||
//~^ WARN all possible in-scope parameters are already captured | ||
//[rpitit]~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
} | ||
#[cfg(rpitit)] | ||
impl<'a> Test<'a> for () { | ||
fn in_trait() -> impl Sized + use<'a> {} | ||
//~^ WARN all possible in-scope parameters are already captured | ||
//[rpitit]~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
} | ||
|
||
fn main() {} |
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
//@ known-bug: unknown | ||
|
||
// RPITITs don't have variances in their GATs, so they always relate invariantly | ||
// and act as if they capture all their args. | ||
// 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)] | ||
|
||
trait Foo<'a> { | ||
fn hello() -> impl PartialEq + use<Self>; | ||
} | ||
|
||
fn test<'a, 'b, T: for<'r> Foo<'r>>() { | ||
PartialEq::eq( | ||
&<T as Foo<'a>>::hello(), | ||
&<T as Foo<'b>>::hello(), | ||
); | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
--> $DIR/rpitit.rs:11:36 | ||
| | ||
LL | fn hello() -> impl PartialEq + use<Self>; | ||
| ^^^^^^^^^ | ||
| | ||
= 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 | ||
--> $DIR/rpitit.rs:11:19 | ||
| | ||
LL | trait Foo<'a> { | ||
| -- this lifetime parameter is captured | ||
LL | fn hello() -> impl PartialEq + use<Self>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime captured due to being mentioned in the bounds of the `impl Trait` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/rpitit.rs:15:5 | ||
| | ||
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | / PartialEq::eq( | ||
LL | | &<T as Foo<'a>>::hello(), | ||
LL | | &<T as Foo<'b>>::hello(), | ||
LL | | ); | ||
| |_____^ argument requires that `'a` must outlive `'b` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/rpitit.rs:15:5 | ||
| | ||
LL | fn test<'a, 'b, T: for<'r> Foo<'r>>() { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | / PartialEq::eq( | ||
LL | | &<T as Foo<'a>>::hello(), | ||
LL | | &<T as Foo<'b>>::hello(), | ||
LL | | ); | ||
| |_____^ argument requires that `'b` must outlive `'a` | ||
| | ||
= help: consider adding the following bound: `'b: 'a` | ||
|
||
help: `'a` and `'b` must be the same: replace one with the other | ||
|
||
error: aborting due to 4 previous errors | ||
|
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,9 +1,8 @@ | ||
//@ check-pass | ||
|
||
#![feature(precise_capturing)] | ||
|
||
trait Foo { | ||
fn bar<'a>() -> impl Sized + use<Self>; | ||
//~^ 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
--> $DIR/self-capture.rs:4:34 | ||
| | ||
LL | fn bar<'a>() -> impl Sized + use<Self>; | ||
| ^^^^^^^^^ | ||
| | ||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope | ||
|
||
error: aborting due to 1 previous error | ||
|