<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by GeekyTwoShoes on Medium]]></title>
        <description><![CDATA[Stories by GeekyTwoShoes on Medium]]></description>
        <link>https://medium.com/@geekytwoshoes11?source=rss-b95b1485da29------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*JwmLnxe9Vx9btanrffZN9w.jpeg</url>
            <title>Stories by GeekyTwoShoes on Medium</title>
            <link>https://medium.com/@geekytwoshoes11?source=rss-b95b1485da29------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:16:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@geekytwoshoes11/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reader’s Block is a thing!]]></title>
            <link>https://medium.com/life-tips/readers-block-is-a-thing-df4a6bd42bb2?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/df4a6bd42bb2</guid>
            <category><![CDATA[beyourself]]></category>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[books]]></category>
            <category><![CDATA[reading]]></category>
            <category><![CDATA[lessons-learned]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 14:18:48 GMT</pubDate>
            <atom:updated>2018-03-17T07:13:38.562Z</atom:updated>
            <content:encoded><![CDATA[<p>My struggle with Reader’s Block and what it taught me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tVy3RiMhD5Sjyz2y-vm1ZA.jpeg" /></figure><p>When I was 6, my aunt gifted me a Panchatantra book (childhood stories). I was delighted. I’ve never looked back since.</p><p>When I was 11, I was introduced to the wizarding world of J.K. Rowling. So what if I never made it to Hogwarts! What followed were Twilight, Percy Jackson, The Long Walk to Freedom and a long list of books.</p><p>When I was 14, I finished off a chapter on Anne Frank from the textbook, even before our English class resumed. I got a copy of the book from the library and finished it. I secretly wished that I could be as natural a writer as her.</p><p>On joining high school, I rushed to get a copy of Breaking Dawn from the library on day one. Oh Thank God for the library! Once, I stayed overnight to finish Angels and Demons too. Ah the memories!</p><p>When I was 18, Paulo Coelho became my favorite writer after reading Brida. Surprisingly though, I could never finish The Witch of Portobello. “Maybe it’s the coursework”, I consoled myself.</p><p>When I was 19, I didn’t read beyond a few pages of Life of Pi, only because my friend shared a negative review. I had got a perfect excuse to not read it.</p><p>Post 19, I experimented with semi-autobiographies and post colonial literature (as a part of my coursework). The God of Small Things, The Inheritance of Loss, Wise and Otherwise and what not. Despite this, my reading speed had decreased. I stopped enjoying reading too. I would skip lines and paragraphs, forget past references in the story and sometimes, hardly focus on what I was reading. I would go to the library, issue books and never read them. Reader’s block is a thing 😞. The mad rush to build careers, the rat race and the coursework left me with no time to read.</p><p>“Reading”, I proudly answered when someone asked my hobby. Little did they know I was referring to course books, developer and software blogs and tutorials.</p><p>Lucky for me, I was soon blessed with a relatively free semester and I made it a point to start reading again. Sudha Murty, Paulo Coelho, Arundhati Roy and many more. Frequent library visits . Since then, nothing much has changed. My hectic day has some time reserved for reading. I had survived Reader’s Block.</p><blockquote>When you have a hobby, don’t give up on it. Like all the good things in life, hobbies are hard to find and even harder to keep. Reading has become more fun after the dry phase. Reading will always be a constant.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df4a6bd42bb2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/life-tips/readers-block-is-a-thing-df4a6bd42bb2">Reader’s Block is a thing!</a> was originally published in <a href="https://medium.com/life-tips">Be Yourself</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rust, Lints and me : The Why❔]]></title>
            <link>https://medium.com/@geekytwoshoes11/rust-lints-and-me-the-why-4a02b20472eb?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a02b20472eb</guid>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[pull-request]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Mon, 11 Dec 2017 17:37:40 GMT</pubDate>
            <atom:updated>2017-12-11T17:37:40.796Z</atom:updated>
            <content:encoded><![CDATA[<p>A to Z on writing a lint against single-use lifetime names in Rust.</p><p>We start with a simple example.</p><pre><strong>fn deref&lt;&#39;x&gt;(v: &amp;&#39;x u32) -&gt; u32 {</strong><br>    *v<br>}<br><br>fn main() { }</pre><p><strong>Step 1.</strong></p><p>Consider the lifetime &#39;x . It is only used <strong>once throughout. </strong>What we are trying to achieve is a lint that warns that &#39;x is being used only once. So, you can do away with the lifetime binding &#39;x and proceed ahead as follows.</p><pre><strong>fn deref(v: &amp;u32) -&gt; u32 {</strong><br>    *v<br>}<br><br>fn main() { }</pre><p>Current Progress</p><pre>warning: lifetime name `&#39;x` only used once<br>  --&gt; $DIR/single_use_lifetimes.rs:12:10<br>   |<br>12 | fn deref&lt;&#39;x&gt;(v: &amp;&#39;x u32) -&gt; u32 {<br>   |          ^^<br>   |<br>note: lint level defined here<br>  --&gt; $DIR/single_use_lifetimes.rs:10:9<br>   |<br>10 | <strong>#![warn(single_use_lifetime)]</strong><br>   |         ^^^^^^^^^^^^^^^^^^^</pre><p><strong>Step 2.</strong></p><p>Looking at a bit more complex examples involving structs like the one below.</p><pre>struct Foo&lt;&#39;a, &#39;b&gt; { <br>    f: &amp;&#39;a u32<br>    g: &amp;&#39;b u32<br>}</pre><pre>fn foo&lt;&#39;x, &#39;y&gt;(foo: Foo&lt;&#39;x, <strong>&#39;y</strong>&gt;) -&gt; &amp;&#39;x u32 {<br>    foo.f <br>}</pre><p>This will produce a lint against &#39;y and suggest a replacement of &#39;y with an <strong>_ .</strong></p><pre>fn foo&lt;&#39;x, &#39;y&gt;(foo: Foo&lt;&#39;x, <strong>&#39;y</strong>&gt;) -&gt; &amp;&#39;x u32 {<br>                             ^^ lifetime name `&#39;y` only used once. Use `_` instead.</pre><pre>   foo.f <br>}</pre><h3>Why?</h3><p>Firstly, using _ instead of lifetime names makes it easier to deal with compulsory lifetime declarations in the code. It also makes sure that you don’t need to worry about repeating lifetimes names throughout.</p><p>Secondly, this change is a part of the <a href="https://github.com/rust-lang/rfcs/pull/2115"><strong>RFC</strong></a> on<strong> In-band lifetime bindings</strong>. The idea is <strong>to eliminate the need for separately binding lifetime parameters in </strong><strong>fn definitions and </strong><strong>impl headers</strong>. Let’s take a look at the example below.</p><pre>fn outer_lifetime&lt;&#39;outer&gt;(arg: &amp;&#39;outer &amp;Foo) -&gt; &amp;&#39;outer Bar</pre><p>If &#39;outer is the only lifetime in use here, you might as well do this.</p><pre>fn outer_lifetime(arg: &amp;&#39;outer &amp;Foo) -&gt; &amp;&#39;outer Bar</pre><p>Quoting <a href="https://medium.com/u/5ab461cc28d4">Niko Matsakis</a> from the PR description on the Github repo</p><blockquote>An explicit name like &#39;a should only be used (at least in a function or impl) to <em>link together</em> two things. Otherwise, you should just use &#39;_ to indicate that the lifetime is not linked to anything.</blockquote><p>The next article will explain about the code in detail. Till then, adiós!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a02b20472eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python for newbies by newbies]]></title>
            <link>https://medium.com/series/python-for-newbies-by-newbies-55ac44a7683f?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/55ac44a7683f</guid>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Sat, 04 Nov 2017 15:16:16 GMT</pubDate>
            <atom:updated>2017-11-04T15:17:43.160Z</atom:updated>
            <content:encoded><![CDATA[<p>A mini series wherein I write about some of the things I find cool about Python and some of the common mistakes I have made while coding and how to do it better :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55ac44a7683f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Once a Rustacean, always a Rustacean.]]></title>
            <link>https://medium.com/@geekytwoshoes11/once-a-rustacean-always-a-rustacean-fed0a877472f?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/fed0a877472f</guid>
            <category><![CDATA[outreachy]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[mozilla]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Tue, 29 Aug 2017 04:55:23 GMT</pubDate>
            <atom:updated>2017-12-23T06:51:58.788Z</atom:updated>
            <content:encoded><![CDATA[<p>This story tracks the beginning of my journey with <a href="https://medium.com/u/95f4ec6ae6f6">Mozilla</a>, where I worked on making error messages for lifetime conflicts user-friendly and simple but precise for the Rust Programming Language.</p><p>The first time I showed interest in making a contribution to Rust, my mentor <a href="https://medium.com/u/e90d951b9220">Niko Matsakis</a> scheduled a video chat with me and explained to me about the project which titled was making an <strong>Unsafe code linting tool for Rust. </strong>He then presented a few code snippets to help me understand where the problem lay and drew similarities with C++, since I was new to Rust then. As much as I was nervous, I loved the idea of developing the unsafe linting tool. Then we went on to discuss how I should proceed with my first contribution and we zeroed in on <strong>Rayon</strong>, a parallel data library for Rust.</p><p>My first contribution was this</p><p><a href="https://github.com/nikomatsakis/rayon/pull/264">add test that drives the collect-consumer, producing too less values by gaurikholkar · Pull Request #264 · nikomatsakis/rayon</a></p><p>The reason we went ahead with Rayon was because the linting tool would be tested with Rayon, as it had a huge amount of unsafe code. I wrote unit tests for the collect consumer, closing an existing issue —</p><p><a href="https://github.com/nikomatsakis/rayon/issues/53">Negative tests abusing the consumer protocol · Issue #53 · nikomatsakis/rayon</a></p><p>and successively made my second contribution too</p><p><a href="https://github.com/nikomatsakis/rayon/pull/269">Adding tests for failing to call complete, produce fewer,more items incase of splitting. by gaurikholkar · Pull Request #269 · nikomatsakis/rayon</a></p><p>The happiness you feel when you make your very first PR issue is 💓</p><p>This helped me understand how the collect consumer worked and I got to see examples of unsafe code.</p><p>Going ahead, my mentor searched for beginner level issues, keeping in mind that the more I get used to Rust, the better and decided that I should fix issues in the Rust Compiler itself. My first reaction must have been 😯 as I was quite new to open source and my first impression of making a contribution to the compiler itself meant something difficult.</p><blockquote>I remember discussing with a friend that Rust is my first open source Contribution and she was like you’re very lucky ☺</blockquote><p>I’ve heard of contribution stories going wrong. Not that it ever mattered but I’ve felt so loved by the community that I’m really grateful for the experience.</p><p>On the rust compiler, I was to work with the region inferencing part of the compiler and the first issue was to fix an existing error message.</p><p><a href="https://github.com/rust-lang/rust/issues/40402">issue on let suggestions</a></p><p>and the PR link for the same.</p><p><a href="https://github.com/rust-lang/rust/pull/41564">Disable ref hint for pattern in let and adding ui tests #40402 by gaurikholkar · Pull Request #41564 · rust-lang/rust</a></p><p>I then worked on the same issue, introducing another change in the error message</p><p><a href="https://github.com/rust-lang/rust/pull/41640">Consider changing to &amp; for let bindings #40402 by gaurikholkar · Pull Request #41640 · rust-lang/rust</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RguBQOrt_C8FUjIEOkBoIQ.png" /></figure><p>Now came the time when I had to build the compiler locally, running ./x.py build — — incremental and ./x.py test src/test/ui constantly, often having my share of struggles with the borrow checker, but nothing short of a learning experience. I followed the mentoring instructions written by my mentor and wrote my first few lines of proper Rust code. Over time, I’ve grown fond of the build commands :p.</p><p>I remember talking to <a href="https://medium.com/u/e90d951b9220">Niko Matsakis</a> and he suggested picking up the harder of the two issues that I was planning to work on and that decision helped me throughout the internship. It familiarized me with building the compiler, running the test suite and running the compiler locally on different examples to see how the code change was reflecting from the user perspective. So when later, he proposed the idea of working on lifetime errors instead of the linting tool, I took an instant liking to it. The major reason he explained was that this would have more of an impact in less amount of time. The second important reason was that I would get to explore a part of the compiler very few apart from the team are familiar with i.e. the region inferencing part. Then based on the feedback, we will be further modifying the errors more( sounds fun?). The linter would be somewhat on the lines of Clippy. The lifetime error work would be something different. As easy as it may sound, designing the message itself needed effort. You have to be simple yet precise. That’s difficult. It’s difficult when you probably want to explain everything in paragraphs so that the user experience is better but then you need to be careful too, as you shouldn’t give them too much information that they understand nothing out of it. The challenge was to think as a user. A code of hundred plus lines and what that did was just change the error message for a few cases. This is how the project title changed.</p><p>I started off a bit early, the excitement was too difficult to contain :p and there was plenty of free time. We looked at a few common examples and tried to understand how lifetimes work. Then he walked me through a bit of the error reporting code, pointing out functions being used and the types of parameters being passed and other important declarations. We picked up the simplest example, discussing it’s features in depth and then figuring out all the cases it covered.</p><p>What I was to deal with was anonymous lifetimes i.e. missing lifetime parameters. Lifetimes or regions, being among the few things that confused the Rust users, we safely assumed that if it was missing the lifetime declarations in the function or trait declarations unlike the fault being in the code itself.</p><p>That’s how we started. A new error message for functions with one named parameter and one anonymous parameter. E0621. There is a systematic procedure you follow for the same. Once you fix the error message, you need to run the test suite. You also need to add an explanation in the diagnostics.rs file which is like registering the error code. You also need to add new ui tests (show the output) and compile-fail tests. Now it might sound simple but it wasn’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6uO3T57OTHcCg8jP-FWBgQ.png" /></figure><p>I had to understand the way Rust Compiler defines an error, to be specific, RegionResolution Errors. I had to understand the report_region_errors() method. I have limited myself to working with only ConcreteFailure errors throughout. My <a href="https://medium.com/@geekytwoshoes11/e0611-why-what-and-how-9fa427a5a650">first blog post</a> speaks about it. <a href="https://medium.com/@geekytwoshoes11/e0621-traits-and-impls-23fdea3ee85c">This post</a> speaks on how we planned to extend it for traits and impls, keeping it on hold for anonymous regions in self and return type. The most challenging part here was to replace the anonymous region with the named region here</p><p>consider changing the type of `y` to `&amp;’a i32`</p><p>I did it using TypeFolders.</p><p>Here is the merged PR</p><p>https://github.com/rust-lang/rust/pull/42669</p><p>Talking of merges, the happiness when your code gets merged with the master branch is amazing : dancer</p><p>Moving on from there, I went a few steps ahead, trying to handle conflicts where both the regions are anonymous or what we call the anon_anon conflict. It was more difficult here, there were too many cases and error design itself kept changing due to the feedback we got.</p><p>Here is the link to the PR for handling it in references.</p><p>https://github.com/rust-lang/rust/pull/43298</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0OyWjiU0mmL6Qd3-S6jkQ.png" /></figure><p>The error message was later changed as follows</p><p>https://github.com/rust-lang/rust/pull/43541</p><p>Later, I extended it to Structs.</p><p>https://github.com/rust-lang/rust/pull/43700</p><p>The code needed a lot of testing as a few cases were breaking. The code reviews emphasised on the need to write cleaner code.</p><p>Currently, I’m having ongoing PRs which are to extend E0623 to <a href="https://github.com/rust-lang/rust/pull/44079">named conflicts</a>(blog on this later) <strong>and</strong> also to cover <a href="https://github.com/rust-lang/rust/pull/44124">return types and self.</a></p><p>I’ve planned so much on how to write this post, because there is too much to write . I doubt I will do justice to it but here is my effort. Working with Rust is like the introductory hello world program for me. It’s my first exploration of open source and community contribution. It’s immense growth and love. It’s learning and satisfaction of giving back to a community that’s given you love.</p><p>I’ve got the opportunity to work with a language compiler and learn the language, understand it better via contributions. Usually that’s something that works the other way around. <em>You learn the language before you go around digging into the compiler. I’ve had the opportunity to make error messages better for Rust users, of something that I had initial struggles with i.e. the lifetime errors.</em> I’ve got to be the consumer and the producer both. My initial hesitation on learning a new language is now replaced with a curiosity to learn more about Rust every single day.</p><p>A huge thank you to Outreachy for organizing this amazing programme and to <a href="https://www.twitter.com/sarahsharp">Sarah Sharp</a> and all the other outreachy admins. A big thank you to <a href="https://medium.com/u/95f4ec6ae6f6">Mozilla</a> , Elizabeth Noonan and <a href="https://medium.com/u/749cadc4fc1f">Larissa Shapiro</a> for making this possible ☺. <strong><em>Thank you </em></strong><a href="https://medium.com/u/e90d951b9220"><strong><em>Niko Matsakis</em></strong></a><strong><em> for being the most amazing mentor anyone could have ever asked for, right from being available to answer my silliest doubts on let and if let to helping out with understanding, writing code and reviewing it, and having an example ready on almost every topic I had doubts with, these three months have been fun to work with you and I’m sure I’m going to continue to be in touch ☺.</em></strong><em> </em>I’ve been fortunate enough to have got to interact with a few of the Rust core team members, <a href="https://medium.com/u/e90d951b9220">Niko Matsakis</a> , a huge thank you to <a href="https://github.com/arielb1">Ariel Ben-Yehuda</a> (Rust Compiler Team) and <a href="https://github.com/estebank">Esteban Kuber</a> for reviewing my code and being ever ready to help, <a href="https://github.com/eddyb">Eduard-Mihai Burtescu</a> (Rust Compiler Team) for being a regular at answering my queries on IRC and <a href="https://github.com/GuillaumeGomez">Guillaume Gomez</a> and J<a href="https://github.com/jonathandturner">onathan Turner</a>(Dev tools team) for their reviews and comments. Last but not the least, thank you Gitter : 💓. For reasons unexplainable, I’ve preferred Gitter more over Slack and IRC.</p><h3>What I’ve learned ?</h3><h3>Deep dive, no first impressions.</h3><p>How much ever difficult something looks, you can’t really gauge the level of difficulty until you get your hands real dirty with the code and try to experiment a bit. Logs helped me do that, to understand where I was going wrong and what the code was doing. So leap of faith.</p><h3>Patience</h3><p>There are days when you feel like productivity seems to be a far away dream. I’ve felt sad looking at a build fail when I know it’s supposed to work fine, I’ve spent my initial days staring at a GitHub pull request, searching for the green tick that often eluded me at the start ( stopped doing that now ;) ) and felt gloomy. Take a short break. A walk maybe. Come back afresh to realize it’s something silly and get it working. The joy that came with it was much more than what would have been if I got it right the first time. I’ve learnt to be patient with my code.</p><h3>Learn</h3><p>Even while I was coding , I kept the side process of learning Rust on too. I’ve been fascinated by what all the language has. Compilers was a course in my third year. It was one of my favorites. The assigned needed us to build a mini compiler for a small subset of C. It was something that interested me then. Never did I think that I would be contributing to a language compiler used by a huge community.</p><h3>Growth</h3><p>It’s being a huge learning opportunity for me. I have grown as a programmer and developer. I’ve become more confident and more efficient. Most importantly, I’ve found happiness in what I do. Immense satisfaction of contributing to a growing community.</p><h3>Small is big</h3><p>The smallest bug fix has got me back to pondering over programming fundamentals and deeper into advanced concepts.</p><h3>Confidence</h3><p>I’ve become pretty fluent in communicating with the other contributors, asking questions when blocked on something, opening up relevant issues on GitHub and trying to be precise with my doubts.</p><h3>Be better.</h3><p>A better programmer. A better computer science student. A better learner. A better developer. A better person. Fortunately, working remotely wasn’t much of a problem for me.</p><h3>Communicate, Ask.</h3><p>When I asked my mentor if there was a faster way to build stage 1 of the compiler, he suggested using ./x.py build --stage 1 src/libsyntax. Earlier I was building the stage 0 redundantly with the ./x.py build --incremental. Often I’ve asked for help to understand certain concepts and he has given me helpful resources and pointers. This has often made me more efficient and saved a lot of my time.</p><h3><strong>Spread the spirit</strong></h3><p>I’ve been lucky to get a chance to explain my work to a fellow contributor eager to work on one of the issues I opened up and I’ve been blogging regularly to spread the spirit ☺</p><h3>First times</h3><p>I’ve opened up my first pull request, my first issue, my first community code review and my first technical blog written during this period. There’s always a first time.</p><p>Moral : <em>Rust is love</em></p><p><strong>Thank you for being the awesome community that you are @rustlang.</strong></p><p>This has been one amazing journey, <strong><em>a journey that’s not going to end so soon ☺</em></strong></p><p>Thanks for being a part of my journey. For any queries and suggestions, leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fed0a877472f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Rewind: E0611]]></title>
            <link>https://medium.com/@geekytwoshoes11/the-rewind-e0611-bc29850c7f7e?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc29850c7f7e</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 18:20:48 GMT</pubDate>
            <atom:updated>2017-08-14T18:20:48.236Z</atom:updated>
            <content:encoded><![CDATA[<p>Updates to the error code E0611 which handles named and anonymous conflicts w.r.t lifetime errors</p><p>In my last <a href="https://medium.com/@geekytwoshoes11/e0621-traits-and-impls-23fdea3ee85c">post</a> on E0611 , I talked about the purpose behind the error code and the coding process. This post will talk about how the error message has been modified from</p><pre><strong>error[E0611]: explicit lifetime required in the type of `x`</strong><br>11 | fn foo&lt;&#39;a&gt;(x: &amp;i32, y: &amp;&#39;a i32) -&gt; &amp;&#39;a i32 {<br>   |                     <strong>^ consider changing the type of `x` to `&amp;&#39;a i32`</strong><br>12 |     if x &gt; y { x } else { y }<br>   |                  <strong>- lifetime `&#39;a` required</strong></pre><p>to something like this.</p><pre><strong>error[E0621]: explicit lifetime required in the type of `x`</strong><br>   |<br>11 | fn foo&lt;&#39;a&gt;(x: &amp;i32, y: &amp;&#39;a i32) -&gt; &amp;&#39;a i32 {<br>   |               <strong>---- consider changing the type of `x` to `&amp;&#39;a i32`</strong><br>12 |     if x &gt; y { x } else { y }<br>   |                <strong>^ lifetime `&#39;a` required</strong></pre><h4>How did this come about?</h4><p>When E0623 was designed about, the hir::Ty corresponding to the argument was highlighted using span_labels instead of the argument itself( what we are doing here).</p><pre>error[E0623]: lifetime mismatch<br>  --&gt; $DIR/ex3-both-anon-regions.rs:12:12<br>   |<br>11 | fn foo(x: &amp;mut Vec&lt;&amp;u8&gt;, y: &amp;u8) {<br>   |                    <strong>---      --- </strong>these references must have the same lifetime<br>12 |     x.push(y);<br>   |            ^ data from `y` flows into `x` here<br><br>error: aborting due to 2 previous errors</pre><h4>Coding it</h4><p>This was an easy task as previous code was just being reused.</p><pre>let span_label = if let Some(ty_anon) = <strong>self.find_anon_type(anon, &amp;br)</strong> {<br>                <strong>ty_anon.span // what we are concerned with</strong><br>            } else {<br>                arg.pat.span<br>            };</pre><p>End result is a more precise error message.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc29850c7f7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A day spent debugging]]></title>
            <link>https://medium.com/@geekytwoshoes11/a-day-spent-debugging-a84ef08c5733?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/a84ef08c5733</guid>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Sat, 12 Aug 2017 13:45:21 GMT</pubDate>
            <atom:updated>2017-08-13T12:23:36.250Z</atom:updated>
            <content:encoded><![CDATA[<p>This snippet of code made me think and then overthink 😧. Though when I did figure out what was going wrong, there was a smug smile on my face 👼. It’s difficult not to lose your head in such times but this time, I felt like a brave warrior 💪 , contradictory to the fallen warrior-like feeling when I debug erros.</p><pre>struct Foo {</pre><pre>field: i32,</pre><pre>}</pre><pre>impl Foo {</pre><pre>fn foo&lt;&#39;a&gt;(&amp;self, x: &amp;Foo) -&gt; &amp;Foo {</pre><pre>if true { x } else { self }</pre><pre>}</pre><pre>}</pre><p>I have already written code to incorporate structs in EO623 and the ui tests seemed to be working fine. But the below snippet failed.</p><ol><li>It did not give the E0623 error message ( expected).</li><li>The logs showed that the find_anon_type() was returning false(???). Much to my surprise, similar testcases worked for other similar ui tests 😕. That called for a *debug mode*.</li></ol><pre>pub fn <strong>try_report_anon_anon_conflict</strong>(&amp;self, error: &amp;RegionResolutionError&lt;&#39;tcx&gt;) -&gt; bool {<br>     let (ty1, ty2, scope_def_id_1, scope_def_id_2, bregion1, bregion2) = if<br>            self.is_suitable_anonymous_region_for_anon_anon(sup)<br>                .is_some() &amp;&amp;<br>            self.is_suitable_anonymous_region_for_anon_anon(sub)<br>                .is_some() {<br>            if let (Some(anon_reg1), Some(anon_reg2)) =<br>                (self.is_suitable_anonymous_region_for_anon_anon(sup),<br>                 self.is_suitable_anonymous_region_for_anon_anon(sub)) {<br>                let ((def_id1, br1), (def_id2, br2)) = (anon_reg1, anon_reg2);<br>                let found_arg1 = <strong>self.find_anon_type</strong>(sup, &amp;br1);<br>                let found_arg2 = <strong>self.find_anon_type</strong>(sub, &amp;br2);<br>                match (found_arg1, found_arg2) {<br>                    (Some(anonarg_1), Some(anonarg_2)) =&gt; {<br>                        (anonarg_1, anonarg_2, def_id1, def_id2, br1, br2)<br>                    }<br>                    _ =&gt; {<br>                        <strong>return false;</strong><br>                    }</pre><p>I examined the code for find_anon_type() and well, I examined it after writing a few debug! statements here and there to figure out the flow.</p><pre><strong>if let hir_map::NodeItem(it) = self.tcx.hir.get(node_id) {</strong><br>                        <strong>if let hir::ItemFn(ref fndecl, _, _, _, _, _) = it.node {</strong><br>                            return fndecl<br>                                       .inputs<br>                                       .iter()<br>                                       .filter_map(|arg| {<br>                                let mut nested_visitor = FindNestedTypeVisitor {<br>                                    infcx: &amp;self,<br>                                    hir_map: &amp;self.tcx.hir,<br>                                    bound_region: *br,<br>                                    found_type: None,<br>                                };<br>                                nested_visitor.visit_ty(&amp;**arg);<br>                                nested_visitor.found_type<br>                            })<br>                                       .next();<br>                        }</pre><p>NodeItem() does not cover impl items and traits. My initial thought was that my examples are wrong. Examining this part of the code suddenly made the problem clear to me.</p><p>This is how I changed it.</p><pre>else if let <strong>hir_map::NodeImplItem(it) = self.tcx.hir.get(node_id) {</strong><br>                        if let hir::ImplItemKind::Method(ref fndecl, _) = it.node {<br>                            return fndecl<br>                                       .decl<br>                                       .inputs<br>                                       .iter()<br>                                       .filter_map(|arg| {<br>                                let mut nested_visitor = FindNestedTypeVisitor {<br>                                    infcx: &amp;self,<br>                                    hir_map: &amp;self.tcx.hir,<br>                                    bound_region: *br,<br>                                    found_type: None,<br>                                };<br>                                nested_visitor.visit_ty(&amp;**arg);<br>                                nested_visitor.found_type<br>                            })<br>                                       .next();</pre><p>Similarly I added a NodeTraitItem too. Now the example works fine 😊. There’s a minor shortcoming though. The below example now generates E0621 despite the fact that the disable of the error message on traits and impls ( yet to figure out what’s happening there).</p><pre>trait Foo {</pre><pre>   fn foo&lt;&#39;a&gt;(x: &amp;i32, y: &amp;&#39;a i32) -&gt; &amp;&#39;a i32;</pre><pre>}</pre><pre>impl Foo for () {</pre><pre>   fn foo&lt;&#39;a&gt;(x: &amp;i32, y: &amp;&#39;a i32) -&gt; &amp;&#39;a i32 {</pre><pre>     if x &gt; y { x } else { y }</pre><pre>}</pre><p>And well, the day continues 💻</p><p>EDIT: The other issue is fixed. Turned out I had changed the function to not return a None for that case.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a84ef08c5733" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[E0623 and anonymous regions in structs]]></title>
            <link>https://medium.com/@geekytwoshoes11/e0623-and-anonymous-regions-in-structs-5dba4b434e43?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/5dba4b434e43</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[rustlang]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Fri, 11 Aug 2017 07:47:10 GMT</pubDate>
            <atom:updated>2017-08-11T07:47:10.409Z</atom:updated>
            <content:encoded><![CDATA[<p>The error code E0623 handles lifetime errors where <strong><em>both the regions are anonymous</em></strong>. The article talks about how a new error code E0624 was avoided when it came to handling structs, what I had initially started off with and what the end result was — a generalized message for anon_anon conflicts, emphasizing on code re-usability as well as simplicity when it comes to end users.</p><p>Let us extend E0623further in the case of <strong><em>structs</em></strong>.</p><p>Let’s start with an example.</p><pre>struct <strong>Ref</strong>&lt;&#39;a&gt; {<br>   x: &amp;&#39;a u32,<br>}</pre><pre>fn foo(mut x: Vec&lt;<strong>Ref</strong>&gt;, y: <strong>Ref</strong>) {<br>   x.push(y);<br>}</pre><p>And here is the final error message.</p><pre>error[<strong>E0623</strong>]: lifetime mismatch<br>  --&gt; $DIR/ex3-both-anon-regions-both-are-structs.rs:15:12<br>   |<br>14 | fn foo(mut x: Vec&lt;Ref&gt;, y: Ref) {<br>   |                   <strong>---      --- these two types are declared </strong>with different lifetimes...<br>15 |     x.push(y);<br>   |            ^ <strong>...but data from `y` flows into `x` here</strong></pre><pre>error: aborting due to previous error</pre><h4>Design the error message.</h4><p>The initial design was as follows and hence, we were planning to make a new error code corresponding to only *structs*.</p><p>Let’s recap how E0623 looks like.</p><pre>|<br>11 | fn foo(x: &amp;mut Vec&lt;&amp;u8&gt;, y: &amp;u8) {<br>   |                    ---      --- <strong>these two references are declared with different lifetimes...</strong><br>12 |     x.push(y);<br>   |            ^ ...<strong>but data from `y` flows into `x` here</strong><br><br>error: aborting due to previous error</pre><p>So here is how we started off — Design I</p><pre>struct Ref&lt;&#39;a, &#39;b&gt; { a: &amp;&#39;a u32, b: &amp;&#39;b u32 }</pre><pre>fn foo(mut x: Ref, y: &amp;u32) {</pre><pre>              ---     - lifetime parameter must match</pre><pre>              2nd lifetime parameter on `Ref` must match</pre><pre>       x.b = y;</pre><pre>}</pre><p>We wanted the error message to provide sufficient info to the user about the error and how to tackle it but it dawned on us that our efforts to create a perfect error message might not be well received by the end users as it would look like *too much information* and maybe E0623 — — explain could serve the purpose. Considering the fact that it might overwhelm the users with too much of information and the need to create a new error code, we decided to do something like this — Design II</p><pre>+error[E0624]: lifetime mismatch<br>+  --&gt; $DIR/ex3-both-anon-regions-both-are-structs.rs:15:12<br>+   |<br>+14 | fn foo(mut x: Vec&lt;Ref&gt;, y: Ref) {<br>+   |                   ---      --- this struct and reference are declared with different lifetimes...<br>+15 |     x.push(y);<br>+   |            ^ ...but data from `y` flows into `x` here<br>+<br>+error: aborting due to previous error</pre><p>This made sure that expanding E0623 to handle the case would suffice. The final aim was to make a generalized error message ( neither too verbose nor too short) and so we decided to combine it with the existing error message of E0623 — Design III</p><pre>+error[E0624]: lifetime mismatch<br>+  --&gt; $DIR/ex3-both-anon-regions-both-are-structs.rs:15:12<br>+   |<br>+14 | fn foo(mut x: Vec&lt;Ref&gt;, y: Ref) {<br>+   |                   ---      --- these types are declared with different lifetimes...<br>+15 |     x.push(y);<br>+   |            ^ ...but data from `y` flows into `x` here<br>+<br>+error: aborting due to previous error</pre><h4>Coding it…</h4><p>This step took me more time than usual, making me give a thought to time management, maybe because somewhere down, I got lost along the flow. But when it did work, there was this feeling of elation 💃.</p><p>Earlier, we were dealing with only references, in the compiler language, it was hir::TyRptr . Similarly, for structs, it is the <a href="https://github.com/rust-lang/rust/blob/f85579d4a2c342654f9b158fafd565eb159fdb59/src/librustc/hir/mod.rs#L1351">hir::TyPath</a>(QPath) . Now, whatever the QPath is, it doesn’t matter much to us.</p><pre>// Corresponds to the <a href="https://github.com/rust-lang/rust/blob/f7bd1b69621c7813a38f464ff109e9ec1fc937c8/src/librustc/infer/error_reporting/anon_anon_conflict.rs#L190">NestedTypeVisitor</a> we use to walk the<br>// anonymous types for e.g. `Vec&lt;&amp;u8&gt;`<br>fn visit_ty(&amp;mut self, arg: &amp;&#39;gcx hir::Ty) {<br>    match arg.node {<br>            hir::TyRptr(ref lifetime, _) =&gt; {...}<br>            // Checks if it is of type `hir::TyPath` which corresponds to a struct.<br>            <strong>hir::TyPath</strong>(_) =&gt; {...}</pre><p>What do we do once we find the hir::TyPath(_) ?</p><pre>            hir::TyPath(_) =&gt; {<br>                let mut subvisitor = &amp;mut <strong>TyPathVisitor</strong> {<br>                                              infcx: self.infcx,<br>                                              found_it: false,<br>                                              bound_region: self.bound_region,<br>                                              hir_map: self.hir_map,<br>                                          };<br>                <strong>intravisit::walk_ty(subvisitor, arg)</strong>; // call walk_ty; as visit_ty is empty,<br>                // this will visit only outermost type<br>                if subvisitor.found_it {<br>                    <strong>self.is_struct = true;</strong><br>                    self.found_type = Some(arg);<br>                } <br>            }</pre><p>Since `walk_ty` visited only the outermost type, I made a call to intravisit::walk_ty(self, arg) where self corresponds to FindNestedTypeVisitor , to recursively search for innermost types ( a mistake I made in one of my earlier commits was to not include this, about which I will talk in a later post)</p><p>What is a TyPathVisitor ?</p><pre>// The visitor captures the corresponding `hir::Ty` of the anonymous // region in the case of structs ie. `hir::TyPath`.<br>// This visitor would be invoked for each lifetime corresponding to // a struct, and would walk the types like Vec&lt;Ref&gt; in the above     example and Ref looking for the HIR<br>// where that lifetime appears. This allows us to highlight the<br>// specific part of the type in the error message.</pre><pre>struct <strong>TyPathVisitor</strong>&lt;&#39;a, &#39;gcx: &#39;a + &#39;tcx, &#39;tcx: &#39;a&gt; {<br>    infcx: &amp;&#39;a InferCtxt&lt;&#39;a, &#39;gcx, &#39;tcx&gt;,<br>    hir_map: &amp;&#39;a hir::map::Map&lt;&#39;gcx&gt;,<br>    found_it: bool,<br>    bound_region: ty::BoundRegion,<br>}</pre><p>And a few minor changes to FindNestedTypeVisitor i.e. adding a new field is_struct .</p><pre>// Indicates if the argument corresponds to a struct.<br>    is_struct: bool,</pre><p>A call to <strong>intravisit::</strong><a href="https://github.com/rust-lang/rust/blob/d84693b93dae3958e3504f817face0184c5c3fdd/src/librustc/hir/intravisit.rs#L543"><strong>walk_ty(subvisitor, arg)</strong></a><strong> </strong>makes calls to various other default visitor functions and somewhere in the sequence lies visit_lifetimes() , which we override as follows.</p><pre>let br_index = match self.bound_region {<br>            ty::BrAnon(index) =&gt; index,<br>            _ =&gt; return,<br>        };<br><br><br>        match <strong>self.infcx.tcx.named_region_map.defs.get(&amp;lifetime.id)</strong> {<br>            Some(&amp;rl::Region::LateBoundAnon(debuijn_index, anon_index)) =&gt; {<br>                if debuijn_index.depth == 1 &amp;&amp; anon_index == br_index {<br>                    <strong>self.found_it = true;</strong><br>                }<br>            }<br>            Some(&amp;rl::Region::Static) |<br>            Some(&amp;rl::Region::EarlyBound(_, _)) |<br>            Some(&amp;rl::Region::LateBound(_, _)) |<br>            Some(&amp;rl::Region::Free(_, _)) |<br>            None =&gt; {<br>                debug!(&quot;no arg found&quot;);<br>            }<br>        }</pre><p>The next few steps are the same as the ones to detect references.</p><pre>if subvisitor.found_it {<br>                    self.is_struct = true; // it is a struct<br>                    self.found_type = Some(arg);<br>                } </pre><p>Now comes the part where we print the error message. I wrote a function process_anon_anon_conflict() which decides what to print in the error message based on the struct and reference combinations — refer <strong>Design II</strong></p><pre>// try to pre-process the errors, for the purpose of generating different<br>    // span labels for the different combinations of the two parameters which can be<br>    // either references or structs.<br>    fn process_anon_anon_conflict(&amp;self,<br>                               is_arg1_struct: bool,<br>                               is_arg2_struct: bool)<br>                               -&gt; Option&lt;(String)&gt; {<br>        let arg1_label = {<br>            if is_arg1_struct &amp;&amp; is_arg2_struct {<br>                format!(&quot;these structs&quot;)<br>            } else if is_arg1_struct &amp;&amp; !is_arg2_struct {<br>                format!(&quot;the struct and reference&quot;)<br>            } else if !is_arg1_struct &amp;&amp; is_arg2_struct {<br>                format!(&quot;the reference and the struct&quot;)<br>            } else {<br>                format!(&quot;these references&quot;)<br>            }<br>        };<br>        Some(arg1_label)<br>    }</pre><p>The decision was made to generalize the error message.</p><p>The is_struct field in the FindNestedTypeVisitor was no longer necessary. Similar was the case with process_anon_anon_conflicts() . The error generating code now looked like this.</p><pre>let span_label_var1 = if let Some(simple_name) = anon_arg1.pat.simple_name() {<br>                    format!(&quot; from `{}`&quot;, simple_name)<br>                } else {<br>                    format!(&quot;&quot;)<br>                };<br><br>                let span_label_var2 = if let Some(simple_name) = anon_arg2.pat.simple_name() {<br>                    format!(&quot; into `{}`&quot;, simple_name)<br>                } else {<br>                    format!(&quot;&quot;)<br>                };<br><br>                (span_label_var1, span_label_var2)<br>            }<br>        } else {<br>            return false;<br>        };<br><br>        struct_span_err!(self.tcx.sess, span, E0623, &quot;lifetime mismatch&quot;)<br>            .span_label(ty1.span,<br>                        format!(&quot;these two types are declared with different lifetimes...&quot;))<br>            .span_label(ty2.span, format!(&quot;&quot;))<br>            .span_label(span, format!(&quot;...but data{} flows{} here&quot;, label1, label2))<br>            .emit();<br>        return true;</pre><p>Neat and clean ❤️. Maintainable code.</p><p>More on this in upcoming articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5dba4b434e43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s Next?]]></title>
            <link>https://medium.com/@geekytwoshoes11/whats-next-863a6f881cbe?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/863a6f881cbe</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[rustlang]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Wed, 26 Jul 2017 20:14:29 GMT</pubDate>
            <atom:updated>2017-07-26T20:14:29.689Z</atom:updated>
            <content:encoded><![CDATA[<p>Some take-home points from the talk by <a href="https://www.linkedin.com/in/amyrrich">Amy Rich</a>, Manager of Release Engineering Operations at Mozilla Corporation.</p><p>The one hour talk started off with Amy explaining about her educational background, her journey as a Mechanical Aeronautical Engineer. She stressed that even the smallest things matter in the long run. Everything that she had picked up in high school and college and her previous jobs have contributed a lot to her career growth, technical as well as the business side. Keep questioning yourself, “What’s next?”. Find mentors to discuss your life goals with. Build a network. Open up doors.</p><p>Pick up other skills apart from *technical skills*. Soft skills and people management skills are a welcome bonus :). She also highlighted the diversity problem in the tech world, highlighting the women in tech has lost it’s flavor as women are no longer looked up to for being awesome engineers and programmers but for being women programmers and engineers. Combating with the typical *geek* stereotype means putting in extra efforts for acceptance. Hopefully, with more and more involvement of women in tech, this too come to an end.</p><p>We narrated our struggles in the tech world. Right from how people react when you introduce yourself as a software developer to putting up with the gender ratio in engineering grad colleges to the constant need to prove and improve yourself, it felt like familiar grounds. Sometimes, it means a lot to know that you are not the only one.</p><p>An awesome learning experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=863a6f881cbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lifetimes-and they lived happily ever after]]></title>
            <link>https://medium.com/@geekytwoshoes11/hi-a545b22a4dd?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/a545b22a4dd</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[rustlang]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Sun, 09 Jul 2017 11:24:38 GMT</pubDate>
            <atom:updated>2017-07-21T12:32:28.334Z</atom:updated>
            <content:encoded><![CDATA[<p>The story of designing E0623, the error case where both the regions corresponding to a function or trait are anonymous.</p><p>Previously, the aim was to infer the variable with the missing lifetime, given a named and anonymous region. Now, we look at cases where both the regions are anonymous. Let’s look at a relevant code sample.</p><pre>struct Foo&lt;&#39;a&gt; { x:  &amp;&#39;a u8 }</pre><pre>fn foo(x: &amp;mut Vec&lt;Foo&gt;, y: Foo) {</pre><pre><strong>       ---      --- these structs must have the same lifetime</strong></pre><pre>   x.push(y);</pre><pre><strong>   ^^^^^^^^^</strong></pre><pre>}</pre><p>Notice that Vec&lt;<strong>Foo</strong>&gt; and<strong> Foo</strong> both do not have lifetime declarations.</p><p>After considering various output messages, we finalized only on one.</p><pre>error[E0621]: lifetime mismatch</pre><pre>--&gt; ../../my_repos/rust/self1.rs:14:12</pre><pre>|</pre><pre>12 |   fn foo(x: &amp;mut Vec&lt;&amp;u8&gt;, y:&amp;u8) {</pre><pre><strong>|                      ---     --- these references must have the same lifetime</strong></pre><pre>13 |</pre><pre>14 |     x.push(y);</pre><pre><strong>|            ^ data from `y` flows into `x` here</strong></pre><h4>How do we go on with the code for this?</h4><ol><li>find both the anonymous regions of concern(Vec&lt;&amp;u8&gt; and &amp;u8). The underlines for x must be for Vec&lt;&amp;u8&gt; and not for &amp;u8 .</li><li>find the 2 arguments, corresponding to the among which the dataflow occurs.</li><li>generates wording of the error message.</li></ol><p>Some of the errors made by me</p><p>The challenge here was to extract the inner type which is Vec&lt;Foo&gt; instead of &amp;mut Vec&lt;Foo&gt; . To find this region, you need to walk the type.</p><h4>Attempt 1</h4><p>We walk the fndecl arguments, look for a LateBoundAnon region and find the corresponding argument using the below snippet. The index corresponds to the BrAnon region.</p><pre><strong>if debuijn_index.depth ==1 &amp;&amp; anon_index == index{</strong><br>                                    <strong>Some(&amp;**arg)}</strong></pre><p>We shall discuss <strong>debruijn indices</strong> in more detail later.</p><pre><strong>fndecl</strong>.inputs.iter().filter_map(<br>|arg| match arg.node {<br>         hir::TyRptr(ref lifetime, _) =&gt; {<br>           match self.tcx.named_region_map.defs.get(&amp;lifetime.id) {<br>              Some(&amp;rl::Region::LateBoundAnon(debuijn_index, <strong>anon_index</strong>))<br>                 match *br{<br>                              ty::BrAnon(index) =&gt; {<br>                                 <strong>if debuijn_index.depth ==1 &amp;&amp; anon_index == index{</strong><br>                                    <strong>Some(&amp;**arg)}</strong><br>                                 else{<br>                                   None}}<br>                              _=&gt; None,<br>                             }<br><br>}                                                           </pre><p>This ended up finding &amp;mut Vec&lt;Foo&gt; instead of Vec&lt;Foo&gt; .</p><h4>Attempt 2</h4><p>Using <strong>TypeFolders</strong>.</p><pre>hir::TyRptr(ref lifetime, _) =&gt; {<br>                    <br>                    match self.tcx.named_region_map.defs.get(&amp;lifetime.id) {<br>                      Some(&amp;rl::Region::LateBoundAnon(debuijn_index, anon_index)) =&gt; {<br><br>if debuijn_index.depth ==1 &amp;&amp; anon_index == br_index {<br>             let mut found_anon_region = false;<br>             if let anon_type = <strong>self.tcx.fold_regions</strong>(&amp;**arg, &amp;mut false, |r, _| <br>                if r == region { found_anon_region = true; r } else { r })<br>                if found_anon_region{Some(&amp;anon_type)}else{None}<br>} <br>                      <br>                              }</pre><p>fold_regions() only handles the internal type Ty&lt;&#39;tcx&gt; but what we need is hir::Ty .</p><h4>Attempt 3</h4><p>And it worked!!!</p><p>Since we need the hir::Ty, we decided to go ahead with using a <a href="https://github.com/gaurikholkar/rust/blob/1ea4bd3c3c363b68642acbfaa75f58a7c0ff3cdb/src/librustc/infer/error_reporting/need_type_info.rs#L53-L73"><strong>HIR Visitor</strong></a><strong>.</strong></p><pre>struct <strong>FindNestedTypeVisitor</strong>&lt;&#39;a, &#39;gcx: &#39;a + &#39;tcx, &#39;tcx: &#39;a&gt; {<br>    infcx: &amp;&#39;a <strong>InferCtxt</strong>&lt;&#39;a, &#39;gcx, &#39;tcx&gt;,<br>    hir_map: &amp;&#39;a<strong> hir::map::Map</strong>&lt;&#39;gcx&gt;,<br>    bound_region: <strong>ty::BoundRegion</strong>,<br>    found_type:<strong> Option&lt;&amp;&#39;gcx hir::Ty&gt;</strong>,<br>}</pre><p><strong>The </strong><a href="https://github.com/rust-lang/rust/blob/master/src/librustc/hir/intravisit.rs#L271"><strong>visit_ty</strong></a><strong> </strong>function is overridden as follows</p><pre>let br_index = match self.bound_region {<br>            ty::BrAnon(index) =&gt; index,<br>            _ =&gt; return,<br>        };<br><br>        match arg.node {<br>            hir::TyRptr(ref lifetime, _) =&gt; {<br>                match self.infcx.tcx.named_region_map.defs.get(&amp;lifetime.id) {<br>                    // the lifetime of the TyRptr!<br>                    Some(&amp;rl::Region::LateBoundAnon(debuijn_index, anon_index)) =&gt; {<br>                        if debuijn_index.depth == 1 &amp;&amp; anon_index == br_index {<br>                            self.found_type = Some(arg);<br>                            return; // we can stop visiting now<br>                        }<br>                    }<br>                    Some(&amp;rl::Region::Static) |<br>                    Some(&amp;rl::Region::EarlyBound(_, _)) |<br>                    Some(&amp;rl::Region::LateBound(_, _)) |<br>                    Some(&amp;rl::Region::Free(_, _)) |<br>                    None =&gt; {<br>                        debug!(&quot;no arg found&quot;);<br>                    }<br>                }<br>            }<br>            _ =&gt; {}<br>        }<br>        // walk the embedded contents: e.g., if we are visiting `Vec&lt;&amp;Foo&gt;`,<br>        // go on to visit `&amp;Foo`<br><a href="https://github.com/rust-lang/rust/blob/master/src/librustc/hir/intravisit.rs#L543">       <strong> intravisit::walk_ty(self, arg);</strong><br></a>    }</pre><p>So now that we have our hands on both the anonymous regions, the next step is a cakewalk :P. More on this in the later articles. Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a545b22a4dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Perfect Two Months]]></title>
            <link>https://medium.com/@geekytwoshoes11/efghi-125a88369123?source=rss-b95b1485da29------2</link>
            <guid isPermaLink="false">https://medium.com/p/125a88369123</guid>
            <category><![CDATA[mozilla]]></category>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[rust]]></category>
            <dc:creator><![CDATA[GeekyTwoShoes]]></dc:creator>
            <pubDate>Sun, 09 Jul 2017 11:24:02 GMT</pubDate>
            <atom:updated>2017-08-01T19:20:51.087Z</atom:updated>
            <content:encoded><![CDATA[<p>My journey with Rust 😍</p><p>It’s been two months already! The discussion took off with a discussion on lifetime errors, deciding which one is more important than the other and selecting specific cases to deal with.</p><h3>loop {</h3><h4>//Iteration I</h4><h4>The Perfect Error</h4><p>The hunt to find the simplest and most basic error message to start with began. Considering various common lifetime errors, we decided to go ahead with the one above. We had discussions on the region inferencing in the Rust Compiler to understand anonymous regions(lifetimes), in particular the RegionResolution Error.</p><pre>fn foo&lt;&#39;a&gt;(x: &amp;&#39;a i32, y: &amp;i32) -&gt; &amp;&#39;a i32 {</pre><pre>    if x &gt; y { x } else { y }</pre><pre>}</pre><p>We picked up an example with one anonymous and one named region.</p><h4>The Perfect Error Message</h4><p>Finding the perfect example to start off wasn’t enough. A lot of time went in discussing the final looks of the error message. Lifetimes are a major reason why the beginners of Rust struggle at the start and our whole effort was directed at changing that experience.</p><pre>fn foo&lt;&#39;a&gt;(x: &amp;&#39;a i32, y: &amp;i32) -&gt; &amp;&#39;a i32 {</pre><pre>                       - consider changing the type of `y` to `&amp;&#39;a i32`</pre><pre>if x &gt; y { x } else { y }</pre><pre>                      ^ this reference must have lifetime &#39;a</pre><pre>}</pre><h4>Write Code</h4><p>Well, when you know what is the expected output, coding becomes a bit easier. This was the first time I had to deep dive into the region_inference related <a href="https://github.com/rust-lang/rust/blob/master/src/librustc/infer/error_reporting/mod.rs">error_reporting modules</a> in the Rust Compiler. Walking the hir map to search for the anonymous region and replacing it by the named region using Typefolders resulted in the above error message.</p><h4>Write Better Code</h4><p>The code review has been an empowering experience for me. I have previously worked on huge codebases for my internship but this was something new. As a beginner in open source, a community review structure has given me a broader perspective on the programming principles of Rust.</p><h4><strong>PR Merged ❤</strong></h4><p>Run the example <a href="https://play.rust-lang.org/?gist=20459b07a0962fa641da6683e4eb3e67&amp;version=nightly">here</a>.</p><h4>//Iteration II</h4><h4>The Next Perfect Example</h4><p><strong>E0623 </strong>considers the cases like above where both the regions are <strong>anonymous</strong>.</p><pre>fn foo(x: &amp;mut Vec&lt;&amp;u8&gt;, y: &amp;u8) {<br>   x.push(y);<br>}</pre><h4><strong>The Next Perfect Error Message</strong></h4><pre>11 | fn foo(x: &amp;mut Vec&lt;&amp;u8&gt;, y: &amp;u8) {<br>   |                    ---      --- these references are not declared with the same lifetime...<br>12 |     x.push(y);<br>   |            ^ ...but data from `y` flows into `x` here<br><br>error: aborting due to previous error</pre><p>The hir::Ty is extracted for both the regions using a NestedTypeVisitor . NestedTypeVisitor.found_type gives us the required region i.e. &amp;&lt;u8&gt; and Vec&lt;&amp;u8&gt; for the case above. For the case of <strong>structs</strong>, we have the following error message( More on this is an upcoming post).</p><pre>| fn foo(mut x: Vec&lt;Ref&lt;T&gt;&gt;,<br>  |                  --- <br>  |       y: Ref&lt;T&gt;) <br>  |          --- these two structs are not declared with the same lifetime ...<br>  |{<br>  | x.push(y);<br>  |        ^ ... but data flows from `y` into `x` here<br>  | }<br>help: consider changing the signature to:<br>  | fn foo&lt;&#39;a&gt;(mut x: Vec&lt;&#39;a, Ref&lt;T&gt;&gt;, y: Ref&lt;&#39;a, T&gt;)</pre><h4>Write Code</h4><p>The changes for the above error message have been merged. The changes for structs are not yet in PR phase.</p><h4>}</h4><p>And the cycle continues…</p><p>The changes for E0621 and E0623 have been successfully merged 😃.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=125a88369123" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>