-
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
Refactored used_mut_nodes #43945
Refactored used_mut_nodes #43945
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@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 :) |
src/librustc/ty/mod.rs
Outdated
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will need to be declared pub
, that is why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good so far =)
src/librustc_lint/unused.rs
Outdated
@@ -35,7 +35,9 @@ declare_lint! { | |||
} | |||
|
|||
#[derive(Copy, Clone)] | |||
pub struct UnusedMut; | |||
pub struct UnusedMut { | |||
borrowck_results: Vec<Rc<BorrowCheckResult>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@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! =) |
☔ The latest upstream changes (presumably #44009) made this pull request unmergeable. Please resolve the merge conflicts. |
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? |
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?). |
@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. |
@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. |
@cynicaldevil do you understand the alternative approach that @alexcrichton was describing? Think you would have time to pursue that? |
@nikomatsakis Hmm I think I understand. I'll ask some more questions if I get stuck along the way. |
@cynicaldevil any update? Also, see #44195, which performed a similar refactoring (for a different lint). |
@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! |
@cynicaldevil great! I was just checking in. =) |
@alexcrichton |
I believe the lint is |
@cynicaldevil ping just to make sure this stays on your radar! If you're busy nowadays no worries as well! |
Yes, sorry about that! I'll try to work on this during the weekend. |
@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! |
From IRC: |
a41db50
to
371a195
Compare
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::MultiSpan as 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? |
Oh, I was hoping for some input here itself :) |
@cynicaldevil You can use |
@arielb1 That solved the problem, thanks. But now I'm getting a long list of |
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: |
@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. |
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