Просмотр исходного кода

When diagnosing a duplicate name, point to the name instead of the instruction (#4953)

Left TODOs where more work is necessary before this change can be
applied or its impact can be verified.

Includes #4952, to avoid regression in some cases.

Similar to #4938. See
https://discord.com/channels/655572317891461132/655578254970716160/1339007384361762857.
Boaz Brickner 1 год назад
Родитель
Сommit
dd7c64bad0
24 измененных файлов с 58 добавлено и 50 удалено
  1. 1 1
      toolchain/check/decl_name_stack.cpp
  2. 1 1
      toolchain/check/handle_binding_pattern.cpp
  3. 1 1
      toolchain/check/handle_class.cpp
  4. 5 4
      toolchain/check/handle_function.cpp
  5. 1 1
      toolchain/check/handle_interface.cpp
  6. 2 2
      toolchain/check/handle_namespace.cpp
  7. 4 0
      toolchain/check/import.cpp
  8. 1 0
      toolchain/check/import_ref.cpp
  9. 2 0
      toolchain/check/name_lookup.cpp
  10. 2 2
      toolchain/check/testdata/class/no_prelude/implicit_import.carbon
  11. 2 2
      toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon
  12. 2 2
      toolchain/check/testdata/generic/local.carbon
  13. 4 4
      toolchain/check/testdata/interface/fail_todo_define_default_fn_out_of_line.carbon
  14. 2 2
      toolchain/check/testdata/interface/no_prelude/fail_definition_imported.carbon
  15. 4 4
      toolchain/check/testdata/interface/no_prelude/fail_duplicate.carbon
  16. 2 2
      toolchain/check/testdata/interface/no_prelude/fail_redeclare_member.carbon
  17. 2 2
      toolchain/check/testdata/interface/no_prelude/fail_todo_generic_default_fn.carbon
  18. 6 6
      toolchain/check/testdata/interface/no_prelude/syntactic_merge.carbon
  19. 2 2
      toolchain/check/testdata/interop/cpp/no_prelude/cpp_namespace.carbon
  20. 4 4
      toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon
  21. 2 2
      toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon
  22. 2 2
      toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon
  23. 2 2
      toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon
  24. 2 2
      toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon

+ 1 - 1
toolchain/check/decl_name_stack.cpp

@@ -180,7 +180,7 @@ auto DeclNameStack::AddNameOrDiagnose(NameContext name_context,
     DiagnosePoisonedName(*context_, name_context.poisoning_loc_id,
                          name_context.loc_id);
   } else if (auto id = name_context.prev_inst_id(); id.has_value()) {
-    DiagnoseDuplicateName(*context_, target_id, id);
+    DiagnoseDuplicateName(*context_, name_context.loc_id, id);
   } else {
     AddName(name_context, target_id, access_kind);
   }

+ 1 - 1
toolchain/check/handle_binding_pattern.cpp

@@ -78,7 +78,7 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
       context.scope_stack().PushCompileTimeBinding(bind_id);
     }
     auto name_context =
-        context.decl_name_stack().MakeUnqualifiedName(node_id, name_id);
+        context.decl_name_stack().MakeUnqualifiedName(name_node, name_id);
     context.decl_name_stack().AddNameOrDiagnose(
         name_context, bind_id, introducer.modifier_set.GetAccessKind());
     context.full_pattern_stack().AddBindName(name_id);

+ 1 - 1
toolchain/check/handle_class.cpp

