-
Notifications
You must be signed in to change notification settings - Fork 195
Refactor dead code lint #4294
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
Open
lucasly-ba
wants to merge
6
commits into
Rust-GCC:master
Choose a base branch
from
lucasly-ba:dead-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor dead code lint #4294
+554
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This change moves the unused variable checker from the type resolver to HIR. We can now use the HIR Default Visitor, and it will be much more easier to implement other unused lints with this change. gcc/rust/ChangeLog: * Make-lang.in: Add new files rules in Makefile. * lang.opt: Add new flag. * rust-session-manager.cc (Session::compile_crate): Execute new variable checker. * 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. gcc/testsuite/ChangeLog: * rust/compile/static_item_0.rs: New test. * rust/compile/template_function_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
gcc/rust/ChangeLog: * checks/lints/unused-var/rust-unused-var-checker.cc (UnusedVarChecker): Implement unused assignments warning. (UnusedVarChecker::go): Remove unique pointer unused var context. (UnusedVarChecker::visit): Visit AssignExpr in HIR default visitor. * checks/lints/unused-var/rust-unused-var-checker.h: Add visit method. * checks/lints/unused-var/rust-unused-var-collector.cc (UnusedVarCollector): Collect warnings for assignments. (UnusedVarCollector::visit): Visit AssignExpr in HIR default visitor. * checks/lints/unused-var/rust-unused-var-collector.h: Add visit method. * checks/lints/unused-var/rust-unused-var-context.cc (UnusedVarContext::add_assign): Add assignment in map. (UnusedVarContext::remove_assign): Remove assignment in map. (UnusedVarContext::is_variable_assigned): Check if a variable is assigned. * checks/lints/unused-var/rust-unused-var-context.h: Add a map to stock assignments. gcc/testsuite/ChangeLog: * rust/compile/issue-4260_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
gcc/rust/ChangeLog: * checks/lints/unused-var/rust-unused-var-checker.cc (UnusedVarChecker::visit): Change unused name warning to unused variable warning. * checks/lints/unused-var/rust-unused-var-collector.cc (UnusedVarCollector::visit): Remove useless methods. * checks/lints/unused-var/rust-unused-var-collector.h: Same here. * checks/lints/unused-var/rust-unused-var-context.cc (UnusedVarContext::add_variable): Add used variables to set. (UnusedVarContext::mark_used): Remove method. (UnusedVarContext::is_variable_used): Check if the set contains the hir id linked to a variable. (UnusedVarContext::as_string): Refactor method for new set. * checks/lints/unused-var/rust-unused-var-context.h: Refactor methods. * lang.opt: Change description for unused check flag. gcc/testsuite/ChangeLog: * rust/compile/static_item_0.rs: Modify warning output. * rust/compile/template_function_0.rs: Modify warning output. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
gcc/rust/ChangeLog: * Make-lang.in: Compile the right files. * checks/lints/unused-var/rust-unused-var-checker.cc: Move to... * checks/lints/unused/rust-unused-checker.cc: ...here. * checks/lints/unused-var/rust-unused-var-checker.h: Move to... * checks/lints/unused/rust-unused-checker.h: ...here. * checks/lints/unused-var/rust-unused-var-collector.cc: Move to... * checks/lints/unused/rust-unused-collector.cc: ...here. * checks/lints/unused-var/rust-unused-var-collector.h: Move to... * checks/lints/unused/rust-unused-collector.h: ...here. * checks/lints/unused-var/rust-unused-var-context.cc: Move to... * checks/lints/unused/rust-unused-context.cc: ...here. * checks/lints/unused-var/rust-unused-var-context.h: Move to... * checks/lints/unused/rust-unused-context.h: ...here. * rust-session-manager.cc (Session::compile_crate): Call the right method. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
gcc/rust/ChangeLog: * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::UnusedChecker): Add warning for identifier pattern and field ident pattern in struct (UnusedChecker::visit): Add methods. * checks/lints/unused/rust-unused-checker.h: Same here. * checks/lints/unused/rust-unused-collector.cc (UnusedCollector::UnusedCollector): Collect unused mut variables (UnusedCollector::visit): Add methods. * checks/lints/unused/rust-unused-collector.h: Same here. * checks/lints/unused/rust-unused-context.cc (UnusedContext::remove_assign): Add methods for unused mut set. (UnusedContext::add_mut): Same here. (UnusedContext::remove_mut): Same here. (UnusedContext::is_mut_used): Same here. * checks/lints/unused/rust-unused-context.h: Same here. gcc/testsuite/ChangeLog: * rust/compile/unused-mut-identifier_0.rs: New test. * rust/compile/unused-mut-struct-field_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
4da5fdc to
fba4e7c
Compare
This patch is simple, it only moves the check of unused static items and unused const items into the dead-code scan visitor. gcc/rust/ChangeLog: * checks/lints/rust-lint-scan-deadcode.h: Warns if there is an unused static item or unused const item. * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit): Removes static item and const item. * checks/lints/unused/rust-unused-checker.h: Same here. gcc/testsuite/ChangeLog: * rust/compile/static_item_0.rs: Change warning description. * rust/compile/const_item_0.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
fba4e7c to
e223a3b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch is simple, it only moves the check of unused static items and unused const items into the dead-code scan visitor.