mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:10:14 +01:00
Per [#toolchain discussion](https://discord.com/channels/655572317891461132/655578254970716160/1176632520834560211) We'd at one point been trying to put `[[nodiscard]]` everywhere, but then we stopped because it had felt verbose without finding many issues (plus, people plain forgot to add it). Some history in #888. Since newer code gets added without it, we now have code like: ``` auto GetLineInfo(Line line) -> LineInfo&; [[nodiscard]] auto GetLineInfo(Line line) const -> const LineInfo&; auto AddLine(LineInfo info) -> Line; auto GetTokenInfo(Token token) -> TokenInfo&; [[nodiscard]] auto GetTokenInfo(Token token) const -> const TokenInfo&; auto AddToken(TokenInfo info) -> Token; [[nodiscard]] auto GetTokenPrintWidths(Token token) const -> PrintWidths; ``` Here, the lack of `[[nodiscard]]` doesn't mean anything: for example, `GetLineInfo` should not have its result discarded if it's called. But the mix could be confusing for readers. As a resolution, remove the attribute. `[[nodiscard]]` should be treated like other attributes going forward, which essentially means "avoid in general, add a comment to explain why the attribute is needed" rather than use-as-default.