Skip to content
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

moves from unsafe ptrs / initializers #2610

Closed
nikomatsakis opened this issue Jun 14, 2012 · 2 comments
Closed

moves from unsafe ptrs / initializers #2610

nikomatsakis opened this issue Jun 14, 2012 · 2 comments

Comments

@nikomatsakis
Copy link
Contributor

Today we accept this:

let i <- *p

where p is an unsafe ptr. This is ok. However, I think we accept it because we are not properly checking for moves in initializers and not for any good reason. We should probably accept moves out of unsafe ptrs (it's useful) but also check initializers properly. I'm not sure whether this is a borrowck or liveness bug but I think borrowck.

@catamorphism
Copy link
Contributor

Obsolete since we don't have <- anymore.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 3, 2021
fix `needless_borrow` suggestion

fixes: rust-lang#2610

While I'm working on this, should needless_borrow be split into two? One lint for expressions and another for patterns. In expression it only lints when the compiler inserts a dereference, but for patterns it's whenever a double reference is created. I think at least the case where a double reference is needed should be split into a new lint as it's not 'needless', it can just be done without a ref binding.

For illustration:

```rust
fn foo(x: &&str) {}

match Some("test") {
    // ref binding is useless here
    Some(ref x) => *x,
    _ => (),
}

match Some("test") {
    // ref binding is useless here
    Some(ref x) => x.len(),
    _ => (),
}

match Some("test") {
    // double reference is needed, but could be `Some(x) => foo(&x)`
    Some(ref x) => foo(x),
    _ => (),
}
```

changelog: Improve the suggestion for `needless_borrow` in patterns to change all usage sites as needed.
changelog: Add lint `ref_binding_to_reference`
RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 22, 2022
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Finished dev [unoptimized] target(s) in 0.06s
Skipping Set({test::src/tools/tidy}) because it is excluded
Skipping Set({test::src/tools/tidy}) because it is excluded
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
error: the lock file /checkout/Cargo.lock needs to be updated but --locked was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.

Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
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

No branches or pull requests

3 participants