Skip to content

Mut on ident patterns. #10026

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

Merged
merged 5 commits into from
Oct 27, 2013
Merged

Mut on ident patterns. #10026

merged 5 commits into from
Oct 27, 2013

Conversation

luqmana
Copy link
Member

@luqmana luqmana commented Oct 23, 2013

Fixes #9792.

@huonw
Copy link
Member

huonw commented Oct 23, 2013

Would this be nicer as BindInfer(Mutability)? (I guess it could be renamed to BindByVal too, in that case?)

@alexcrichton
Copy link
Member

I have a feeling that way back when we used to infer what the kind of binding was (maybe it was inferred to be by reference or by value?), but now we don't have that any more. I agree with @huonw that we should probably just replace it with BindByValue and then taking a mutability argument seems to make the most sense to me.

Also, would you mind expending the lint-unused-mut.rs test a bit to include the new cases where mutability is allowed? Other than that, this looks great!

@luqmana
Copy link
Member Author

luqmana commented Oct 23, 2013

@huonw, @alexcrichton: Done and done.

let lo = self.span.lo;
let pat = self.parse_pat();

if is_mutbl && !ast_util::pat_is_ident(pat) {
self.obsolete(*self.span, ObsoleteMutWithMultipleBindings)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ObsoleteMutWithMultipleBindings unused after this removal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, and now gone!

@alexcrichton
Copy link
Member

The only thing holding me back from an r+ on this is that I don't fully understand mem_categorization and friends dealing with the analysis of mutable variables. It looks correct to me, but I can't quite say for sure.

If someone else who understand those portions wants to r+, sounds good to me. Otherwise, if you add some tests with errors about mutable matches, I'd r+ this. Things like you can take a mutable loan out of a binding, but you can't do it twice, or moving out and then re-assigning, etc.

@nikomatsakis
Copy link
Contributor

I'll take a look

@nikomatsakis
Copy link
Contributor

Overall this looks reasonably good to me except that the tests look insufficient. I'd like to see various compile-fail and run-pass tests covering various weird cases like fn foo((x, mut y): (...)) etc. (the tests should cover the various interesting patterns used in fn arguments, let declarations, and match statements).

bors added a commit that referenced this pull request Oct 27, 2013
@bors bors closed this Oct 27, 2013
@bors bors merged commit 523a28d into rust-lang:master Oct 27, 2013
@nikomatsakis
Copy link
Contributor

I'm glad to see this landed, but I feel like the tests are still insufficient. There are lots and lots of edge cases here and I don't see much coverage. I also see no coverage of the possible interactions with the borrow checker and so on. I'll open a bug with some suggestions for tests we need.

@luqmana luqmana deleted the mut-pat branch June 5, 2014 23:18
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 17, 2022
Add missing slash to produce function documentation

changelog: none
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.

Allow mut qualification on idents in patterns
7 participants