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

"error: cannot bind by-move with sub-bindings" when sub-binding is _ #8271

Closed
lilyball opened this issue Aug 3, 2013 · 1 comment
Closed

Comments

@lilyball
Copy link
Contributor

lilyball commented Aug 3, 2013

The x@foo construct cannot be used in a match arm if foo contains sub-bindings. This is not surprising. However, when the sub-bindings are actually _, this should be allowed as _ is not a real binding.

Example:

match a {
    x@Some(_) => x,
    None => None
}

Result:

foo.rs:3:8: 3:17 error: cannot bind by-move with sub-bindings
foo.rs:3         x@Some(_) => x,
@lilyball
Copy link
Contributor Author

I think this is a dupe of #3761.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 27, 2022
Check usages in `ptr_arg`

fixes rust-lang#214
fixes rust-lang#1981
fixes rust-lang#3381
fixes rust-lang#6406
fixes rust-lang#6964

This does not take into account the return type of the function currently, so `(&Vec<_>) -> &Vec<_>` functions may still be false positives.

The name given for the type also has to match the real type name, so `type Foo = Vec<u32>` won't trigger the lint, but `type Vec = Vec<u32>` will. I'm not sure if this is the best way to handle this, or if a note about the actual type should be added instead.

changelog: Check if the argument is used in a way which requires the original type in `ptr_arg`
changelog: Lint mutable references in `ptr_arg`
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

1 participant