Implement unused pattern bindings, continued (#6518)

Implementation of unused pattern bindings #2022, continued.

Whereas previous PR #6460 took care of parsing, and PR #6479 prepared
the stage by using _ in some test cases, this PR has the the actual
implementation, using a simple dataflow analysis.

---------

Co-authored-by: Burak Emir <bqe@google.com>
Co-authored-by: jonmeow <jperkins@google.com>
This commit is contained in:
Burak Emir
2026-02-19 23:33:36 +00:00
committed by GitHub
co-authored by Burak Emir jonmeow
parent bea24a8bee
commit fdb188ccfd
366 changed files with 8453 additions and 7996 deletions
+5 -3
View File
@@ -14,6 +14,7 @@
#include "toolchain/check/name_component.h"
#include "toolchain/check/name_lookup.h"
#include "toolchain/check/type_completion.h"
#include "toolchain/check/unused.h"
#include "toolchain/diagnostics/diagnostic.h"
#include "toolchain/sem_ir/ids.h"
#include "toolchain/sem_ir/name_scope.h"
@@ -86,10 +87,11 @@ auto DeclNameStack::FinishImplName() -> NameContext {
return result;
}
auto DeclNameStack::PopScope() -> void {
auto DeclNameStack::PopScope(bool check_unused) -> void {
CARBON_CHECK(decl_name_stack_.back().state == NameContext::State::Finished,
"Missing call to FinishName before PopScope");
context_->scope_stack().PopTo(decl_name_stack_.back().initial_scope_index);
context_->scope_stack().PopTo(decl_name_stack_.back().initial_scope_index,
check_unused);
decl_name_stack_.pop_back();
}
@@ -248,7 +250,7 @@ static auto PushNameQualifierScope(Context& context, SemIR::LocId loc_id,
-> SemIR::NameScopeId {
// If the qualifier has no parameters, we don't need to keep around a
// parameter scope.
context.scope_stack().PopIfEmpty();
context.scope_stack().PopIfEmpty(/*check_unused=*/true);
auto self_specific_id = SemIR::SpecificId::None;
if (generic_id.has_value()) {