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
This commit is contained in:
Richard Smith authored and GitHub committed 2026-10-15 20:15:28 +00:00
1 parent 7beb29f8b2
commit d87891f3a6
11 files changed
+39 -39

No files matched your search

+2 -2
View File
@@ -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,
+3 -3
View File
@@ -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);
@@ -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))));
+2 -2
View File
@@ -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) {});
}
@@ -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];
}
+1 -1
View File
@@ -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());
+3 -3
View File
@@ -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);
}
+8 -8
View File
@@ -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 }
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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);
+6 -6
View File
@@ -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} = {};