diff options
| author | Michael Goulet <michael@errs.io> | 2023-09-22 18:45:53 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-09-22 18:55:44 +0000 |
| commit | b5a904a9d450c2afbefcc0c95974f3396e73d487 (patch) | |
| tree | bcc9b02384ee11f0f2582a0ece95453b68cf65f7 /tests/ui/impl-trait | |
| parent | 0fd7ce99b0508aff7f7a2c639871de4e8080e3f8 (diff) | |
| download | rust-b5a904a9d450c2afbefcc0c95974f3396e73d487.tar.gz rust-b5a904a9d450c2afbefcc0c95974f3396e73d487.zip | |
Use placeholders to prevent using inferred RPITIT types to imply their own WF-ness
Diffstat (limited to 'tests/ui/impl-trait')
| -rw-r--r-- | tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.rs | 23 | ||||
| -rw-r--r-- | tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.stderr | 16 |
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.rs b/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.rs new file mode 100644 index 00000000000..c1885af4e5e --- /dev/null +++ b/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.rs @@ -0,0 +1,23 @@ +#![feature(return_position_impl_trait_in_trait)] + +trait Extend { + fn extend(_: &str) -> (impl Sized + '_, &'static str); +} + +impl Extend for () { + fn extend(s: &str) -> (Option<&'static &'_ ()>, &'static str) { + //~^ ERROR in type `&'static &()`, reference has a longer lifetime than the data it references + (None, s) + } +} + +// This indirection is not necessary for reproduction, +// but it makes this test future-proof against #114936. +fn extend<T: Extend>(s: &str) -> &'static str { + <T as Extend>::extend(s).1 +} + +fn main() { + let use_after_free = extend::<()>(&String::from("temporary")); + println!("{}", use_after_free); +} diff --git a/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.stderr b/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.stderr new file mode 100644 index 00000000000..7b63e72acbf --- /dev/null +++ b/tests/ui/impl-trait/in-trait/rpitit-hidden-types-self-implied-wf.stderr @@ -0,0 +1,16 @@ +error[E0491]: in type `&'static &()`, reference has a longer lifetime than the data it references + --> $DIR/rpitit-hidden-types-self-implied-wf.rs:8:27 + | +LL | fn extend(s: &str) -> (Option<&'static &'_ ()>, &'static str) { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the pointer is valid for the static lifetime +note: but the referenced data is only valid for the anonymous lifetime defined here + --> $DIR/rpitit-hidden-types-self-implied-wf.rs:8:18 + | +LL | fn extend(s: &str) -> (Option<&'static &'_ ()>, &'static str) { + | ^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0491`. |
