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

custom disjoint rules #16

Open
nikomatsakis opened this issue May 25, 2017 · 4 comments
Open

custom disjoint rules #16

nikomatsakis opened this issue May 25, 2017 · 4 comments

Comments

@nikomatsakis
Copy link
Owner

I don't have a syntax for this, but it seems likely that we'll eventually want the ability to specify disjoint-ness in a finer-grained fashion. However, this is not unique to properties -- we probably want this on methods as well! There are a lot of open questions here on the best way to go about this.

@burdges
Copy link

burdges commented May 25, 2017

Is this going to be common? If not, you can do it with a trait hierarchy already, right?

We can require that x be disjoint from y and z like this, without requiring that y and z be disjoint, right?

trait A { x: [T] }
trait B : A { y: [T] }
trait C : A { z: [T] }

It's verbose to use and impl all these traits, but another syntax could resolve that, like say pub trait Foo : pub A, pub B, pub C {} to merge these traits for export.

If struct were used as an alternative to let then I guess trait Foo { struct mut f: T; struct mut g: U; ... } would prohibit mutabling borrowing both f and g while trait Foo { struct { f: T, g: U } ... } would prohibit overlap between f and g, but this syntax does not support forbidding some overlap like above.

@nikomatsakis
Copy link
Owner Author

Is this going to be common? If not, you can do it with a trait hierarchy already, right?

Indeed. This is why I was originally thinking that we would never need it.

That said, I think it would be useful to be able to declare methods that are "disjoint" from one another (i.e., that they access disjoint sets of fields, as in rust-lang/rfcs#1215). I can imagine that if we grow a way to do that, we might also use it to declare overlapping fields.

Certainly seems out of scope for the initial shot at this RFC, particularly since the RFC itself provides a partial means to address rust-lang/rfcs#1215.

@burdges
Copy link

burdges commented May 26, 2017

I see. It appears the struct version suffices for creating multiple "disjointness families" of methods. I suppose expressing overlap helps, but maybe not soo much, and maybe duplicate files could do the job.

@burdges
Copy link

burdges commented May 26, 2017

I suppose the struct version can be quite expressive if we identify duplicate fields between struct field declarations together :

trait Foo {
    struct { a: T, b: T }
    struct { b, d: T }
    struct { a, c: T }
    struct { c, d }
}

This says a and d are disjoint form b and c but not necessary each other, with b and c are not necessarily disjoint from each other, so you can define method using any. I've removed the type suffix from second occurrences of each name.

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

No branches or pull requests

2 participants