-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly pass down immutability info for thread-locals. #47425
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This is only needed because of how |
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. |
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 |
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? |
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? |
@EdSchouten yep, I've been tracking such bugs in #47366 -- I'll add #47053 to that list |
@EdSchouten maybe repurpose this PR for that purpose? #47366 has a bit of directions for how to go about it. |
859debc
to
93c892a
Compare
It 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
e47cc69
Compare
I've just reworked this PR to only add testing coverage for NLL. Does this look all right? |
@bors r+ rollup |
📌 Commit e47cc69 has been approved by |
@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