-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make String a must_use type #75934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make String a must_use type #75934
Conversation
@@ -472,7 +472,7 @@ impl DocFolder for Cache { | |||
}); | |||
|
|||
if pushed { | |||
self.stack.pop().expect("stack already empty"); | |||
let _ = self.stack.pop().expect("stack already empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think lines like this are a good example of why String
and Vec<T>
aren't must_use
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These cases are rare in Rustc codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @scottmcm here. If it's on String, then it should be on Vec too, and if it's on Vec, then it should also be on every container. At which point you'd have to somewhat argue why it's not on basically everything that's not Copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With all respects, I just want some actions on resolving #75742 . If the team doesn't like this approach,
what about marking String::from
, str::into
, fmt::format
with must_use
attr?
a3d3a08
to
0bcc7d6
Compare
0bcc7d6
to
962e564
Compare
@rustbot modify labels: T-libs +S-waiting-on-review |
r? @dtolnay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @scottmcm above. A String being present in a return value does not mean it's a newly allocated string that you could hope to optimize away when unused, as implied by the PR's must_use message of "unused allocation might not be optimized out by compiler"
. I am concerned that must_use has been trending noisier and noisier as it appears in increasingly questionable places and I would prefer to be more cautious and attentive about false positives when applying it.
I don't see the connection of those suggestions toward resolving #75742. That issue is motivated by Independent of #75742, I would still recommend against going for must_use on those functions unless there is some evidence of pattern of misuse of those functions that we are hoping to prevent. Aggressively tagging must_use without a pattern of misuse just increases the false positive rate and general nuisance of must_use without delivering practical benefit. |
I meant: But yeah, if the lib team has other ways to resolve the issue, I am happy to wait for it. |
@lzutao An idea you might be interested to play with: the |
Make String a must_use type to lint again unused String: #75742