<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dw="https://www.dreamwidth.org">
  <id>tag:dreamwidth.org,2016-12-27:2634070</id>
  <title>Dmitry Popov</title>
  <subtitle>Dmitry Popov</subtitle>
  <author>
    <name>Dmitry Popov</name>
  </author>
  <link rel="alternate" type="text/html" href="https://thedeemon.dreamwidth.org/"/>
  <link rel="self" type="text/xml" href="https://thedeemon.dreamwidth.org/data/atom"/>
  <updated>2019-09-12T10:22:35Z</updated>
  <dw:journal username="thedeemon" type="personal"/>
  <entry>
    <id>tag:dreamwidth.org,2016-12-27:2634070:134543</id>
    <link rel="alternate" type="text/html" href="https://thedeemon.dreamwidth.org/134543.html"/>
    <link rel="self" type="text/xml" href="https://thedeemon.dreamwidth.org/data/atom/?itemid=134543"/>
    <title>о гарантиях</title>
    <published>2019-09-12T10:18:10Z</published>
    <updated>2019-09-12T10:22:35Z</updated>
    <category term="rust"/>
    <dw:security>public</dw:security>
    <dw:reply-count>6</dw:reply-count>
    <content type="html">&lt;pre&gt;
fn helper&amp;lt;'a, 'b, T&amp;gt;(_: &amp;'a &amp;'b (), v: &amp;'b T) -&amp;gt; &amp;'a T { v }

/// Turn any `&amp;T` into a `&amp;'static T`. May introduce undefined behavior.
pub fn make_static&amp;lt;'a, T&amp;gt;(input: &amp;'a T) -&amp;gt; &amp;'static T {
    let f: fn(_, &amp;'a T) -&amp;gt; &amp;'static T = helper;
    f(&amp;&amp;(), input)
}
&lt;/pre&gt;&lt;br /&gt;(&lt;a href="https://github.com/NieDzejkob/fake-static"&gt;отсюда&lt;/a&gt;)&lt;br /&gt;Не ожидал, что так просто. Безо всякого unsafe берем и превращаем "одолженную" ссылку на временное значение в "вечную", с соответствующими use-after-free последствиями. А просто дырка в borrow checker'e, и давно уже, все никак не залатают.&lt;br /&gt;&lt;br /&gt;&lt;img src="https://www.dreamwidth.org/tools/commentcount?user=thedeemon&amp;ditemid=134543" width="30" height="12" alt="comment count unavailable" style="vertical-align: middle;"/&gt; comments</content>
  </entry>
</feed>
