Uh oh!
There was an error while loading. Please reload this page.
Refactored used_mut_nodes - #43945
Conversation
rust-highfive
commented
Aug 17, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
nikhilshagri
commented
Aug 17, 2017
@nikomatsakis I've created the PR, but I haven't been able to build it yet, something went awfully wrong when I was rebasing it. I'll let the bot do its job :) |
| /// contains the node-ids for variables within this function where the `mut` | ||
| /// declaration was used in some way (e.g., by modifying the variable's value, | ||
| /// or taking an `&mut` borrow of it). | ||
| used_mut_nodes: NodeSet |
There was a problem hiding this comment.
Failed to compile due to denied warning.
[00:07:27] error: field is never used: `used_mut_nodes`
[00:07:27] --> /checkout/src/librustc/ty/mod.rs:2607:5[00:07:27] |
[00:07:27]2607 | used_mut_nodes:NodeSet[00:07:27] | ^^^^^^^^^^^^^^^^^^^^^^^
[00:07:27] |There was a problem hiding this comment.
this will need to be declared pub, that is why
There was a problem hiding this comment.
huh, that's weird. It's used both in check_loans.rs and gather_loans.rs, I can't figure why that's cropping up.
nikomatsakis
left a comment
There was a problem hiding this comment.
Looking good so far =)
| #[derive(Copy, Clone)] | ||
| pub struct UnusedMut; | ||
| pub struct UnusedMut { | ||
| borrowck_results: Vec<Rc<BorrowCheckResult>> |
There was a problem hiding this comment.
It seems that there are no uses of this field -- looking at the rest of this file, it seems like it still reads from tcx.used_mut_nodes. Once you add the pub keyword to the above file, of course, we'll get to this crate, at which point it won't compile, since tcx.used_mut_nodes has been removed.
nikomatsakis
commented
Aug 21, 2017
@cynicaldevil did what I wrote make sense to you? seems like this PR is close, I'd love to see it get over the finish line! =) |
bors
commented
Aug 21, 2017
☔ The latest upstream changes (presumably #44009) made this pull request unmergeable. Please resolve the merge conflicts. |
nikhilshagri
commented
Aug 22, 2017
I've been trying to build my PR for the last few days, and have been running into a lot of little problems. Is it ok if I just make the changes you described and push them, without building it first? |
Mark-Simulacrum
commented
Aug 22, 2017
That should be fine. Let us know if we can help out with any of those problems (which I take are errors during the build?). |
alexcrichton
commented
Aug 23, 2017
@nikomatsakis @cynicaldevil hey! I was passing by and noticed this, and was curious, I wonder if we need to save off the set of unused nodes still? Long ago we had to save off these nodes as we didn't know the lint level for nodes until the very end of the compiler, but as of recently we actually know the lint levels of all nodes throughout most of compilation. With that information, I wonder if this could be refactored to directly emit the lint as soon as it's detected? That way there's no need to persist these sets until the end of compilation, but rather we can emit the lint right-then-and-there and the diagnostic is cached through standard mechanisms for incremental. |
nikomatsakis
commented
Aug 23, 2017
@alexcrichton um yeah good point! In this case, the lint is purely local to the function, so there is no need to combine the results of multiple functions, so I think we could just do it "in place" as you suggest. |
nikomatsakis
commented
Aug 23, 2017
@cynicaldevil do you understand the alternative approach that @alexcrichton was describing? Think you would have time to pursue that? |
nikhilshagri
commented
Aug 24, 2017
@nikomatsakis Hmm I think I understand. I'll ask some more questions if I get stuck along the way. |
nikomatsakis
commented
Aug 31, 2017
@cynicaldevil any update? Also, see #44195, which performed a similar refactoring (for a different lint). |
nikhilshagri
commented
Aug 31, 2017
@nikomatsakis I asked @alexcrichton some questions on IRC a couple days ago, and I plan to work on it tomorrow. Sorry for dragging it, I'll wrap this up soon! |
nikomatsakis
commented
Sep 1, 2017
@cynicaldevil great! I was just checking in. =) |
nikhilshagri
commented
Sep 2, 2017
@alexcrichton |
alexcrichton
commented
Sep 3, 2017
I believe the lint is |
alexcrichton
commented
Sep 7, 2017
@cynicaldevil ping just to make sure this stays on your radar! If you're busy nowadays no worries as well! |
nikhilshagri
commented
Sep 8, 2017
Yes, sorry about that! I'll try to work on this during the weekend. |
nikomatsakis
commented
Sep 14, 2017
@cynicaldevil friendly ping =) PS It's actually kind of important for us to fix this particular problem soon-ish. It's perfectly fine if you don't have time right now to get to it, someone else can write the patch -- there will be more decent bugs to tackle! |
nikhilshagri
commented
Sep 15, 2017
From IRC: |
a41db50 to
371a195Comparenikhilshagri
commented
Sep 16, 2017
Right, I've pushed the latest changes here. I'm still getting a couple of errors: error[E0308]: mismatched types
--> src/librustc_borrowck/borrowck/check_loans.rs:853:72
|
853 | self.bccx.tcx.hir.span_if_local(local_id),
| ^^^^^^^^ expected struct `rustc::hir::def_id::DefId`, found struct `syntax::ast::NodeId`
|
= note: expected type `rustc::hir::def_id::DefId`
found type `syntax::ast::NodeId`
error[E0277]: the trait bound `syntax_pos::MultiSpan: std::convert::From<std::option::Option<syntax_pos::Span>>` is not satisfied
--> src/librustc_borrowck/borrowck/check_loans.rs:851:35
|
851 | self.bccx.tcx.lint_node(UNUSED_MUT,
| ^^^^^^^^^ the trait `std::convert::From<std::option::Option<syntax_pos::Span>>` is not implemented for `syntax_pos::MultiSpan`
|
= help: the following implementations were found:
<syntax_pos::MultiSpanas std::convert::From<syntax_pos::Span>>
= note: required because of the requirements on the impl of `std::convert::Into<syntax_pos::MultiSpan>` for `std::option::Option<syntax_pos::Span>`And the exact same errors appear in |
@cynicaldevil just so we're clear on where this PR is at, are you planning on asking on IRC about the failures above or are you hoping for some input as a comment on this PR? |
nikhilshagri
commented
Sep 20, 2017
Oh, I was hoping for some input here itself :) |
arielb1
commented
Sep 21, 2017
@cynicaldevil You can use |
nikhilshagri
commented
Sep 24, 2017
@arielb1 That solved the problem, thanks. But now I'm getting a long list of |
carols10cents
commented
Oct 2, 2017
ping @nikomatsakis@arielb1, looks like @cynicaldevil could use some input! |
Thanks @carols10cents! @arielb1 and I had talked over IRC, and I progressed further, but got stuck again. I was thinking of asking on the IRC channel, but I'll post it here: |
alexcrichton
commented
Oct 6, 2017
@cynicaldevil yes the warning there I believe is warning about the inverse. As described on #42384 what you'll probably want to do is to change the borrowck query to return a set of used mutable nodes. Then somewhere else in the compiler you'll use these results to warn about mutable nodes that aren't in the set. |
nikomatsakis
commented
Oct 10, 2017
Per our conversation on IRC, I'm going to close this PR (@cynicaldevil told me that they won't have time to follow up on it). Sorry @cynicaldevil that this turned out to be more difficult than I initially anticipated! Thanks for banging on it, in any case. |
Fixes#42384