Start every diagnostic with a single message attached to the code (#8102)

This is the final step in landing the _structural_ updates to diagnostic
rendering.

The key idea here is that we want the primary diagnostic to have a
message clearly explaining the problem and attached to the code that has
that problem. This should be the starting point for readers working to
address the issue, but is rendered attached to the code snippet in
question so errors are always "in context" of the code with the error.
Everything else in a diagnostic is an additional label attached to code
to explain or help the reader understand the problem in the primary
message.

Previously, `ContextScope` resulted in some confusion here, as
diagnostic consumers turned messages into labels and made the message in
the context scope the message. In essence, this isn't a scope with
context _for_ a diagnostic (with two exceptions that should probably
have been an `AnnotationScope`), but a context within `check` where we
have a preferred message for a diagnostic emitted by general purpose
code we call into. For example, "class was forward declared here" starts
as an error, and then consumers render it as a label to make the message
from the context scope the error. We also grew an `AnnotationScope` to
handle the contextual information we want to show for a diagnostic (what
I would have assumed `ContextScope` actually did).

Now we have a `Diagnoser`: code in `check` that can better explain the
problem than shared logic it is calling into passes a callback that
builds a caller-specific diagnostic. The callee then can attach relevant
labels and emit it. Diagnostics no longer store `contexts` and consumers
no longer need the logic to restructure things. We move all (but two) of
the old contexts to be normal messages emitted in this way, and we move
some diagnostics to become labels. Each of the new normal messages
corresponds to a new diagnostic kind as usual. Common code following
this pattern now _requires_ the `Diagnoser` to be passed (or emit
nothing), and this uncovered three places where an empty context was
used that made the rendered form miss key information. All three are
fixed with new diagnostics, one already covered by tests, and two with
TODOs to add test coverage.

We also completely remove the old `ContextScope` and
`CARBON_DIAGNOSTIC_CONTEXT` and rename `AnnotationScope` to
`ContextScope`. It is only used to attach information about when/where a
diagnostic occurred.

Labels also no longer have categories. What were `Primary` are now
`ExtraRange`s on the diagnostic rather than labels. Labels are now
always informational.

`DeclaredName` now narrows the range of a label when the range is a
declaration of a named entity to only be the range of that name. For
entities that don't have a declared name, the entire declaration remains
the range. The code building and emitting these diagnostics can skip
them if the declared location isn't distinct from the diagnostic
location.

Wording is largely unchanged here so we can just review the _structural_
change. #7991 iterates using this to improve locations and adds missing
labels. A subsequent PR will iterate on the wording to increasingly fit
within this structural model.

This is separated out as a way to review incrementally, and so that
subsequently we don't have to review wording improvements that only make
sense in a new structure that you cannot see yet. It seems easier to
look at the structure here even with awkward wording.

Assisted-by: Claude Code
This commit is contained in:
Chandler Carruth authored and GitHub committed 2026-11-22 05:19:35 +00:00
1 parent 4729b4473b
commit 0072b28129
378 files changed
+5795 -6998

No files matched your search

@@ -68,7 +68,7 @@ int GArrayVarParam() {
// CHECK:STDERR: · ╰──┤ 'GArrayVarParam' declared here [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ return Carbon::FArrayVarParam({1, 2, 3, 4, 5});
// CHECK:STDERR: · ┳─────────────────────
// CHECK:STDERR: · ┳───────━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: no member named 'FArrayVarParam' in namespace 'Carbon'; did
// CHECK:STDERR: · │ ┃ you mean 'GArrayVarParam'?
// CHECK:STDERR: · │ ┃ [CppInteropParseError]
@@ -81,7 +81,7 @@ int GArrayVarParam() {
// CHECK:STDERR: · ╰──┤ 'GArrayVarParam' declared here [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ return Carbon::FArrayVarParam({1, 2, 3, 4, 5});
// CHECK:STDERR: · ────────────── ┳━━━━━━━━━━━━━━
// CHECK:STDERR: · ━━━━━━━━━━━━━━ ┳━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: too many arguments to function call,
// CHECK:STDERR: · ┃ expected 0, have 1
// CHECK:STDERR: · ┃ [CppInteropParseError]
@@ -120,7 +120,7 @@ int GArrayReturn() {
// CHECK:STDERR: · ╰──┤ 'GArrayReturn' declared here [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ auto &&arr = Carbon::FArrayReturn();
// CHECK:STDERR: · ┳───────────────────
// CHECK:STDERR: · ┳───────━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: no member named 'FArrayReturn' in namespace 'Carbon';
// CHECK:STDERR: · │ ┃ did you mean 'GArrayReturn'?
// CHECK:STDERR: · │ ┃ [CppInteropParseError]
@@ -130,7 +130,7 @@ int GArrayReturn() {
auto &&arr = Carbon::FArrayReturn();
// CHECK:STDERR: ╭─┤ fail_todo_array_return.carbon:[[@LINE+7]]:13
// CHECK:STDERR: -> │ return arr[0];
// CHECK:STDERR: · ──╴╻╶
// CHECK:STDERR: · ━━╸╻╺
// CHECK:STDERR: · ┗━━┫ error: subscripted value is not an array, pointer, or vector
// CHECK:STDERR: · ┃ [CppInteropParseError]
// CHECK:STDERR: ╰────
@@ -53,7 +53,7 @@ void CallFactoryIsMethod() {
// CHECK:STDERR: · │ [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ Carbon::FactoryIsMethod a(42);
// CHECK:STDERR: · ┳ ──
// CHECK:STDERR: · ┳ ━━
// CHECK:STDERR: · ┗━━┫ error: no matching constructor for initialization
// CHECK:STDERR: · ┃ of 'Carbon::FactoryIsMethod' (aka
// CHECK:STDERR: · ┃ 'Carbon::Main::FactoryIsMethod')
@@ -94,7 +94,7 @@ void CallFactoryDoesntReturnSelf() {
// CHECK:STDERR: · │ [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ Carbon::FactoryDoesntReturnSelf a(42);
// CHECK:STDERR: · ┳ ──
// CHECK:STDERR: · ┳ ━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
// CHECK:STDERR: · ┃ error: no matching constructor for initialization of
// CHECK:STDERR: · ┃ 'Carbon::FactoryDoesntReturnSelf' (aka
@@ -136,7 +136,7 @@ void CallFactoryReturnsByRef() {
// CHECK:STDERR: · │ [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ Carbon::FactoryReturnsByRef a(42);
// CHECK:STDERR: · ┳ ──
// CHECK:STDERR: · ┳ ━━
// CHECK:STDERR: · ┗━━┫ error: no matching constructor for
// CHECK:STDERR: · ┃ initialization of
// CHECK:STDERR: · ┃ 'Carbon::FactoryReturnsByRef' (aka
@@ -187,7 +187,7 @@ void CallGenericConstructor() {
// CHECK:STDERR: · │ [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ Carbon::GenericConstructor b(0);
// CHECK:STDERR: · ┳ ─
// CHECK:STDERR: · ┳ ━
// CHECK:STDERR: · ┗━━┫ error: no matching constructor for
// CHECK:STDERR: · ┃ initialization of
// CHECK:STDERR: · ┃ 'Carbon::GenericConstructor' (aka
@@ -231,7 +231,7 @@ void CallGenericClass() {
// CHECK:STDERR: · │ [CppInteropParseNote]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ Carbon::GenericClass<int> c(0);
// CHECK:STDERR: · ┳ ─
// CHECK:STDERR: · ┳ ━
// CHECK:STDERR: · ┗━━┫ error: no matching constructor for
// CHECK:STDERR: · ┃ initialization of
// CHECK:STDERR: · ┃ 'Carbon::GenericClass<int>'
@@ -90,12 +90,11 @@ void CallUsingF() { UsingF(); }
package OtherGeneric;
// CHECK:STDERR: ╷ ╭── imported from: fail_todo_generic.carbon [InImport]
// CHECK:STDERR: ├─┤ other_generic.carbon:[[@LINE+8]]:1
// CHECK:STDERR: ├─┤ other_generic.carbon:[[@LINE+7]]:1
// CHECK:STDERR: -> │ fn HasGenericArg(generic T: type, a: T) { a; }
// CHECK:STDERR: · ━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: 1 argument passed to function expecting 2 arguments
// CHECK:STDERR: · │ ┃ [CallArgCountMismatch]
// CHECK:STDERR: · ╰────┤ calling function declared here [InCallToEntity]
// CHECK:STDERR: · ┃ [CallArgCountMismatch]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
fn HasGenericArg(generic T: type, a: T) { a; }
@@ -142,7 +142,7 @@ void CallEnclosingF() {
Carbon::EnclosingB b;
// CHECK:STDERR: ╭─┤ fail_todo_enclosing_generic.carbon:[[@LINE+7]]:5
// CHECK:STDERR: -> │ b.MemberF(1, 2);
// CHECK:STDERR: · ─ ┳
// CHECK:STDERR: · ━ ┳
// CHECK:STDERR: · ┗━━┫ error: no member named 'MemberF' in 'Carbon::Main::EnclosingA<int>'
// CHECK:STDERR: · ┃ [CppInteropParseError]
// CHECK:STDERR: ╰────
@@ -309,14 +309,12 @@ library "[[@TEST_NAME]]";
import Cpp library "short_param.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_short_param_int32_arg.carbon:[[@LINE+15]]:11
// CHECK:STDERR: ╭─┤ fail_import_short_param_int32_arg.carbon:[[@LINE+13]]:11
// CHECK:STDERR: -> │ Cpp.foo(1 as i32);
// CHECK:STDERR: · ┳━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `i32` to
// CHECK:STDERR: · │ ┃ `i16`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `i32` does not implement interface `Core.ImplicitAs(i16)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `i16`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./short_param.h
// CHECK:STDERR: │ auto foo(short a) -> void;
@@ -62,14 +62,13 @@ library "[[@TEST_NAME]]";
import Cpp library "decl_value_param_type.h";
fn F(p: Cpp.ForwardDeclaredClass*) {
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+19]]:23
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+18]]:23
// CHECK:STDERR: -> │ Cpp.foo_decl_param1(*p);
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: forming value of incomplete type
// CHECK:STDERR: · ┃ `Cpp.ForwardDeclaredClass`
// CHECK:STDERR: · ┃ [IncompleteTypeInValueConversion]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_param_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_param_type.h
// CHECK:STDERR: │ class ForwardDeclaredClass;
// CHECK:STDERR: · ┬
@@ -82,14 +81,13 @@ fn F(p: Cpp.ForwardDeclaredClass*) {
// CHECK:STDERR: ╰────
// CHECK:STDERR:
Cpp.foo_decl_param1(*p);
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+19]]:23
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+18]]:23
// CHECK:STDERR: -> │ Cpp.foo_decl_param2(*p);
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: forming value of incomplete type
// CHECK:STDERR: · ┃ `Cpp.ForwardDeclaredClass`
// CHECK:STDERR: · ┃ [IncompleteTypeInValueConversion]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_param_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_param_type.h
// CHECK:STDERR: │ class ForwardDeclaredClass;
// CHECK:STDERR: · ┬
@@ -479,13 +477,12 @@ library "[[@TEST_NAME]]";
import Cpp library "incomplete.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_incomplete.carbon:[[@LINE+13]]:3
// CHECK:STDERR: ╭─┤ fail_import_incomplete.carbon:[[@LINE+12]]:3
// CHECK:STDERR: -> │ Cpp.Incomplete.foo();
// CHECK:STDERR: · ━━━━━━━━━┳━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: member access into incomplete class `Cpp.Incomplete`
// CHECK:STDERR: · ┃ [QualifiedExprInIncompleteClassScope]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_incomplete.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./incomplete.h
// CHECK:STDERR: │ class Incomplete;
// CHECK:STDERR: · ┬
@@ -575,13 +572,12 @@ library "[[@TEST_NAME]]";
import Cpp library "decl_value_return_type.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_decl_value_return_type.carbon:[[@LINE+18]]:3
// CHECK:STDERR: ╭─┤ fail_import_decl_value_return_type.carbon:[[@LINE+17]]:3
// CHECK:STDERR: -> │ Cpp.foo_decl_value_return();
// CHECK:STDERR: · ━━━━━━━┳━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: function returns incomplete type `Cpp.DeclValueReturnClass`
// CHECK:STDERR: · ┃ [IncompleteTypeInFunctionReturnType]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_return_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_return_type.h
// CHECK:STDERR: │ class DeclValueReturnClass;
// CHECK:STDERR: · ┬
@@ -74,15 +74,12 @@ fn F() {
// CHECK:STDERR:
Cpp.TakesFunction(&n[0]);
// CHECK:STDERR: ╭─┤ fail_todo_call_params_2.carbon:[[@LINE+17]]:21
// CHECK:STDERR: ╭─┤ fail_todo_call_params_2.carbon:[[@LINE+14]]:21
// CHECK:STDERR: -> │ Cpp.TakesFunction(Cpp.nullptr);
// CHECK:STDERR: · ┳━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `Cpp.nullptr_t` to `<C++ type int (*)(int)>`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `Cpp.nullptr_t` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(<C++ type int (*)(int)>)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `Cpp.nullptr_t` to `<C++ type int (*)(int)>`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./params.h
// CHECK:STDERR: │ void TakesFunction(int f(int));
@@ -917,12 +914,12 @@ fn F() {
// CHECK:STDOUT: %.loc36_24.2: %i32 = converted %int_0, %.loc36_24.1 [concrete = constants.%int_0.753]
// CHECK:STDOUT: %.loc36_25: ref %i32 = array_index %n.ref, %.loc36_24.2
// CHECK:STDOUT: %addr: %ptr.a17 = addr_of %.loc36_25
// CHECK:STDOUT: %Cpp.ref.loc55_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %TakesFunction.ref.loc55: %TakesFunction.cpp_overload_set.type = name_ref TakesFunction, imports.%TakesFunction.cpp_overload_set.value [concrete = constants.%TakesFunction.cpp_overload_set.value]
// CHECK:STDOUT: %Cpp.ref.loc55_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %Cpp.ref.loc52_3: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: %TakesFunction.ref.loc52: %TakesFunction.cpp_overload_set.type = name_ref TakesFunction, imports.%TakesFunction.cpp_overload_set.value [concrete = constants.%TakesFunction.cpp_overload_set.value]
// CHECK:STDOUT: %Cpp.ref.loc52_21: <namespace> = name_ref Cpp, imports.%Cpp [concrete = imports.%Cpp]
// CHECK:STDOUT: <elided>
// CHECK:STDOUT: %nullptr.ref: %Cpp.nullptr_t = name_ref nullptr, %uninit [concrete = constants.%uninit]
// CHECK:STDOUT: %.loc55: %.659 = converted %nullptr.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %.loc52: %.659 = converted %nullptr.ref, <error> [concrete = <error>]
// CHECK:STDOUT: %TakesFunction.call: init %empty_tuple.type = call imports.%TakesFunction.decl(<error>)
// CHECK:STDOUT: %Destroy.facet.loc20_3.1: %Destroy.type = facet_value constants.%Array.3b5, (constants.%DestroyImpl.impl_witness.be3, constants.%custom_witness.b80ef6.3) [concrete = constants.%Destroy.facet.843]
// CHECK:STDOUT: %.loc20_3.2: %Destroy.type = converted constants.%Array.3b5, %Destroy.facet.loc20_3.1 [concrete = constants.%Destroy.facet.843]
@@ -165,13 +165,12 @@ library "[[@TEST_NAME]]";
import Cpp library "forward_decl.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_use_forward_decl.carbon:[[@LINE+16]]:3
// CHECK:STDERR: ╭─┤ fail_use_forward_decl.carbon:[[@LINE+15]]:3
// CHECK:STDERR: -> │ Cpp.ReturnCallback()();
// CHECK:STDERR: · ━━━━━━━━━━━┳━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: function returns incomplete type `Cpp.Incomplete`
// CHECK:STDERR: · ┃ [IncompleteTypeInFunctionReturnType]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_use_forward_decl.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./forward_decl.h
// CHECK:STDERR: │ class Incomplete;
// CHECK:STDERR: · ┬
@@ -75,7 +75,7 @@ library "[[@TEST_NAME]]";
import Cpp library "method_ptr.h";
fn F(c: Cpp.C) {
// CHECK:STDERR: ╭─┤ fail_todo_call_method_ptr.carbon:[[@LINE+39]]:3
// CHECK:STDERR: ╭─┤ fail_todo_call_method_ptr.carbon:[[@LINE+36]]:3
// CHECK:STDERR: -> │ c.(Cpp.GetMethodPtr())(42);
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: member name of type `<C++ type void (C::*)(void) const>` in
@@ -84,7 +84,7 @@ fn F(c: Cpp.C) {
// CHECK:STDERR: · ┃ [CompoundMemberAccessDoesNotUseBase]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
// CHECK:STDERR: ╭─┤ fail_todo_call_method_ptr.carbon:[[@LINE+30]]:3
// CHECK:STDERR: ╭─┤ fail_todo_call_method_ptr.carbon:[[@LINE+27]]:3
// CHECK:STDERR: -> │ c.(Cpp.GetMethodPtr())(42);
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: semantics TODO:
@@ -97,21 +97,18 @@ fn F(c: Cpp.C) {
// CHECK:STDERR: · ┃ function pointer
// CHECK:STDERR: · ┃ [CppInteropParseError]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ fail_todo_call_method_ptr.carbon:[[@LINE+17]]:3
// CHECK:STDERR: ├─┤ fail_todo_call_method_ptr.carbon:[[@LINE+14]]:3
// CHECK:STDERR: │ c.(Cpp.GetMethodPtr())(42);
// CHECK:STDERR: · ─────────────┬────────────
// CHECK:STDERR: · ╰──┤ in thunk for C++ function pointer type used here
// CHECK:STDERR: · │ [InCppFunctionPointerThunk]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
// CHECK:STDERR: ╭─┤ fail_todo_call_method_ptr.carbon:[[@LINE+10]]:3
// CHECK:STDERR: ╭─┤ fail_todo_call_method_ptr.carbon:[[@LINE+7]]:3
// CHECK:STDERR: -> │ c.(Cpp.GetMethodPtr())(42);
// CHECK:STDERR: · ━━━━━━━━━━━━━┳━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: 1 argument passed to function expecting 0 arguments
// CHECK:STDERR: · ┃ [CallArgCountMismatch]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ fail_todo_call_method_ptr.carbon
// CHECK:STDERR: · ╰──┤ calling function declared here [InCallToEntity]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
c.(Cpp.GetMethodPtr())(42);
@@ -283,7 +283,7 @@ import Cpp library "struct_init.h";
fn MakeThreeFields() -> {.a: i32, .b: i32, .c: i32};
fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b: i32, .c: i32}) {
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+20]]:23
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+16]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields({.a = 1, .b = 2, .c = 3});
// CHECK:STDERR: · ━━━━━━━━━━━━┳━━━━━━━━━━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
@@ -291,10 +291,6 @@ fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b:
// CHECK:STDERR: · ┃ `{.a: Core.IntLiteral, .b: Core.IntLiteral, .c: Core.IntLiteral}` to
// CHECK:STDERR: · ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: · ╭─────────────────────────────────╯
// CHECK:STDERR: · │ type `{.a: Core.IntLiteral, .b: Core.IntLiteral, .c: Core.IntLiteral}` does
// CHECK:STDERR: · │ not implement interface `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -305,17 +301,13 @@ fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b:
// CHECK:STDERR:
Cpp.PassThreeFields({.a = 1, .b = 2, .c = 3});
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+19]]:23
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+15]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields(value);
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `{.a: i32, .b: i32, .c: i32}` to
// CHECK:STDERR: · │ ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `{.a: i32, .b: i32, .c: i32}` does not
// CHECK:STDERR: · │ implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `{.a: i32, .b: i32, .c: i32}` to
// CHECK:STDERR: · ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -326,17 +318,13 @@ fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b:
// CHECK:STDERR:
Cpp.PassThreeFields(value);
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+19]]:23
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+15]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields(reference);
// CHECK:STDERR: · ┳━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `{.a: i32, .b: i32, .c: i32}` to
// CHECK:STDERR: · │ ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `{.a: i32, .b: i32, .c: i32}` does not
// CHECK:STDERR: · │ implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `{.a: i32, .b: i32, .c: i32}` to
// CHECK:STDERR: · ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -347,17 +335,13 @@ fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b:
// CHECK:STDERR:
Cpp.PassThreeFields(reference);
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+19]]:23
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+15]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields(MakeThreeFields());
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `{.a: i32, .b: i32, .c: i32}` to
// CHECK:STDERR: · │ ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `{.a: i32, .b: i32, .c: i32}` does not
// CHECK:STDERR: · │ implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `{.a: i32, .b: i32, .c: i32}` to
// CHECK:STDERR: · ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -368,7 +352,7 @@ fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b:
// CHECK:STDERR:
Cpp.PassThreeFields(MakeThreeFields());
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+20]]:23
// CHECK:STDERR: ╭─┤ fail_todo_struct_init_nonempty.carbon:[[@LINE+16]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields({.b = 1, .c = 2, .a = 3});
// CHECK:STDERR: · ━━━━━━━━━━━━┳━━━━━━━━━━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
@@ -376,10 +360,6 @@ fn ThreeFields(value: {.a: i32, .b: i32, .c: i32}, ref reference: {.a: i32, .b:
// CHECK:STDERR: · ┃ `{.b: Core.IntLiteral, .c: Core.IntLiteral, .a: Core.IntLiteral}` to
// CHECK:STDERR: · ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: · ╭─────────────────────────────────╯
// CHECK:STDERR: · │ type `{.b: Core.IntLiteral, .c: Core.IntLiteral, .a: Core.IntLiteral}` does
// CHECK:STDERR: · │ not implement interface `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -462,15 +442,12 @@ import Cpp library "struct_init.h";
fn MakeEmpty() -> ();
fn Empty(value: (), ref reference: ()) {
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:20
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:20
// CHECK:STDERR: -> │ Cpp.PassNoFields(());
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `()`
// CHECK:STDERR: · │ ┃ to `Cpp.NoFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `()` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.NoFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ to `Cpp.NoFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassNoFields(NoFields s) -> void;
@@ -481,15 +458,12 @@ fn Empty(value: (), ref reference: ()) {
// CHECK:STDERR:
Cpp.PassNoFields(());
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:20
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:20
// CHECK:STDERR: -> │ Cpp.PassNoFields(value);
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `()`
// CHECK:STDERR: · │ ┃ to `Cpp.NoFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `()` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.NoFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ to `Cpp.NoFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassNoFields(NoFields s) -> void;
@@ -500,15 +474,12 @@ fn Empty(value: (), ref reference: ()) {
// CHECK:STDERR:
Cpp.PassNoFields(value);
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:20
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:20
// CHECK:STDERR: -> │ Cpp.PassNoFields(reference);
// CHECK:STDERR: · ┳━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `()`
// CHECK:STDERR: · │ ┃ to `Cpp.NoFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `()` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.NoFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ to `Cpp.NoFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassNoFields(NoFields s) -> void;
@@ -519,15 +490,12 @@ fn Empty(value: (), ref reference: ()) {
// CHECK:STDERR:
Cpp.PassNoFields(reference);
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:20
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:20
// CHECK:STDERR: -> │ Cpp.PassNoFields(MakeEmpty());
// CHECK:STDERR: · ┳━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `()`
// CHECK:STDERR: · │ ┃ to `Cpp.NoFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `()` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.NoFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ to `Cpp.NoFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassNoFields(NoFields s) -> void;
@@ -542,19 +510,14 @@ fn Empty(value: (), ref reference: ()) {
fn MakeThreeFields() -> (i32, i32, i32);
fn ThreeFields(value: (i32, i32, i32), ref reference: (i32, i32, i32)) {
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+21]]:23
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+16]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields((1, 2, 3));
// CHECK:STDERR: · ┳━━━━━━━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━┛
// CHECK:STDERR: · ━━━━┳━━━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━┛
// CHECK:STDERR: · ┃ error: cannot implicitly convert expression of type
// CHECK:STDERR: · ┃ `(Core.IntLiteral, Core.IntLiteral, Core.IntLiteral)` to
// CHECK:STDERR: · ┃ `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: · ╰──┤ type
// CHECK:STDERR: · │ `(Core.IntLiteral, Core.IntLiteral, Core.IntLiteral)`
// CHECK:STDERR: · │ does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -565,15 +528,12 @@ fn ThreeFields(value: (i32, i32, i32), ref reference: (i32, i32, i32)) {
// CHECK:STDERR:
Cpp.PassThreeFields((1, 2, 3));
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:23
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields(value);
// CHECK:STDERR: · ┳━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `(i32, i32, i32)` to `Cpp.ThreeFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `(i32, i32, i32)` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `(i32, i32, i32)` to `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -584,15 +544,12 @@ fn ThreeFields(value: (i32, i32, i32), ref reference: (i32, i32, i32)) {
// CHECK:STDERR:
Cpp.PassThreeFields(value);
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:23
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields(reference);
// CHECK:STDERR: · ┳━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `(i32, i32, i32)` to `Cpp.ThreeFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `(i32, i32, i32)` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `(i32, i32, i32)` to `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -603,15 +560,12 @@ fn ThreeFields(value: (i32, i32, i32), ref reference: (i32, i32, i32)) {
// CHECK:STDERR:
Cpp.PassThreeFields(reference);
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+17]]:23
// CHECK:STDERR: ╭─┤ fail_struct_init_from_tuple.carbon:[[@LINE+14]]:23
// CHECK:STDERR: -> │ Cpp.PassThreeFields(MakeThreeFields());
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `(i32, i32, i32)` to `Cpp.ThreeFields`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `(i32, i32, i32)` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(Cpp.ThreeFields)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `(i32, i32, i32)` to `Cpp.ThreeFields`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./struct_init.h
// CHECK:STDERR: │ auto PassThreeFields(ThreeFields t) -> void;
@@ -641,15 +595,12 @@ import Cpp library "int_from_struct.h";
fn F() {
// C++ permits `{}` to be used to initialize an int, but Carbon does not.
// CHECK:STDERR: ╭─┤ fail_int_from_struct.carbon:[[@LINE+16]]:15
// CHECK:STDERR: ╭─┤ fail_int_from_struct.carbon:[[@LINE+13]]:15
// CHECK:STDERR: -> │ Cpp.PassInt({});
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `{}` to
// CHECK:STDERR: · │ ┃ `i32`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `{}` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(i32)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `i32`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./int_from_struct.h
// CHECK:STDERR: │ auto PassInt(int n) -> void;
@@ -659,15 +610,12 @@ fn F() {
// CHECK:STDERR:
Cpp.PassInt({});
// CHECK:STDERR: ╭─┤ fail_int_from_struct.carbon:[[@LINE+16]]:15
// CHECK:STDERR: ╭─┤ fail_int_from_struct.carbon:[[@LINE+13]]:15
// CHECK:STDERR: -> │ Cpp.PassInt(());
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type `()` to
// CHECK:STDERR: · │ ┃ `i32`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `()` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(i32)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `i32`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./int_from_struct.h
// CHECK:STDERR: │ auto PassInt(int n) -> void;
@@ -688,15 +636,12 @@ fn F() {
// C++ overload resolution prefers to convert `{}` to `int` rather than to an
// empty struct. So that's the overload we pick, even though we can't call it.
// CHECK:STDERR: ╭─┤ fail_int_from_struct_overloaded.carbon:[[@LINE+17]]:22
// CHECK:STDERR: ╭─┤ fail_int_from_struct_overloaded.carbon:[[@LINE+14]]:22
// CHECK:STDERR: -> │ Cpp.PassOverloaded({});
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `{}` to `i32`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `{}` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(i32)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `{}` to `i32`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./int_from_struct.h
// CHECK:STDERR: │ auto PassOverloaded(int n) -> void;
@@ -707,15 +652,12 @@ fn F() {
// CHECK:STDERR:
Cpp.PassOverloaded({});
// CHECK:STDERR: ╭─┤ fail_int_from_struct_overloaded.carbon:[[@LINE+17]]:22
// CHECK:STDERR: ╭─┤ fail_int_from_struct_overloaded.carbon:[[@LINE+14]]:22
// CHECK:STDERR: -> │ Cpp.PassOverloaded(());
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `()` to `i32`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `()` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(i32)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `()` to `i32`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./int_from_struct.h
// CHECK:STDERR: │ auto PassOverloaded(int n) -> void;
@@ -771,7 +713,7 @@ library "[[@TEST_NAME]]";
import Cpp library "nested_structs.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_todo_pass_nested_structs.carbon:[[@LINE+19]]:13
// CHECK:STDERR: ╭─┤ fail_todo_pass_nested_structs.carbon:[[@LINE+15]]:13
// CHECK:STDERR: -> │ Cpp.TakeB({.a = {.x = 1, .y = 2}, .n = 3});
// CHECK:STDERR: · ━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┛
@@ -779,10 +721,6 @@ fn F() {
// CHECK:STDERR: · ┃ `{.a: {.x: Core.IntLiteral, .y: Core.IntLiteral}, .n: Core.IntLiteral}`
// CHECK:STDERR: · ┃ to `Cpp.B`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: · ╭──────────────────────────╯
// CHECK:STDERR: · │ type `{.a: {.x: Core.IntLiteral, .y: Core.IntLiteral}, .n: Core.IntLiteral}`
// CHECK:STDERR: · │ does not implement interface `Core.ImplicitAs(Cpp.B)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./nested_structs.h
// CHECK:STDERR: │ void TakeB(B);
@@ -822,15 +760,12 @@ library "[[@TEST_NAME]]";
import Cpp library "signedness_change.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_signedness_change_rejected.carbon:[[@LINE+17]]:22
// CHECK:STDERR: ╭─┤ fail_signedness_change_rejected.carbon:[[@LINE+14]]:22
// CHECK:STDERR: -> │ Cpp.signedness_foo(1 as i32);
// CHECK:STDERR: · ┳━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `i32` to `u32`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `i32` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(u32)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `i32` to `u32`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./signedness_change.h
// CHECK:STDERR: │ auto signedness_foo(unsigned int a) -> void;
@@ -853,15 +788,12 @@ library "[[@TEST_NAME]]";
import Cpp library "downsizing_rejected.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_downsizing_rejected.carbon:[[@LINE+17]]:22
// CHECK:STDERR: ╭─┤ fail_import_downsizing_rejected.carbon:[[@LINE+14]]:22
// CHECK:STDERR: -> │ Cpp.downsizing_foo(1 as i32);
// CHECK:STDERR: · ┳━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of type
// CHECK:STDERR: · │ ┃ `i32` to `i16`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `i32` does not implement interface
// CHECK:STDERR: · │ `Core.ImplicitAs(i16)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ `i32` to `i16`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ┆
// CHECK:STDERR: ├─┤ ./downsizing_rejected.h
// CHECK:STDERR: │ auto downsizing_foo(short a) -> void;
@@ -989,9 +921,9 @@ fn EchoValue[ValueT: I](unused generic value: ValueT) {}
fn F() {
// CHECK:STDERR: ╭─┤ fail_missing_impl.carbon:[[@LINE+13]]:3
// CHECK:STDERR: │ fn EchoValue[ValueT: I](unused generic value: ValueT) {}
// CHECK:STDERR: · ─────────────────────────┬─────────────────────────────
// CHECK:STDERR: · ╰──┤ while deducing parameters of generic declared here
// CHECK:STDERR: · │ [DeductionGenericHere]
// CHECK:STDERR: · ────┬────
// CHECK:STDERR: · ╰──┤ while deducing parameters of generic declared here
// CHECK:STDERR: · │ [DeductionGenericHere]
// CHECK:STDERR: ┆
// CHECK:STDERR: -> │ EchoValue(Cpp.missing_impl_foo);
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -425,7 +425,7 @@ import Cpp library "deduced_pointer_param.h";
fn F() {
// This could return a null pointer, so should not be given the type `Cpp.DeducedPointerS*`.
// CHECK:STDERR: ╭─┤ fail_import_deduced_pointer_param_as_optional_pointer.carbon:[[@LINE+14]]:40
// CHECK:STDERR: ╭─┤ fail_import_deduced_pointer_param_as_optional_pointer.carbon:[[@LINE+10]]:40
// CHECK:STDERR: -> │ let unused a: Cpp.DeducedPointerS* = Cpp.Indirect({} as Cpp.DeducedPointerS);
// CHECK:STDERR: · ━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
@@ -433,10 +433,6 @@ fn F() {
// CHECK:STDERR: · ┃ `Core.Optional(Cpp.DeducedPointerS* as Core.OptionalStorage)` to
// CHECK:STDERR: · ┃ `Cpp.DeducedPointerS*`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: · ╭─────────────────────────────────────────────────────────╯
// CHECK:STDERR: · │ type `Core.Optional(Cpp.DeducedPointerS* as Core.OptionalStorage)` does not
// CHECK:STDERR: · │ implement interface `Core.ImplicitAs(Cpp.DeducedPointerS*)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
let unused a: Cpp.DeducedPointerS* = Cpp.Indirect({} as Cpp.DeducedPointerS);
@@ -461,15 +461,12 @@ library "[[@TEST_NAME]]";
import Cpp library "return_const_lvalue_ref.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_call_return_const_lvalue_ref_const_correctness.carbon:[[@LINE+11]]:29
// CHECK:STDERR: ╭─┤ fail_call_return_const_lvalue_ref_const_correctness.carbon:[[@LINE+8]]:29
// CHECK:STDERR: -> │ let unused ref s: Cpp.S = Cpp.ReturnConstLValue();
// CHECK:STDERR: · ┳━━━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: cannot implicitly convert expression of
// CHECK:STDERR: · │ ┃ type `const Cpp.S` to `Cpp.S`
// CHECK:STDERR: · │ ┃ [ConversionFailure]
// CHECK:STDERR: · ╰────┤ type `const Cpp.S` does not implement
// CHECK:STDERR: · │ interface `Core.ImplicitAs(Cpp.S)`
// CHECK:STDERR: · │ [MissingImplInMemberAccessInContext]
// CHECK:STDERR: · ┃ type `const Cpp.S` to `Cpp.S`
// CHECK:STDERR: · ┃ [ConversionFailure]
// CHECK:STDERR: ╰────
// CHECK:STDERR:
let unused ref s: Cpp.S = Cpp.ReturnConstLValue();
@@ -62,14 +62,13 @@ library "[[@TEST_NAME]]";
import Cpp library "decl_value_param_type.h";
fn F(p: Cpp.ForwardDeclaredStruct*) {
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+19]]:12
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+18]]:12
// CHECK:STDERR: -> │ Cpp.foo1(*p);
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: forming value of incomplete type
// CHECK:STDERR: · ┃ `Cpp.ForwardDeclaredStruct`
// CHECK:STDERR: · ┃ [IncompleteTypeInValueConversion]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_param_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_param_type.h
// CHECK:STDERR: │ struct ForwardDeclaredStruct;
// CHECK:STDERR: · ┬
@@ -82,14 +81,13 @@ fn F(p: Cpp.ForwardDeclaredStruct*) {
// CHECK:STDERR: ╰────
// CHECK:STDERR:
Cpp.foo1(*p);
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+19]]:12
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+18]]:12
// CHECK:STDERR: -> │ Cpp.foo2(*p);
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: forming value of incomplete type
// CHECK:STDERR: · ┃ `Cpp.ForwardDeclaredStruct`
// CHECK:STDERR: · ┃ [IncompleteTypeInValueConversion]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_param_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_param_type.h
// CHECK:STDERR: │ struct ForwardDeclaredStruct;
// CHECK:STDERR: · ┬
@@ -350,13 +348,12 @@ library "[[@TEST_NAME]]";
import Cpp library "incomplete.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_incomplete.carbon:[[@LINE+13]]:3
// CHECK:STDERR: ╭─┤ fail_import_incomplete.carbon:[[@LINE+12]]:3
// CHECK:STDERR: -> │ Cpp.IncompleteStruct.foo();
// CHECK:STDERR: · ━━━━━━━━┳━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: member access into incomplete class `Cpp.IncompleteStruct`
// CHECK:STDERR: · ┃ [QualifiedExprInIncompleteClassScope]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_incomplete.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./incomplete.h
// CHECK:STDERR: │ struct IncompleteStruct;
// CHECK:STDERR: · ┬
@@ -447,13 +444,12 @@ library "[[@TEST_NAME]]";
import Cpp library "decl_value_return_type.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_decl_value_return_type.carbon:[[@LINE+18]]:3
// CHECK:STDERR: ╭─┤ fail_import_decl_value_return_type.carbon:[[@LINE+17]]:3
// CHECK:STDERR: -> │ Cpp.foo_decl_value_return();
// CHECK:STDERR: · ━━━━━━┳━━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: function returns incomplete type `Cpp.DeclValueReturnStruct`
// CHECK:STDERR: · ┃ [IncompleteTypeInFunctionReturnType]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_return_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_return_type.h
// CHECK:STDERR: │ struct DeclValueReturnStruct;
// CHECK:STDERR: · ┬
@@ -62,14 +62,13 @@ library "[[@TEST_NAME]]";
import Cpp library "decl_value_param_type.h";
fn F(p: Cpp.ForwardDeclaredUnion*) {
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+19]]:12
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+18]]:12
// CHECK:STDERR: -> │ Cpp.foo1(*p);
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: forming value of incomplete type
// CHECK:STDERR: · ┃ `Cpp.ForwardDeclaredUnion`
// CHECK:STDERR: · ┃ [IncompleteTypeInValueConversion]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_param_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_param_type.h
// CHECK:STDERR: │ union ForwardDeclaredUnion;
// CHECK:STDERR: · ┬
@@ -82,14 +81,13 @@ fn F(p: Cpp.ForwardDeclaredUnion*) {
// CHECK:STDERR: ╰────
// CHECK:STDERR:
Cpp.foo1(*p);
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+19]]:12
// CHECK:STDERR: ╭─┤ fail_import_decl_value_param_type.carbon:[[@LINE+18]]:12
// CHECK:STDERR: -> │ Cpp.foo2(*p);
// CHECK:STDERR: · ┳━
// CHECK:STDERR: · ┗━━┫ error: forming value of incomplete type
// CHECK:STDERR: · ┃ `Cpp.ForwardDeclaredUnion`
// CHECK:STDERR: · ┃ [IncompleteTypeInValueConversion]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_param_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_param_type.h
// CHECK:STDERR: │ union ForwardDeclaredUnion;
// CHECK:STDERR: · ┬
@@ -306,13 +304,12 @@ library "[[@TEST_NAME]]";
import Cpp library "incomplete.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_incomplete.carbon:[[@LINE+13]]:3
// CHECK:STDERR: ╭─┤ fail_import_incomplete.carbon:[[@LINE+12]]:3
// CHECK:STDERR: -> │ Cpp.IncompleteUnion.foo();
// CHECK:STDERR: · ━━━━━━━━━┳━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: member access into incomplete class `Cpp.IncompleteUnion`
// CHECK:STDERR: · ┃ [QualifiedExprInIncompleteClassScope]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_incomplete.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./incomplete.h
// CHECK:STDERR: │ union IncompleteUnion;
// CHECK:STDERR: · ┬
@@ -402,13 +399,12 @@ library "[[@TEST_NAME]]";
import Cpp library "decl_value_return_type.h";
fn F() {
// CHECK:STDERR: ╭─┤ fail_import_decl_value_return_type.carbon:[[@LINE+18]]:3
// CHECK:STDERR: ╭─┤ fail_import_decl_value_return_type.carbon:[[@LINE+17]]:3
// CHECK:STDERR: -> │ Cpp.foo_decl_value_return();
// CHECK:STDERR: · ━━━━━━━┳━━━━━━━━━━━━━━━━━━━
// CHECK:STDERR: · ┗━━┫ error: function returns incomplete type `Cpp.DeclValueReturnUnion`
// CHECK:STDERR: · ┃ [IncompleteTypeInFunctionReturnType]
// CHECK:STDERR: ┆
// CHECK:STDERR: │ ╭── included from: fail_import_decl_value_return_type.carbon [InCppInclude]
// CHECK:STDERR: ├─┤ ./decl_value_return_type.h
// CHECK:STDERR: │ union DeclValueReturnUnion;
// CHECK:STDERR: · ┬