-
Notifications
You must be signed in to change notification settings - Fork 184
Implement unused variable checker on HIR #4055
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
base: master
Are you sure you want to change the base?
Conversation
c2bb066
to
038d637
Compare
gcc/rust/ChangeLog: * Make-lang.in: New file. * checks/lints/unused-var/rust-unused-var-checker.cc (UnusedVarChecker): Implement unused variable checker. * checks/lints/unused-var/rust-unused-var-checker.h (UnusedVarChecker): Implement unused variable checker. * checks/lints/unused-var/rust-unused-var-collector.cc (UnusedVarCollector): Implement unused variable collector. * checks/lints/unused-var/rust-unused-var-collector.h (UnusedVarCollector): Implement unused variable collector. * checks/lints/unused-var/rust-unused-var-context.cc (UnusedVarContext): Implement unused variable context. * checks/lints/unused-var/rust-unused-var-context.h (UnusedVarContext): Implement unused variable context. Signed-off-by: Ryutaro Okada <[email protected]>
038d637
to
f27c7a7
Compare
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.
I think this is a really good base and the code looks good to me! I think it is important to add testcases for features like these, so it would be good if you could add a flag to enable the lints you've written and then add testcases to the testsuite
UnusedVarContext * | ||
UnusedVarContext::get () | ||
{ | ||
static UnusedVarContext *instance; | ||
if (instance == nullptr) | ||
instance = new UnusedVarContext (); | ||
return instance; | ||
} |
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.
I think this is fine but we should also check if we can do without a global variable
UnusedVarCollector::visit (HIR::LetStmt &stmt) | ||
{ | ||
HIR::Pattern &pattern = stmt.get_pattern (); | ||
collect_variable (pattern); |
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.
can't we visit instead here? mabye I'm missing something but I think all patterns should create variables to check for, so we could just do visit(pattern)
and then create visitors for all our kinds of patterns instead of manually dispatching like in collect_variable
make check-rust
passes locallyclang-format