@@ -163,7 +163,7 @@ static auto MergeOrAddName(Context& context, Parse::AnyClassDeclId node_id,
 
   if (!prev_class_id.has_value()) {
     // This is a redeclaration of something other than a class.
-    DiagnoseDuplicateName(context, class_decl_id, prev_id);
+    DiagnoseDuplicateName(context, name_context.loc_id, prev_id);
     return;
   }
 

+ 5 - 4
toolchain/check/handle_function.cpp

@@ -138,7 +138,7 @@ static auto MergeFunctionRedecl(Context& context,
 
 // Check whether this is a redeclaration, merging if needed.
 static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id,
-                           SemIR::InstId prev_id,
+                           SemIR::InstId prev_id, SemIR::LocId name_loc_id,
                            SemIR::FunctionDecl& function_decl,
                            SemIR::Function& function_info, bool is_definition)
     -> void {
@@ -179,7 +179,7 @@ static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id,
   }
 
   if (!prev_function_id.has_value()) {
-    DiagnoseDuplicateName(context, function_info.latest_decl_id(), prev_id);
+    DiagnoseDuplicateName(context, name_loc_id, prev_id);
     return;
   }
 
@@ -295,8 +295,9 @@ static auto BuildFunctionDecl(Context& context,
     DiagnosePoisonedName(context, name_context.poisoning_loc_id,
                          name_context.loc_id);
   } else {
-    TryMergeRedecl(context, node_id, name_context.prev_inst_id(), function_decl,
-                   function_info, is_definition);
+    TryMergeRedecl(context, node_id, name_context.prev_inst_id(),
+                   name_context.loc_id, function_decl, function_info,
+                   is_definition);
   }
 
   // Create a new function if this isn't a valid redeclaration.

+ 1 - 1
toolchain/check/handle_interface.cpp

@@ -104,7 +104,7 @@ static auto BuildInterfaceDecl(Context& context,
       }
     } else {
       // This is a redeclaration of something other than a interface.
-      DiagnoseDuplicateName(context, interface_decl_id, existing_id);
+      DiagnoseDuplicateName(context, name_context.loc_id, existing_id);
     }
   }
 

+ 2 - 2
toolchain/check/handle_namespace.cpp

@@ -64,7 +64,7 @@ auto HandleParseNode(Context& context, Parse::NamespaceId node_id) -> bool {
               .Get(existing->name_scope_id)
               .is_closed_import()) {
         // The existing name is a package name, so this is a name conflict.
-        DiagnoseDuplicateName(context, namespace_id, existing_inst_id);
+        DiagnoseDuplicateName(context, name_context.loc_id, existing_inst_id);
 
         // Treat this as a local namespace name from now on to avoid further
         // diagnostics.
@@ -78,7 +78,7 @@ auto HandleParseNode(Context& context, Parse::NamespaceId node_id) -> bool {
         context.SetNamespaceNodeId(existing_inst_id, node_id);
       }
     } else {
-      DiagnoseDuplicateName(context, namespace_id, existing_inst_id);
+      DiagnoseDuplicateName(context, name_context.loc_id, existing_inst_id);
     }
   }
 

+ 4 - 0
toolchain/check/import.cpp

