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

When using value after move, point at span of local #57294

Open
wants to merge 5 commits into
base: master
from

Conversation

Projects
None yet
5 participants
@estebank
Copy link
Contributor

estebank commented Jan 3, 2019

When trying to use a value after move, instead of using a note, point
at the local declaration that has a type that doesn't implement Copy
trait.

error[E0382]: use of moved value: `x`
  --> $DIR/issue-34721.rs:27:9
   |
LL |     pub fn baz<T: Foo>(x: T) -> T {
   |                -       - move occurs because `x` has type `T`, which does not implement the `Copy` trait
   |                |
   |                consider adding a `Copy` constraint to this type argument
LL |         if 0 == 1 {
LL |             bar::bar(x.zero())
   |                      - value moved here
LL |         } else {
LL |             x.zero()
   |             - value moved here
LL |         };
LL |         x.zero()
   |         ^ value used here after move

Fix #34721.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 3, 2019

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@estebank

This comment was marked as resolved.

Copy link
Contributor

estebank commented Jan 3, 2019

If there's a way to get the current scope's type arguments, we could add an appropriate suggestion (and close the linked ticket):

error[E0382]: use of moved value: `x`
  --> src/main.rs:25:3
   |
   | pub fn baz<T: Foo>(x: T) -> T {
   |            ------  - move occurs because `x` has type `T`, which does not implement the `Copy` trait
   |            |
   |            help: consider adding a `Copy` constraint here: `T: Foo + Copy`
   |   if 0 == 1 {
21 |     bar::bar(x.zero())
   |              - value moved here
...
25 |   x.zero()
   |   ^ value used here after move

@estebank estebank force-pushed the estebank:point-copy-less branch from 19a3c07 to abbf5a2 Jan 6, 2019

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 7, 2019

@nikomatsakis, you might also be interested in taking a look at this.

@nikomatsakis
Copy link
Contributor

nikomatsakis left a comment

I think this looks nice

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 10, 2019

Ping @eddyb :)

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 18, 2019

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Jan 18, 2019

estebank added some commits Jan 3, 2019

When using value after move, point at span of local
When trying to use a value after move, instead of using a note, point
at the local declaration that has a type that doesn't implement `Copy`
trait.

@estebank estebank force-pushed the estebank:point-copy-less branch from abbf5a2 to 09006d8 Jan 18, 2019

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 21, 2019

@bors r=nikomatsakis

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 21, 2019

📌 Commit 09006d8 has been approved by nikomatsakis

Centril added a commit to Centril/rust that referenced this pull request Jan 21, 2019

Rollup merge of rust-lang#57294 - estebank:point-copy-less, r=nikomat…
…sakis

When using value after move, point at span of local

When trying to use a value after move, instead of using a note, point
at the local declaration that has a type that doesn't implement `Copy`
trait.

```
error[E0382]: use of moved value: `x`
  --> $DIR/issue-34721.rs:27:9
   |
LL |     pub fn baz<T: Foo>(x: T) -> T {
   |                -       - move occurs because `x` has type `T`, which does not implement the `Copy` trait
   |                |
   |                consider adding a `Copy` constraint to this type argument
LL |         if 0 == 1 {
LL |             bar::bar(x.zero())
   |                      - value moved here
LL |         } else {
LL |             x.zero()
   |             - value moved here
LL |         };
LL |         x.zero()
   |         ^ value used here after move
```

Fix rust-lang#34721.

bors added a commit that referenced this pull request Jan 22, 2019

Auto merge of #57823 - Centril:rollup, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #57294 (When using value after move, point at span of local)
 - #57552 (Default images)
 - #57667 (Fix memory leak in P::filter_map)
 - #57677 (const_eval: Predetermine the layout of all locals when pushing a stack frame)
 - #57730 (Merge visitors in AST validation)
 - #57791 (Add regression test for #54582)
 - #57795 (Use structured suggestion in stead of notes)
 - #57809 (Add powerpc64-unknown-freebsd)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 22, 2019

⌛️ Testing commit 09006d8 with merge 1c661d9...

bors added a commit that referenced this pull request Jan 22, 2019

Auto merge of #57294 - estebank:point-copy-less, r=nikomatsakis
When using value after move, point at span of local

When trying to use a value after move, instead of using a note, point
at the local declaration that has a type that doesn't implement `Copy`
trait.

```
error[E0382]: use of moved value: `x`
  --> $DIR/issue-34721.rs:27:9
   |
LL |     pub fn baz<T: Foo>(x: T) -> T {
   |                -       - move occurs because `x` has type `T`, which does not implement the `Copy` trait
   |                |
   |                consider adding a `Copy` constraint to this type argument
LL |         if 0 == 1 {
LL |             bar::bar(x.zero())
   |                      - value moved here
LL |         } else {
LL |             x.zero()
   |             - value moved here
LL |         };
LL |         x.zero()
   |         ^ value used here after move
```

Fix #34721.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 22, 2019

💔 Test failed - checks-travis

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 22, 2019

@bors retry

@estebank

This comment has been minimized.

Copy link
Contributor

estebank commented Jan 22, 2019

@bors r- need to update nll tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment