Skip to content

Update FFI tutorial to reference c_str::to_c_str #8692

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

Closed
wants to merge 1 commit into from

Conversation

lilyball
Copy link
Contributor

The FFI tutorial still incorrectly stated that strings were terminated
with \0 and suggested using str::as_c_str.

The FFI tutorial still incorrectly stated that strings were terminated
with \0 and suggested using `str::as_c_str`.
bors added a commit that referenced this pull request Aug 23, 2013
The FFI tutorial still incorrectly stated that strings were terminated
with
@bors bors closed this Aug 23, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 21, 2022
… r=giraffate

fix unnecessary_to_owned about msrv

This PR fixes ``[`unnecessary_owned`]``.

## What

```rust
# sample code
fn _msrv_1_35() {
    #![clippy::msrv = "1.35"]
    let _ = &["x"][..].to_vec().into_iter();
}

fn _msrv_1_36() {
    #![clippy::msrv = "1.36"]
    let _ = &["x"][..].to_vec().into_iter();
}
```

If we will check this code using clippy, ``[`unnecessary_owned`]`` will modify the code as follows.

```rust
error: unnecessary use of `to_vec`
  --> $DIR/unnecessary_to_owned.rs:219:14
   |
LL |     let _ = &["x"][..].to_vec().into_iter();
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`

error: unnecessary use of `to_vec`
  --> $DIR/unnecessary_to_owned.rs:224:14
   |
LL |     let _ = &["x"][..].to_vec().into_iter();
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`
```

This is incorrect. Because `Iterator::copied` was estabilished in 1.36.

## Why

This bug was caused by not separating "copied" and "clone" by reference to msrv.

https://github.com/rust-lang/rust-clippy/blob/89ee6aa6e32df974ef9dbb3c825afbdce441e856/clippy_lints/src/methods/unnecessary_to_owned.rs#L195

So, I added a conditional branch and described the corresponding test.

Thank you in advance.

changelog: fix wrong suggestions about msrv in [`unnecessary_to_owned`]

r! `@giraffate`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants