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
@@ -13,8 +13,8 @@
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/fail_param_count.carbon
fn Run0() {}
fn Run1(a: i32) {}
fn Run2(a: i32, b: i32) {}
fn Run1(unused a: i32) {}
fn Run2(unused a: i32, unused b: i32) {}
fn Main() {
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 0 arguments [CallArgCountMismatch]
@@ -38,16 +38,16 @@ fn Main() {
// CHECK:STDERR: Run1();
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-24]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run1(a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
// CHECK:STDERR: fn Run1(unused a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run1();
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 2 arguments passed to function expecting 1 argument [CallArgCountMismatch]
// CHECK:STDERR: Run1(0, 1);
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-32]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run1(a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
// CHECK:STDERR: fn Run1(unused a: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run1(0, 1);
@@ -55,16 +55,16 @@ fn Main() {
// CHECK:STDERR: Run2();
// CHECK:STDERR: ^~~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-40]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run2(a: i32, b: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fn Run2(unused a: i32, unused b: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run2();
// CHECK:STDERR: fail_param_count.carbon:[[@LINE+7]]:3: error: 1 argument passed to function expecting 2 arguments [CallArgCountMismatch]
// CHECK:STDERR: Run2(0);
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR: fail_param_count.carbon:[[@LINE-48]]:1: note: calling function declared here [InCallToEntity]
// CHECK:STDERR: fn Run2(a: i32, b: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fn Run2(unused a: i32, unused b: i32) {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
Run2(0);
}
@@ -126,15 +126,15 @@ fn Main() {
// CHECK:STDOUT: %b.param_patt: %pattern_type.7ce = value_param_pattern %b.patt, call_param1 [concrete]
// CHECK:STDOUT: } {
// CHECK:STDOUT: %a.param: %i32 = value_param call_param0
// CHECK:STDOUT: %.loc17_12: type = splice_block %i32.loc17_12 [concrete = constants.%i32] {
// CHECK:STDOUT: %int_32.loc17_12: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32.loc17_12: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: %.loc17_19: type = splice_block %i32.loc17_19 [concrete = constants.%i32] {
// CHECK:STDOUT: %int_32.loc17_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32.loc17_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: }
// CHECK:STDOUT: %a: %i32 = value_binding a, %a.param
// CHECK:STDOUT: %b.param: %i32 = value_param call_param1
// CHECK:STDOUT: %.loc17_20: type = splice_block %i32.loc17_20 [concrete = constants.%i32] {
// CHECK:STDOUT: %int_32.loc17_20: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32.loc17_20: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: %.loc17_34: type = splice_block %i32.loc17_34 [concrete = constants.%i32] {
// CHECK:STDOUT: %int_32.loc17_34: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
// CHECK:STDOUT: %i32.loc17_34: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
// CHECK:STDOUT: }
// CHECK:STDOUT: %b: %i32 = value_binding b, %b.param
// CHECK:STDOUT: }