Uh oh!
There was an error while loading. Please reload this page.
Properly pass down immutability info for thread-locals. - #47425
Conversation
rust-highfive
commented
Jan 14, 2018
(rust_highfive has picked a reviewer for you, use r? to override) |
eddyb
commented
Jan 15, 2018
This is only needed because of how |
nikomatsakis
commented
Jan 16, 2018
This is indeed fixed in MIR borrowck, as you can see from this example. It may still be worth fixing in AST borrowck, if it's easy -- we're still going to need some version of the mem-cat / expr-use-visitor code for upvar inference, though I hope we'll be able to greatly simplify it. |
nikomatsakis
commented
Jan 16, 2018
OK, I think I see what you are saying. I don't think I realized how this was being handled. Basically I guess thread-locals are being converted into rvalues so that borrowck will assign a more limited lifetime? That does indeed feel like rather a hack. |
Maybe I should take a look at what it might mean to integrate more "properly" into borrowck? It feels like that would likely be very easy to do (i.e., maybe even a smaller diff than what is here). I think the main thing is that this line has to change: rust/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs Lines 83 to 85 in da569fa This basically says that a loan of static content can have any lifetime. But in the case of a static item tagged with |
EdSchouten
commented
Jan 17, 2018
Hi @nikomatsakis! That does sound like a decent approach. That said, I've only been using Rust for the last four weeks. I was already quite happy to come up with this patch. I suspect it would be wiser for you to take a stab at this. Would that be all right? |
nikomatsakis
commented
Jan 17, 2018
Hmm, in that case, I might be inclined to let this "fix itself" as we transition to the MIR-based borrowck. |
That sounds reasonable to me. Before closing this pull request: do we want to add this as a unit test for the new borrowck? |
nikomatsakis
commented
Jan 17, 2018
@EdSchouten yep, I've been tracking such bugs in #47366 -- I'll add #47053 to that list |
nikomatsakis
commented
Jan 17, 2018
@EdSchouten maybe repurpose this PR for that purpose? #47366 has a bit of directions for how to go about it. |
859debc to
93c892aCompareIt is currently allowed to perform such assignments when not making use of NLL. NLL already does this right, but let's add a test in place to ensure it never regresses.
93c892a to
e47cc69CompareEdSchouten
commented
Jan 20, 2018
I've just reworked this PR to only add testing coverage for NLL. Does this look all right? |
nikomatsakis
commented
Jan 22, 2018
@bors r+ rollup |
bors
commented
Jan 22, 2018
📌 Commit e47cc69 has been approved by |
nikomatsakis
commented
Jan 22, 2018
@EdSchouten looks great =) |
…sakis Properly pass down immutability info for thread-locals. For thread-locals we call into cat_rvalue_node() to create a CMT (Category, Mutability, Type) that always has McDeclared. This is incorrect for thread-locals that don't have the 'mut' keyword; we should use McImmutable there. Extend cat_rvalue_node() to have an additional mutability parameter. Fix up all the callers to make use of that function. Also extend one of the existing unit tests to cover this. Fixes: rust-lang#47053
For thread-locals we call into cat_rvalue_node() to create a CMT
(Category, Mutability, Type) that always has McDeclared. This is
incorrect for thread-locals that don't have the 'mut' keyword; we should
use McImmutable there.
Extend cat_rvalue_node() to have an additional mutability parameter. Fix
up all the callers to make use of that function. Also extend one of the
existing unit tests to cover this.
Fixes: #47053