Add #[must_use] to from_value conversions#89753
Merged
bors merged 1 commit intorust-lang:masterfrom Oct 11, 2021
Merged
Conversation
3fe1c3b to
4967c6a
Compare
This comment has been minimized.
This comment has been minimized.
4967c6a to
cf2bcd1
Compare
Member
|
If we find any significant number of crates that are using one of these methods to convert to a type with Drop as a means of freeing it, we should consider reverting the addition of must_use to that method to avoid excessive disruption. Such a code pattern would be unusual but legitimate. We're allowed to add warnings to existing code, but we typically take into account how many warnings we're adding to the ecosystem. |
Member
|
@bors r+ |
Collaborator
|
📌 Commit cf2bcd1 has been approved by |
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Oct 11, 2021
…rsions, r=joshtriplett
Add #[must_use] to from_value conversions
I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument.
```rust
core::str const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;
std::ffi::CString unsafe fn from_raw(ptr: *mut c_char) -> CString;
```
I put a custom note on `from_raw`:
```rust
#[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"]
pub unsafe fn from_raw(ptr: *mut c_char) -> CString {
```
Parent issue: rust-lang#89692
r? `@joshtriplett`
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Oct 11, 2021
…laumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#89655 (bootstrap: don't use `--merges` to look for commit hashes for downloading artifacts) - rust-lang#89726 (Add #[must_use] to alloc constructors) - rust-lang#89729 (Add #[must_use] to core and std constructors) - rust-lang#89743 (Fix RUSTC_LOG handling) - rust-lang#89753 (Add #[must_use] to from_value conversions) - rust-lang#89754 (Cleanup .item-table CSS) - rust-lang#89761 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Member
|
Is there any particular reason why this was added to |
Contributor
Author
|
@BurntSushi No, I don't believe so. I don't remember excluding it. I'm guessing I simply didn't catch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I added two methods to the list myself. Clippy did not flag them because they take
mutargs, but neither modifies their argument.I put a custom note on
from_raw:Parent issue: #89692
r? @joshtriplett