Repository: carbon-language/carbon-lang
File: toolchain/check/handle_require.cpp (C++)

Code before:

  return ValidateRequireResult{.constraint_type_id = constraint_type_id,
                               .identified_facet_type = &identified};
}

auto HandleParseNode(Context& context, Parse::RequireDeclId node_id) -> bool {
  auto [constraint_node_id, constraint_inst_id] =
      context.node_stack().PopExprWithNodeId();
  auto [self_node_id, self_inst_id] =
      context.node_stack().PopWithNodeId<Parse::NodeCategory::RequireImpls>();

  auto decl_block_id = context.inst_block_stack().Pop();

  // Process modifiers.
  auto introducer =
      context.decl_introducer_state_stack().Pop<Lex::TokenKind::Require>();
  LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Extend);
  bool extend = introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extend);

  auto scope_inst_id =
      context.node_stack().Pop<Parse::NodeKind::RequireIntroducer>();

  auto validated = ValidateRequire(context, node_id, self_inst_id,
                                   constraint_inst_id, scope_inst_id);
  if (!validated) {
    // In an `extend` decl, errors get propageted into the parent scope just as
    // names do.
    if (extend) {
      context.name_scopes()
          .Get(context.scope_stack().PeekNameScopeId())
          .set_has_error();
    }
    DiscardGenericDecl(context);
    return true;
  }

  auto [constraint_type_id, identified_facet_type] = *validated;
  if (identified_facet_type->required_interfaces().empty()) {
    // A `require T impls type` adds no actual constraints, so nothing to do.
    // This is not an error though.
    DiscardGenericDecl(context);
    return true;
  }

  auto require_impls_decl =
      SemIR::RequireImplsDecl{// To be filled in after.
                              .require_impls_id = SemIR::RequireImplsId::None,
                              .decl_block_id = decl_block_id};
  auto decl_id = AddPlaceholderInst(context, node_id, require_impls_decl);
  auto require_impls_id = context.require_impls().Add(
      {.self_id = self_inst_id,

Review comment (suggestion):
```suggestion
    // In an `extend` decl, errors get propagated into the parent scope just as
```

Code after:

  return ValidateRequireResult{.constraint_type_id = constraint_type_id,
                               .identified_facet_type = &identified};
}

auto HandleParseNode(Context& context, Parse::RequireDeclId node_id) -> bool {
  auto [constraint_node_id, constraint_inst_id] =
      context.node_stack().PopExprWithNodeId();
  auto [self_node_id, self_inst_id] =
      context.node_stack().PopWithNodeId<Parse::NodeCategory::RequireImpls>();

  auto decl_block_id = context.inst_block_stack().Pop();

  // Process modifiers.
  auto introducer =
      context.decl_introducer_state_stack().Pop<Lex::TokenKind::Require>();
  LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Extend);
  bool extend = introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extend);

  auto scope_inst_id =
      context.node_stack().Pop<Parse::NodeKind::RequireIntroducer>();

  auto validated = ValidateRequire(context, node_id, self_inst_id,
                                   constraint_inst_id, scope_inst_id);
  if (!validated) {
    // In an `extend` decl, errors get propagated into the parent scope just as
    // names do.
    if (extend) {
      auto scope_id = context.scope_stack().PeekNameScopeId();
      context.name_scopes().Get(scope_id).set_has_error();
    }
    DiscardGenericDecl(context);
    return true;
  }

  auto [constraint_type_id, identified_facet_type] = *validated;
  if (identified_facet_type->required_interfaces().empty()) {
    // A `require T impls type` adds no actual constraints, so nothing to do.
    // This is not an error though.
    DiscardGenericDecl(context);
    return true;
  }

  auto require_impls_decl =
      SemIR::RequireImplsDecl{// To be filled in after.
                              .require_impls_id = SemIR::RequireImplsId::None,
                              .decl_block_id = decl_block_id};
  auto decl_id = AddPlaceholderInst(context, node_id, require_impls_decl);
  auto require_impls_id = context.require_impls().Add(
      {.self_id = self_inst_id,
       .facet_type_inst_id =