forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#124029 - compiler-errors:rpitit-variances, r=…
…<try> Give RPITITs variances, so they can (not) capture lifetimes This is needed for edition 2021 and the `precise_captures` feature, so we can specify that we *don't* want to capture a lifetime implicitly for an RPITIT. I'll elaborate this further and try to motivate its soundness once perf comes back. r? `@ghost`
- Loading branch information
Showing
8 changed files
with
96 additions
and
2 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
15 changes: 15 additions & 0 deletions
15
tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.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,15 @@ | ||
#![feature(precise_capturing)] | ||
//~^ WARN the feature `precise_capturing` is incomplete | ||
|
||
struct Invariant<'a>(&'a mut &'a mut ()); | ||
|
||
trait Trait { | ||
fn hello(self_: Invariant<'_>) -> impl use<Self> Sized; | ||
} | ||
|
||
impl Trait for () { | ||
fn hello(self_: Invariant<'_>) -> impl use<'_> Sized {} | ||
//~^ return type captures more lifetimes than trait definition | ||
} | ||
|
||
fn main() {} |
26 changes: 26 additions & 0 deletions
26
tests/ui/impl-trait/precise-capturing/rpitit-impl-captures-too-much.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,26 @@ | ||
warning: the feature `precise_capturing` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/rpitit-impl-captures-too-much.rs:1:12 | ||
| | ||
LL | #![feature(precise_capturing)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/rpitit-impl-captures-too-much.rs:11:39 | ||
| | ||
LL | fn hello(self_: Invariant<'_>) -> impl use<'_> Sized {} | ||
| -- ^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| this lifetime was captured | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/rpitit-impl-captures-too-much.rs:7:39 | ||
| | ||
LL | fn hello(self_: Invariant<'_>) -> impl use<Self> Sized; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Sized` | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
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,17 @@ | ||
//@ check-pass | ||
|
||
#![feature(precise_capturing)] | ||
//~^ WARN the feature `precise_capturing` is incomplete | ||
|
||
struct Invariant<'a>(&'a mut &'a mut ()); | ||
|
||
trait Trait { | ||
fn hello(self_: Invariant<'_>) -> impl use<Self> Sized; | ||
} | ||
|
||
fn eq<'a, 'b, T: Trait>(x: Invariant<'a>, y: Invariant<'b>) { | ||
let mut out = T::hello(x); | ||
out = T::hello(y); | ||
} | ||
|
||
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,11 @@ | ||
warning: the feature `precise_capturing` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/rpitit.rs:3:12 | ||
| | ||
LL | #![feature(precise_capturing)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|