Repository: carbon-language/carbon-lang
File: toolchain/sem_ir/name_scope.h (C/C++)

Code before:

  static auto MakeWrappedLookupResult(InstId target_inst_id,
                                      AccessKind access_kind)
      -> ScopeLookupResult {
    return ScopeLookupResult(target_inst_id, access_kind);
  }

  // True iff CreatePoisoned() was used.
  auto is_poisoned() const -> bool { return is_poisoned_; }

  // True when lookup was successful or resulted with an error. False for
  // poisoned or not found.
  auto is_found() const -> bool {
    return !is_poisoned() && target_inst_id_.has_value();
  }

  // The `InstId` of the result of the lookup. Must only be called when lookup
  // was successful e.g. `is_found()` returns true. Always returns an existing
  // `InstId`.
  auto target_inst_id() const -> InstId {
    CARBON_CHECK(is_found());
    return target_inst_id_;
  }

  // The `LocId` where the name poisoning was triggered. Must only be called
  // when lookup resulted with a poisoned name e.g. `is_poisoned()` returns
  // true. Always returns an existing `InstId`.
  auto poisoning_loc_id() const -> LocId {
    CARBON_CHECK(is_poisoned());
    return poisoning_loc_id_;
  }

  auto access_kind() const -> AccessKind { return access_kind_; }

  // Equality means either:
  // - Both are not poisoned and have the same `InstId` and `AccessKind`.
  // - Both are poisoned and have the same `LocId`.
  friend auto operator==(const ScopeLookupResult& lhs,
                         const ScopeLookupResult& rhs) -> bool {
    return lhs.is_poisoned_ == rhs.is_poisoned_ &&
           (lhs.is_poisoned_ ? lhs.poisoning_loc_id_ == rhs.poisoning_loc_id_
                             : lhs.target_inst_id_ == rhs.target_inst_id_ &&
                                   lhs.access_kind_ == rhs.access_kind_);
  }

 private:
  explicit ScopeLookupResult(InstId target_inst_id, AccessKind access_kind)
      : target_inst_id_(target_inst_id),
        access_kind_(access_kind),
        is_poisoned_(false) {}


Review comment (bug):
```suggestion
  // when lookup returned a poisoned name; in other words, when `is_poisoned()` returns
```

"e.g." means "for example"
"i.e." means "that is" or "in other words"

I think "for example" is incorrect here; "is_poisoned" is instead restating the same thing in a different way. It may be helpful to avoid the abbreviation. (plus other minor grammar)

Code after:

  static auto MakeWrappedLookupResult(InstId target_inst_id,
                                      AccessKind access_kind)
      -> ScopeLookupResult {
    return ScopeLookupResult(target_inst_id, access_kind);
  }

  // True iff CreatePoisoned() was used.
  auto is_poisoned() const -> bool { return is_poisoned_; }

  // True when lookup was successful or resulted with an error. False for
  // poisoned or not found.
  auto is_found() const -> bool {
    return !is_poisoned() && target_inst_id_.has_value();
  }

  // The `InstId` of the result of the lookup. Must only be called when lookup
  // was successful; in other words, when `is_found()` returns true. Always
  // returns an existing `InstId`.
  auto target_inst_id() const -> InstId {
    CARBON_CHECK(is_found());
    return target_inst_id_;
  }

  // The `LocId` where the name poisoning was triggered. Must only be called
  // when lookup returned a poisoned name; in other words, when `is_poisoned()`
  // returns true. Always returns an existing `InstId`.
  auto poisoning_loc_id() const -> LocId {
    CARBON_CHECK(is_poisoned());
    return poisoning_loc_id_;
  }

  auto access_kind() const -> AccessKind { return access_kind_; }

  // Equality means either:
  // - Both are not poisoned and have the same `InstId` and `AccessKind`.
  // - Both are poisoned and have the same `LocId`.
  friend auto operator==(const ScopeLookupResult& lhs,
                         const ScopeLookupResult& rhs) -> bool {
    return lhs.is_poisoned_ == rhs.is_poisoned_ &&
           lhs.access_kind_ == rhs.access_kind_ &&
           (lhs.is_poisoned_ ? lhs.poisoning_loc_id_ == rhs.poisoning_loc_id_
                             : lhs.target_inst_id_ == rhs.target_inst_id_);
  }

 private:
  explicit ScopeLookupResult(InstId target_inst_id, AccessKind access_kind)
      : target_inst_id_(target_inst_id),
        access_kind_(access_kind),
        is_poisoned_(false) {}