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

Rename PatUniq to PatBox and extend support to arbitrary smart pointers #13910

Closed
pcwalton opened this issue May 3, 2014 · 17 comments
Closed
Labels
A-parser Area: The parsing of Rust source code to an AST. C-cleanup Category: PRs that clean code up or issues documenting cleanup. C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@pcwalton
Copy link
Contributor

pcwalton commented May 3, 2014

Yup.

@ahmedcharles
Copy link
Contributor

Would you mind commenting on what "extend support to arbitrary smart pointers" means? I did the rename, but I imagine that wasn't the most important part of this?

@alexcrichton
Copy link
Member

Something like this should also work:

let foo = Rc::new(3);
match foo {
    box n => println!("{}", n),
}

That should also work for things like Gc, Arc, etc.

@ghost
Copy link

ghost commented Jun 8, 2014

I'll look into this.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 8, 2014

@jakub- do you have someone mentoring you on it? It will probably tie into our allocator story, which remains to be 100% settled.

I don't want to investing a lot of effort into a path that we are not planning on going down.

@ghost
Copy link

ghost commented Jun 9, 2014

@pnkfelix Well, for now I was just going to make the box pattern compile down to a deref for arbitrary pointers rather than Box<> pointers specifically. I'd imagine the Deref trait is going to stay regardless of the allocator changes?

@huonw
Copy link
Member

huonw commented Jun 9, 2014

Should box patterns go through an RFC? (Just to get the precise semantics (& what's supported/what's not) nailed down.)

@pnkfelix
Copy link
Member

pnkfelix commented Jun 9, 2014

@jakub- oh sorry, I misread the title and was thinking of the box (..) expr expression, not of box patterns.

@ghost
Copy link

ghost commented Jun 9, 2014

@pnkfelix Right, no worries!

@huonw I agree this could use an RFC. I'll write one up.

@Manishearth
Copy link
Member

Is there an RFC for this? If not, I don't mind writing one and maybe starting work on this.

@ghost
Copy link

ghost commented Sep 6, 2014

@Manishearth Please go ahead if you're interested!

The reason I hadn't gotten around to writing an RFC is my serious doubts around if allowing box patterns for arbitrary pointers is really feasible and/or a good idea. Essentially, for it to work the deref method would be required to be referentially transparent, something which the compiler cannot guarantee in the general case. Rust used to have a notion of purity for functions that was not well-defined and subsequently removed which in this case would probably be useful to have.

But I'm looking forward to your proposal and maybe it's workable!

@ghost
Copy link

ghost commented Sep 6, 2014

To be fair, what I described above is already a problem for the borrow checker in that without the special knowledge of particular smart pointers (like Box) it cannot guarantee that dereferencing a smart pointer always returns the same location in memory. So maybe it's worth exploring potential avenues for expressing that guarantee to the compiler.

@Manishearth
Copy link
Member

Actually, I don't have enouigh knowledge of the compiler to be able to write a good RfC on this, after probing the issue, sorry :/

@Kimundi
Copy link
Member

Kimundi commented Sep 6, 2014

Could box patterns maybe simply get restricted so that for a given pattern match, the implementation of the matcher only has to call deref() at most once?

@steveklabnik
Copy link
Member

Triage: box patterns are now feature gated.

@steveklabnik
Copy link
Member

Triage: box patterns are still gated, but doing a grep of the source code:

$ git grep "PatUniq"
src/grammar/parser-lalr.y:| BOX pat                                         { $$ = mk_node("PatUniq", 1, $2); }
$

I'm guessing this is used somewhere, but maybe under a different name or something?

@pnkfelix
Copy link
Member

pnkfelix commented May 25, 2016

@steveklabnik I think the rename happened, but not the extension to arbitrary box patterns smart pointers

@nikomatsakis
Copy link
Contributor

I think we can close this. The extension to arbitrary "smart pointers" etc feels like an RFC issue to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST. C-cleanup Category: PRs that clean code up or issues documenting cleanup. C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

9 participants