We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
*const Trait<'a>
*const Trait<'b>
1 parent 3141b78 commit f3de343Copy full SHA for f3de343
tests/ui/cast/ptr-to-trait-obj-different-regions.rs
@@ -0,0 +1,31 @@
1
+// check-pass
2
+//
3
+// issue: <https://github.com/rust-lang/rust/issues/120217>
4
+
5
+#![feature(arbitrary_self_types)]
6
7
+trait Static<'a> {
8
+ fn proof(self: *const Self, s: &'a str) -> &'static str;
9
+}
10
11
+fn bad_cast<'a>(x: *const dyn Static<'static>) -> *const dyn Static<'a> {
12
+ x as _
13
14
15
+impl Static<'static> for () {
16
+ fn proof(self: *const Self, s: &'static str) -> &'static str {
17
+ s
18
+ }
19
20
21
+fn extend_lifetime(s: &str) -> &'static str {
22
+ bad_cast(&()).proof(s)
23
24
25
+fn main() {
26
+ let s = String::from("Hello World");
27
+ let slice = extend_lifetime(&s);
28
+ println!("Now it exists: {slice}");
29
+ drop(s);
30
+ println!("Now it’s gone: {slice}");
31
0 commit comments