-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
discussion/tracking issue for #[must_use] functions in the standard library #48926
Copy link
Copy link
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
RFC 1940 authorized use of the
#[must_use]attribute on functions (with the result that invocations of the function behave as if the return type was#[must_use].This has been implemented for a while under a
fn_must_usefeature gate (tracking issue), and PR #48925 proposes stabilization.#[must_use]has been added to the comparison methods in the standard library (.eq,.lt, &c.), but we never got a consensus as to what other standard library methods, if any, should get it. In principle, any function or with no side effects could be must-use (e.g.,.len()on collections), but adding dozens or hundreds of annotations to the standard library feels kind of dramatic: perhaps must-use should instead be reserved for functions with "unusually result-like" semantics—after all, users who want to be really sure they're not uselessly throwing away a return value can always opt in to the (allow-by-default)unused-resultslint.If we wanted to be very conservative, we could refuse to stabilize until we've made a decision on this: if we were to stabilize first, any new
#[must_use]annotations in the standard library would be insta-stable. But, maybe this isn't a big deal (cargopassescap-lints allowto dependencies, so tinkering with lints shouldn't break people's builds).