From d87891f3a628a8ce41b7995a983d84e41570c0d7 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 15 Oct 2026 20:15:28 +0000 Subject: [PATCH] Fix diagnostic style issues (#7982) Remove trailing `.`s and leading capitalization from diagnostics, and separate clauses with `;` rather than `.`, per https://docs.carbon-lang.dev/toolchain/docs/diagnostics.html#diagnostic-message-style-guide --- toolchain/check/eval.cpp | 4 ++-- toolchain/check/function.cpp | 6 +++--- .../function/declaration/default_values.carbon | 18 +++++++++--------- toolchain/check/testdata/lambda/lambda.carbon | 4 ++-- .../overloaded/string_indexing.carbon | 4 ++-- toolchain/driver/link_driver.cpp | 2 +- toolchain/lex/lex.cpp | 6 +++--- .../lex/testdata/dollar_int_literals.carbon | 16 ++++++++-------- toolchain/parse/handle_binding_pattern.cpp | 2 +- toolchain/parse/handle_pattern_list.cpp | 4 ++-- .../testdata/struct/struct_pattern.carbon | 12 ++++++------ 11 files changed, 39 insertions(+), 39 deletions(-) diff --git a/toolchain/check/eval.cpp b/toolchain/check/eval.cpp index bc102803874e..74e979eb550f 100644 --- a/toolchain/check/eval.cpp +++ b/toolchain/check/eval.cpp @@ -2549,7 +2549,7 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context, if (index_val.isNegative()) { CARBON_DIAGNOSTIC(StringAtIndexNegative, Error, - "index `{0}` is negative.", TypedInt); + "index `{0}` is negative", TypedInt); context.emitter().Emit( loc_id, StringAtIndexNegative, {.type = eval_context.insts().Get(index_id).type_id(), @@ -2560,7 +2560,7 @@ static auto MakeConstantForBuiltinCall(EvalContext& eval_context, if (index_val.getZExtValue() >= string_value.size()) { CARBON_DIAGNOSTIC( StringAtIndexOutOfBounds, Error, - "string index `{0}` is out of bounds; string has length {1}.", + "string index `{0}` is out of bounds; string has length {1}", TypedInt, size_t); context.emitter().Emit( loc_id, StringAtIndexOutOfBounds, diff --git a/toolchain/check/function.cpp b/toolchain/check/function.cpp index 257359714da7..f0ed7cc4e4f8 100644 --- a/toolchain/check/function.cpp +++ b/toolchain/check/function.cpp @@ -684,14 +684,14 @@ static auto CheckDefaults(Context& context, SemIR::Function& function) // Finished processing this tuple-pattern, emit diagnostics if any. if (!state->patterns_missing_defaults.empty()) { CARBON_DIAGNOSTIC(RequiredPatternDefaultValueMissing, Error, - "this pattern is missing a required default value."); + "this pattern is missing a required default value"); CARBON_DIAGNOSTIC_LABEL(RequiredPatternDefaultValueFirstDefault, Info, "all patterns to the right of this first pattern " "with a default value must also specify a " - "default value."); + "default value"); CARBON_DIAGNOSTIC_LABEL( RequiredPatternDefaultValueMissingAdditional, Primary, - "this pattern is also missing a required default value."); + "this pattern is also missing a required default value"); auto inst_ref = llvm::ArrayRef(state->patterns_missing_defaults); auto builder = context.emitter().Build( inst_ref.consume_front(), RequiredPatternDefaultValueMissing); diff --git a/toolchain/check/testdata/function/declaration/default_values.carbon b/toolchain/check/testdata/function/declaration/default_values.carbon index f452e62ccc2f..efde49985e49 100644 --- a/toolchain/check/testdata/function/declaration/default_values.carbon +++ b/toolchain/check/testdata/function/declaration/default_values.carbon @@ -44,12 +44,12 @@ library "[[@TEST_NAME]]"; class C {} -// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+7]]:35-38: error: this pattern is missing a required default value. [RequiredPatternDefaultValueMissing] -// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+6]]:24-27: note: all patterns to the right of this first pattern with a default value must also specify a default value. [RequiredPatternDefaultValueFirstDefault] +// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+7]]:35-38: error: this pattern is missing a required default value [RequiredPatternDefaultValueMissing] +// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+6]]:24-27: note: all patterns to the right of this first pattern with a default value must also specify a default value [RequiredPatternDefaultValueFirstDefault] // CHECK:STDERR: -// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+4]]:23-39: error: this pattern is missing a required default value. [RequiredPatternDefaultValueMissing] -// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+3]]:53-56: note: this pattern is also missing a required default value. [RequiredPatternDefaultValueMissingAdditional] -// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+2]]:12-15: note: all patterns to the right of this first pattern with a default value must also specify a default value. [RequiredPatternDefaultValueFirstDefault] +// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+4]]:23-39: error: this pattern is missing a required default value [RequiredPatternDefaultValueMissing] +// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+3]]:53-56: note: this pattern is also missing a required default value [RequiredPatternDefaultValueMissingAdditional] +// CHECK:STDERR: fail_required_default_values_missing.carbon:[[@LINE+2]]:12-15: note: all patterns to the right of this first pattern with a default value must also specify a default value [RequiredPatternDefaultValueFirstDefault] // CHECK:STDERR: fn Z(v: C, x: C = {}, (y: C = {}, z: C), w: C = {}, k: C); @@ -58,11 +58,11 @@ library "[[@TEST_NAME]]"; class C {} -// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+6]]:36-47: error: this pattern is missing a required default value. [RequiredPatternDefaultValueMissing] -// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+5]]:25-28: note: all patterns to the right of this first pattern with a default value must also specify a default value. [RequiredPatternDefaultValueFirstDefault] +// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+6]]:36-47: error: this pattern is missing a required default value [RequiredPatternDefaultValueMissing] +// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+5]]:25-28: note: all patterns to the right of this first pattern with a default value must also specify a default value [RequiredPatternDefaultValueFirstDefault] // CHECK:STDERR: -// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+3]]:24-48: error: this pattern is missing a required default value. [RequiredPatternDefaultValueMissing] -// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+2]]:13-16: note: all patterns to the right of this first pattern with a default value must also specify a default value. [RequiredPatternDefaultValueFirstDefault] +// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+3]]:24-48: error: this pattern is missing a required default value [RequiredPatternDefaultValueMissing] +// CHECK:STDERR: fail_nesting_required_default_values_missing.carbon:[[@LINE+2]]:13-16: note: all patterns to the right of this first pattern with a default value must also specify a default value [RequiredPatternDefaultValueFirstDefault] // CHECK:STDERR: fn F(a: C, (b: C = {}, (c: C = {}, (d: C, e: C)))); diff --git a/toolchain/check/testdata/lambda/lambda.carbon b/toolchain/check/testdata/lambda/lambda.carbon index 4a080cd30233..4cddab267a5e 100644 --- a/toolchain/check/testdata/lambda/lambda.carbon +++ b/toolchain/check/testdata/lambda/lambda.carbon @@ -238,8 +238,8 @@ fn F() { library "[[@TEST_NAME]]"; fn F() { - // CHECK:STDERR: fail_default_values.carbon:[[@LINE+3]]:34-39: error: this pattern is missing a required default value. [RequiredPatternDefaultValueMissing] - // CHECK:STDERR: fail_default_values.carbon:[[@LINE+2]]:15-20: note: all patterns to the right of this first pattern with a default value must also specify a default value. [RequiredPatternDefaultValueFirstDefault] + // CHECK:STDERR: fail_default_values.carbon:[[@LINE+3]]:34-39: error: this pattern is missing a required default value [RequiredPatternDefaultValueMissing] + // CHECK:STDERR: fail_default_values.carbon:[[@LINE+2]]:15-20: note: all patterns to the right of this first pattern with a default value must also specify a default value [RequiredPatternDefaultValueFirstDefault] // CHECK:STDERR: (fn (unused x: i32 = 1, unused y: i32) {}); } diff --git a/toolchain/check/testdata/operators/overloaded/string_indexing.carbon b/toolchain/check/testdata/operators/overloaded/string_indexing.carbon index 622bc0f9e85b..d8fea824c391 100644 --- a/toolchain/check/testdata/operators/overloaded/string_indexing.carbon +++ b/toolchain/check/testdata/operators/overloaded/string_indexing.carbon @@ -14,7 +14,7 @@ library "[[@TEST_NAME]]"; fn TestLiteralNegativeIndex() { - // CHECK:STDERR: fail_literal_negative_index.carbon:[[@LINE+2]]:24-33: error: index `-1` is negative. [StringAtIndexNegative] + // CHECK:STDERR: fail_literal_negative_index.carbon:[[@LINE+2]]:24-33: error: index `-1` is negative [StringAtIndexNegative] // CHECK:STDERR: let unused c: char = "Test"[-1]; } @@ -23,7 +23,7 @@ fn TestLiteralNegativeIndex() { library "[[@TEST_NAME]]"; fn TestLiteralOutOfBounds() { - // CHECK:STDERR: fail_literal_out_of_bounds.carbon:[[@LINE+2]]:24-32: error: string index `4` is out of bounds; string has length 4. [StringAtIndexOutOfBounds] + // CHECK:STDERR: fail_literal_out_of_bounds.carbon:[[@LINE+2]]:24-32: error: string index `4` is out of bounds; string has length 4 [StringAtIndexOutOfBounds] // CHECK:STDERR: let unused c: char = "Test"[4]; } diff --git a/toolchain/driver/link_driver.cpp b/toolchain/driver/link_driver.cpp index fd4cd2d24cdd..3979aa2d2cdd 100644 --- a/toolchain/driver/link_driver.cpp +++ b/toolchain/driver/link_driver.cpp @@ -122,7 +122,7 @@ auto LinkDriver::Link(DriverEnv& driver_env) -> DriverResult { auto path_or_error = std::move(prelude_builder).Build(); if (!path_or_error.ok()) { CARBON_DIAGNOSTIC(LinkCarbonPreludeBuildFailed, Error, - "Failed to build Carbon prelude during linking: {0}", + "failed to build Carbon prelude during linking: {0}", std::string); driver_env.emitter.Emit(LinkCarbonPreludeBuildFailed, path_or_error.error().message()); diff --git a/toolchain/lex/lex.cpp b/toolchain/lex/lex.cpp index bf29c0732156..001be9272a2a 100644 --- a/toolchain/lex/lex.cpp +++ b/toolchain/lex/lex.cpp @@ -1502,21 +1502,21 @@ auto Lexer::LexWordAsDollarIntLiteralToken(llvm::StringRef word, auto diagnose_invalid_char = [&]() { CARBON_DIAGNOSTIC( InvalidCharacterInDollarIntLiteral, Error, - "Positional parameters can only contain digits after `$`"); + "positional parameters can only contain digits after `$`"); emitter_.Emit(word.begin() + 1, InvalidCharacterInDollarIntLiteral); return LexTokenWithPayload(TokenKind::Error, word.size(), byte_offset); }; if (word.size() < 2) { CARBON_DIAGNOSTIC(DollarIntLiteralMissingNumber, Error, - "Expected digits after `$`"); + "expected digits after `$`"); emitter_.Emit(word.begin() + 1, DollarIntLiteralMissingNumber); return LexTokenWithPayload(TokenKind::Error, word.size(), byte_offset); } if (word[1] == '0' && word.size() > 2) { CARBON_DIAGNOSTIC( DollarIntLiteralLeadingZero, Error, - "Leading zeroes are not allowed in positional parameters"); + "leading zeroes are not allowed in positional parameters"); emitter_.Emit(word.begin() + 1, DollarIntLiteralLeadingZero); return LexTokenWithPayload(TokenKind::Error, word.size(), byte_offset); } diff --git a/toolchain/lex/testdata/dollar_int_literals.carbon b/toolchain/lex/testdata/dollar_int_literals.carbon index 29ace510c8e2..c4e9d6b84c14 100644 --- a/toolchain/lex/testdata/dollar_int_literals.carbon +++ b/toolchain/lex/testdata/dollar_int_literals.carbon @@ -26,36 +26,36 @@ $999999999999 // CHECK:STDOUT: - filename: fail_invalid.carbon // CHECK:STDOUT: tokens: -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Expected digits after `$` [DollarIntLiteralMissingNumber] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: expected digits after `$` [DollarIntLiteralMissingNumber] // CHECK:STDERR: $ // CHECK:STDOUT: - { index: 1, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Expected digits after `$` [DollarIntLiteralMissingNumber] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: expected digits after `$` [DollarIntLiteralMissingNumber] // CHECK:STDERR: $ 1 // CHECK:STDOUT: - { index: 2, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$", has_leading_space: true } // CHECK:STDOUT: - { index: 3, kind: "IntLiteral", line: {{ *}}[[@LINE-2]], column: 3, indent: 1, spelling: "1", value: "1", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Positional parameters can only contain digits after `$` [InvalidCharacterInDollarIntLiteral] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: positional parameters can only contain digits after `$` [InvalidCharacterInDollarIntLiteral] // CHECK:STDERR: $foo // CHECK:STDOUT: - { index: 4, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$foo", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Positional parameters can only contain digits after `$` [InvalidCharacterInDollarIntLiteral] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: positional parameters can only contain digits after `$` [InvalidCharacterInDollarIntLiteral] // CHECK:STDERR: $1a32 // CHECK:STDOUT: - { index: 5, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$1a32", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] // CHECK:STDERR: $00 // CHECK:STDOUT: - { index: 6, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$00", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] // CHECK:STDERR: $025321 // CHECK:STDOUT: - { index: 7, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$025321", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] // CHECK:STDERR: $0x12 // CHECK:STDOUT: - { index: 8, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$0x12", has_leading_space: true } -// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: Leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] +// CHECK:STDERR: fail_invalid.carbon:[[@LINE+2]]:2: error: leading zeroes are not allowed in positional parameters [DollarIntLiteralLeadingZero] // CHECK:STDERR: $0b1100 // CHECK:STDOUT: - { index: 9, kind: "Error", line: {{ *}}[[@LINE-1]], column: 1, indent: 1, spelling: "$0b1100", has_leading_space: true } diff --git a/toolchain/parse/handle_binding_pattern.cpp b/toolchain/parse/handle_binding_pattern.cpp index a7008ce6a4ee..abc93e9442ef 100644 --- a/toolchain/parse/handle_binding_pattern.cpp +++ b/toolchain/parse/handle_binding_pattern.cpp @@ -133,7 +133,7 @@ auto HandleBindingPattern(Context& context) -> void { if (state.in_field_shorthand_pattern) { CARBON_DIAGNOSTIC( AnonymousBindingInStructPattern, Error, - "Anonymous binding found in struct pattern. Use `.field = " + "anonymous binding found in struct pattern; use `.field = " "_: field_type` or `unused field: field_type`"); context.emitter().Emit(*context.position(), AnonymousBindingInStructPattern); diff --git a/toolchain/parse/handle_pattern_list.cpp b/toolchain/parse/handle_pattern_list.cpp index da8ef579166b..fbcf8b3ba64f 100644 --- a/toolchain/parse/handle_pattern_list.cpp +++ b/toolchain/parse/handle_pattern_list.cpp @@ -268,7 +268,7 @@ static auto HandlePatternList(Context& context, NodeKind node_kind, if (state.in_field_shorthand_pattern) { if (node_kind == NodeKind::TuplePatternStart) { CARBON_DIAGNOSTIC(NestedTuplePatternInStructPatternShortField, Error, - "Tuple pattern in shorthand struct pattern field. Use " + "tuple pattern in shorthand struct pattern field; use " "`.field = (...)` instead"); context.emitter().Emit(*context.position(), NestedTuplePatternInStructPatternShortField); @@ -276,7 +276,7 @@ static auto HandlePatternList(Context& context, NodeKind node_kind, context.ReturnErrorOnState(); } else if (node_kind == NodeKind::StructPatternStart) { CARBON_DIAGNOSTIC(NestedStructPatternStructPatternShortField, Error, - "Struct pattern in shorthand struct pattern field. Use " + "struct pattern in shorthand struct pattern field; use " "`.field = {{...}` instead"); context.emitter().Emit(*context.position(), NestedStructPatternStructPatternShortField); diff --git a/toolchain/parse/testdata/struct/struct_pattern.carbon b/toolchain/parse/testdata/struct/struct_pattern.carbon index 412054eed925..becd4f88a191 100644 --- a/toolchain/parse/testdata/struct/struct_pattern.carbon +++ b/toolchain/parse/testdata/struct/struct_pattern.carbon @@ -206,31 +206,31 @@ let {"foo" = , .x = x:()} = {}; // --- fail_struct_pattern_nested_tuple_pattern.carbon -// CHECK:STDERR: fail_struct_pattern_nested_tuple_pattern.carbon:[[@LINE+2]]:14: error: Tuple pattern in shorthand struct pattern field. Use `.field = (...)` instead [NestedTuplePatternInStructPatternShortField] +// CHECK:STDERR: fail_struct_pattern_nested_tuple_pattern.carbon:[[@LINE+2]]:14: error: tuple pattern in shorthand struct pattern field; use `.field = (...)` instead [NestedTuplePatternInStructPatternShortField] // CHECK:STDERR: var {x: i32, (y: i32, z: i32)} = {}; // --- fail_struct_pattern_nested_var_tuple_pattern.carbon -// CHECK:STDERR: fail_struct_pattern_nested_var_tuple_pattern.carbon:[[@LINE+2]]:18: error: Tuple pattern in shorthand struct pattern field. Use `.field = (...)` instead [NestedTuplePatternInStructPatternShortField] +// CHECK:STDERR: fail_struct_pattern_nested_var_tuple_pattern.carbon:[[@LINE+2]]:18: error: tuple pattern in shorthand struct pattern field; use `.field = (...)` instead [NestedTuplePatternInStructPatternShortField] // CHECK:STDERR: let {x: i32, var (y: i32, z: i32)} = {}; // --- fail_struct_pattern_nested_struct_pattern.carbon -// CHECK:STDERR: fail_struct_pattern_nested_struct_pattern.carbon:[[@LINE+2]]:13: error: Struct pattern in shorthand struct pattern field. Use `.field = {...}` instead [NestedStructPatternStructPatternShortField] +// CHECK:STDERR: fail_struct_pattern_nested_struct_pattern.carbon:[[@LINE+2]]:13: error: struct pattern in shorthand struct pattern field; use `.field = {...}` instead [NestedStructPatternStructPatternShortField] // CHECK:STDERR: let{x: i32, {y: i32, z: i32}} = {}; // --- fail_struct_pattern_unused_shorthand.carbon -// CHECK:STDERR: fail_struct_pattern_unused_shorthand.carbon:[[@LINE+2]]:7: error: Anonymous binding found in struct pattern. Use `.field = _: field_type` or `unused field: field_type` [AnonymousBindingInStructPattern] +// CHECK:STDERR: fail_struct_pattern_unused_shorthand.carbon:[[@LINE+2]]:7: error: anonymous binding found in struct pattern; use `.field = _: field_type` or `unused field: field_type` [AnonymousBindingInStructPattern] // CHECK:STDERR: var {_: i32} = {}; -// CHECK:STDERR: fail_struct_pattern_unused_shorthand.carbon:[[@LINE+2]]:11: error: Anonymous binding found in struct pattern. Use `.field = _: field_type` or `unused field: field_type` [AnonymousBindingInStructPattern] +// CHECK:STDERR: fail_struct_pattern_unused_shorthand.carbon:[[@LINE+2]]:11: error: anonymous binding found in struct pattern; use `.field = _: field_type` or `unused field: field_type` [AnonymousBindingInStructPattern] // CHECK:STDERR: let {ref _: i32} = {}; -// CHECK:STDERR: fail_struct_pattern_unused_shorthand.carbon:[[@LINE+2]]:11: error: Anonymous binding found in struct pattern. Use `.field = _: field_type` or `unused field: field_type` [AnonymousBindingInStructPattern] +// CHECK:STDERR: fail_struct_pattern_unused_shorthand.carbon:[[@LINE+2]]:11: error: anonymous binding found in struct pattern; use `.field = _: field_type` or `unused field: field_type` [AnonymousBindingInStructPattern] // CHECK:STDERR: let {var _: i32} = {};