mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 19:58:11 +00:00
Adopt ref in Core.Iterate.Next (#7381)
Change the `cursor` parameter in `Core.Iterate.Next` to be a `ref` parameter instead of a pointer parameter. Assisted-by: Gemini via Antigravity --------- Co-authored-by: Geoff Romer <gromer@google.com>
This commit is contained in:
1 parent
72e425fe5c
commit
df3cf92943
14 files changed
+703
-675
No files matched your search
@@ -222,20 +222,15 @@ auto HandleParseNode(Context& context, Parse::ForHeaderId node_id) -> bool {
|
||||
auto loop_header_id = StartLoopHeader(context, start_node_id);
|
||||
auto continue_depth = context.scope_stack().ambient_cleanup_scope_depth();
|
||||
|
||||
// Call `<range>.(Iterate.Next)(&cursor)`.
|
||||
auto cursor_type_inst_id = context.types().GetTypeInstId(cursor_type_id);
|
||||
auto cursor_addr_id = AddInst<SemIR::AddrOf>(
|
||||
context, node_id,
|
||||
{.type_id = GetPointerType(context, cursor_type_inst_id),
|
||||
.lvalue_id = cursor_var_id});
|
||||
// A range that implements neither fails both lookups; reporting the second
|
||||
// would say the same thing about the same expression a second time.
|
||||
// Call `<range>.(Iterate.Next)(ref cursor)`.
|
||||
// Don't diagnose if the call to `Iterate.NewCursor` failed, since this call
|
||||
// will likely also fail for the same reason.
|
||||
// TODO: We should only perform the impl lookup once.
|
||||
auto element_id =
|
||||
BuildBinaryOperator(context, node_id,
|
||||
{.interface_name = CoreIdentifier::Iterate,
|
||||
.op_name = CoreIdentifier::Next},
|
||||
range_id, cursor_addr_id,
|
||||
range_id, cursor_var_id,
|
||||
/*diagnose=*/cursor_id != SemIR::ErrorInst::InstId);
|
||||
// We need to convert away from an initializing expression in order to call
|
||||
// `HasValue` and then separately pattern-match against the element.
|
||||
|
||||
Reference in new issue
Block a user