@@ -107,6 +107,8 @@ auto AddImportNamespace(Context& context, SemIR::TypeId namespace_type_id,
         if (diagnose_duplicate_namespace) {
           auto import_id = make_import_id();
           CARBON_CHECK(import_id.has_value());
+          // TODO: Pass the import package name location instead of the import
+          // id to get more accurate location.
           DiagnoseDuplicateName(context, import_id, prev_inst_id);
         }
         return {.name_scope_id = namespace_inst->name_scope_id,
@@ -148,6 +150,8 @@ auto AddImportNamespace(Context& context, SemIR::TypeId namespace_type_id,
   // may be overwriting a poisoned entry here.
   auto& result = parent_scope->GetEntry(entry_id).result;
   if (!result.is_poisoned() && !inserted) {
+    // TODO: Pass the import namespace name location instead of the namespace id
+    // to get more accurate location.
     DiagnoseDuplicateName(context, namespace_id, result.target_inst_id());
   }
   result = SemIR::ScopeLookupResult::MakeFound(namespace_id,

+ 1 - 0
toolchain/check/import_ref.cpp

@@ -149,6 +149,7 @@ auto VerifySameCanonicalImportIRInst(Context& context, SemIR::InstId prev_id,
   }
   auto conflict_id =
       AddImportRef(context, {.ir_id = new_ir_id, .inst_id = new_inst_id});
+  // TODO: Pass the imported name location instead of the conflict id.
   DiagnoseDuplicateName(context, conflict_id, prev_id);
 }
 

+ 2 - 0
toolchain/check/name_lookup.cpp

@@ -17,6 +17,8 @@ auto AddNameToLookup(Context& context, SemIR::NameId name_id,
   if (auto existing = context.scope_stack().LookupOrAddName(name_id, target_id,
                                                             scope_index);
       existing.has_value()) {
+    // TODO: Add coverage to this use case and use the location of the name
+    // instead of the target.
     DiagnoseDuplicateName(context, target_id, existing);
   }
 }

+ 2 - 2
toolchain/check/testdata/class/no_prelude/implicit_import.carbon

@@ -71,9 +71,9 @@ alias B = C;
 
 impl library "[[@TEST_NAME]]";
 
-// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:7: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: class B {}
-// CHECK:STDERR: ^~~~~~~~~
+// CHECK:STDERR:       ^
 // CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE-5]]:6: in import [InImport]
 // CHECK:STDERR: def_alias.carbon:5:7: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: alias B = C;

+ 2 - 2
toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon

@@ -111,9 +111,9 @@ alias B = A;
 
 impl library "[[@TEST_NAME]]";
 
-// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn B() {}
-// CHECK:STDERR: ^~~~~~~~
+// CHECK:STDERR:    ^
 // CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE-5]]:6: in import [InImport]
 // CHECK:STDERR: def_alias.carbon:5:7: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: alias B = A;

+ 2 - 2
toolchain/check/testdata/generic/local.carbon

@@ -25,9 +25,9 @@ library "[[@TEST_NAME]]";
 
 fn F() {
   // TODO: Decide on what behavior we want here. We don't reject the corresponding case outside of a function.
-  // CHECK:STDERR: fail_param_shadows_class.carbon:[[@LINE+7]]:3: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+  // CHECK:STDERR: fail_param_shadows_class.carbon:[[@LINE+7]]:9: error: duplicate name being declared in the same scope [NameDeclDuplicate]
   // CHECK:STDERR:   class C(C:! type) {
-  // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~
+  // CHECK:STDERR:         ^
   // CHECK:STDERR: fail_param_shadows_class.carbon:[[@LINE+4]]:11: note: name is previously declared here [NameDeclPrevious]
   // CHECK:STDERR:   class C(C:! type) {
   // CHECK:STDERR:           ^

+ 4 - 4
toolchain/check/testdata/interface/fail_todo_define_default_fn_out_of_line.carbon

@@ -24,18 +24,18 @@ interface Interface {
   default fn G(a: i32, b: i32) -> i32;
 }
 
-// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:14: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn Interface.F() {}
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:              ^
 // CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE-12]]:3: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR:   default fn F();
 // CHECK:STDERR:   ^~~~~~~~~~~~~~~
 // CHECK:STDERR:
 fn Interface.F() {}
 
-// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:14: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn Interface.G(a: i32, b: i32) -> i32 = "int.sadd";
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:              ^
 // CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE-15]]:3: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR:   default fn G(a: i32, b: i32) -> i32;
 // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 2 - 2
toolchain/check/testdata/interface/no_prelude/fail_definition_imported.carbon

@@ -19,9 +19,9 @@ interface I;
 library "[[@TEST_NAME]]";
 import library "a";
 
-// CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: interface I {}
-// CHECK:STDERR: ^~~~~~~~~~~~~
+// CHECK:STDERR:           ^
 // CHECK:STDERR: fail_b.carbon:[[@LINE-5]]:1: in import [InImport]
 // CHECK:STDERR: a.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: interface I;

+ 4 - 4
toolchain/check/testdata/interface/no_prelude/fail_duplicate.carbon

@@ -48,9 +48,9 @@ library "[[@TEST_NAME]]";
 
 fn Function();
 
-// CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: interface Function;
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~~~~~~
 // CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: fn Function();
 // CHECK:STDERR: ^~~~~~~~~~~~~~
@@ -61,9 +61,9 @@ interface Function;
 
 class Class;
 
-// CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: interface Class { }
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~~~
 // CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: class Class;
 // CHECK:STDERR: ^~~~~~~~~~~~

+ 2 - 2
toolchain/check/testdata/interface/no_prelude/fail_redeclare_member.carbon

@@ -10,9 +10,9 @@
 
 interface Interface {
   fn F();
-  // CHECK:STDERR: fail_redeclare_member.carbon:[[@LINE+7]]:3: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+  // CHECK:STDERR: fail_redeclare_member.carbon:[[@LINE+7]]:6: error: duplicate name being declared in the same scope [NameDeclDuplicate]
   // CHECK:STDERR:   fn F();
-  // CHECK:STDERR:   ^~~~~~~
+  // CHECK:STDERR:      ^
   // CHECK:STDERR: fail_redeclare_member.carbon:[[@LINE-4]]:3: note: name is previously declared here [NameDeclPrevious]
   // CHECK:STDERR:   fn F();
   // CHECK:STDERR:   ^~~~~~~

+ 2 - 2
toolchain/check/testdata/interface/no_prelude/fail_todo_generic_default_fn.carbon

@@ -13,9 +13,9 @@ interface I(T:! type) {
   fn F[self: Self]() -> Self;
 }
 
-// CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE+7]]:16: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn I(T:! type).F[self: Self]() -> Self { return self; }
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:                ^
 // CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE-6]]:3: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR:   fn F[self: Self]() -> Self;
 // CHECK:STDERR:   ^~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 6 - 6
toolchain/check/testdata/interface/no_prelude/syntactic_merge.carbon

@@ -69,18 +69,18 @@ interface Bar(a:! D);
 
 impl library "[[@TEST_NAME]]";
 
-// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: interface Foo(a:! C) {}
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~
 // CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE-5]]:6: in import [InImport]
 // CHECK:STDERR: two_file.carbon:7:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: interface Foo(a:! C);
 // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
 // CHECK:STDERR:
 interface Foo(a:! C) {}
-// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: interface Bar(a:! D) {}
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~
 // CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE-14]]:6: in import [InImport]
 // CHECK:STDERR: two_file.carbon:8:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: interface Bar(a:! D);
@@ -156,9 +156,9 @@ alias D = C;
 // TODO: This fails because importing interfaces doesn't work well. It should
 // fail due to `C` versus `D`, but may succeed if importing interfaces is fixed
 // before syntax matching on imports is supported.
-// CHECK:STDERR: fail_alias_two_file.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_alias_two_file.impl.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: interface Foo(a:! D) {}
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~
 // CHECK:STDERR: fail_alias_two_file.impl.carbon:[[@LINE-10]]:6: in import [InImport]
 // CHECK:STDERR: alias_two_file.carbon:6:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: interface Foo(a:! C);

+ 2 - 2
toolchain/check/testdata/interop/cpp/no_prelude/cpp_namespace.carbon

@@ -16,9 +16,9 @@ library "[[@TEST_NAME]]";
 
 import Cpp library "header.h";
 
-// CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: namespace Cpp;
-// CHECK:STDERR: ^~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~
 // CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: import Cpp library "header.h";
 // CHECK:STDERR: ^~~~~~

+ 4 - 4
toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon

@@ -24,9 +24,9 @@ import library "namespace";
 // imported declaration.
 namespace NS;
 
-// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn NS();
-// CHECK:STDERR: ^~~~~~~~
+// CHECK:STDERR:    ^~
 // CHECK:STDERR: fail_conflict.carbon:[[@LINE-9]]:1: in import [InImport]
 // CHECK:STDERR: namespace.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: namespace NS;
@@ -38,9 +38,9 @@ fn NS();
 // we don't move it.
 namespace NS;
 
-// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn NS();
-// CHECK:STDERR: ^~~~~~~~
+// CHECK:STDERR:    ^~
 // CHECK:STDERR: fail_conflict.carbon:[[@LINE-23]]:1: in import [InImport]
 // CHECK:STDERR: namespace.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: namespace NS;

+ 2 - 2
toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon

@@ -20,9 +20,9 @@ package Example;
 
 import library "namespace";
 
-// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: fn NS();
-// CHECK:STDERR: ^~~~~~~~
+// CHECK:STDERR:    ^~
 // CHECK:STDERR: fail_conflict.carbon:[[@LINE-5]]:1: in import [InImport]
 // CHECK:STDERR: namespace.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: namespace NS;

+ 2 - 2
toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon

@@ -16,9 +16,9 @@ namespace Nested;
 // --- fail_conflict.carbon
 
 import Other;
-// CHECK:STDERR: fail_conflict.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_conflict.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: namespace Other;
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~~~
 // CHECK:STDERR: fail_conflict.carbon:[[@LINE-4]]:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: import Other;
 // CHECK:STDERR: ^~~~~~

+ 2 - 2
toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon

@@ -20,9 +20,9 @@ package Example;
 
 import library "fn";
 
-// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: namespace NS;
-// CHECK:STDERR: ^~~~~~~~~~~~~
+// CHECK:STDERR:           ^~
 // CHECK:STDERR: fail_conflict.carbon:[[@LINE-5]]:1: in import [InImport]
 // CHECK:STDERR: fn.carbon:4:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: fn NS();

+ 2 - 2
toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon

@@ -150,9 +150,9 @@ library "[[@TEST_NAME]]";
 
 import Other library "other_fn";
 
-// CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate]
+// CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate]
 // CHECK:STDERR: namespace Other;
-// CHECK:STDERR: ^~~~~~~~~~~~~~~~
+// CHECK:STDERR:           ^~~~~
 // CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious]
 // CHECK:STDERR: import Other library "other_fn";
 // CHECK:STDERR: ^~~~~~