Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Traits extending kinds / built-in traits #7083

Closed
nikomatsakis opened this issue Jun 12, 2013 · 5 comments
Closed

Traits extending kinds / built-in traits #7083

nikomatsakis opened this issue Jun 12, 2013 · 5 comments
Labels
A-type-system Area: Type system

Comments

@nikomatsakis
Copy link
Contributor

You should be able to write:

trait Foo: Sized { ... }

and then have a parameter like

fn foo<T:Foo>(...) 

where this also implies that T is Sized.

Related to #5527

@nikomatsakis
Copy link
Contributor Author

Nominating for milestone feature complete.

@emberian
Copy link
Member

emberian commented Aug 5, 2013

Testcase:

trait Foo: Send {
    pub fn sendit(self) {
        do spawn {
            printfln!("%?", self);
        }
    }
}

fn foo<T: Foo>(x: T) {
    x.sendit();
}

impl Foo for int;

fn main() {
    let x = 5i;
    foo(x);
}

fails with:

foo.rs:13:0: 13:17 error: failed to find an implementation of trait std::kinds::Send for int
foo.rs:13 impl Foo for int;
          ^~~~~~~~~~~~~~~~~

@nikomatsakis I think this error is a different bug?

@bblum
Copy link
Contributor

bblum commented Aug 14, 2013

In addition to inheriting from the builtin kinds, should we allow boxing up as the builtin kinds? I can't imagine what possible use this could have, as no vtable could be generated, but something like:

fn main() {
    let x = ~() as ~Send;
}

currently errors with

foo.rs:2:12: 2:24 error: failed to find an implementation of trait ~std::kinds::Send:Send for ()
foo.rs:2     let x = ~() as ~Send;
                     ^~~~~~~~~~~~

because of code very similar to the code I will be changing for this, in typeck/collect.rs.

@nikomatsakis
Copy link
Contributor Author

I ... see no reason to allow that in particular, since the built-in kinds have no methods, but I guess if it's easy to do?

@bblum
Copy link
Contributor

bblum commented Aug 16, 2013

Probably it is not trivial to do.

@bblum bblum mentioned this issue Aug 16, 2013
bblum added a commit to bblum/rust that referenced this issue Aug 20, 2013
bblum added a commit to bblum/rust that referenced this issue Aug 20, 2013
bors added a commit that referenced this issue Aug 21, 2013
For #7083.

The metadata issue with the old version is now fixed. Ready for review.

This is also not the full solution to #7083, because this is not supported yet:
```
trait Foo : Send { }

impl <T: Send> Foo for T { }

fn foo<T: Foo>(val: T, chan: std::comm::Chan<T>) {
    chan.send(val);
}
```

cc @nikomatsakis
bors added a commit that referenced this issue Aug 22, 2013
For #7083.

The metadata issue with the old version is now fixed. Ready for review.

This is also not the full solution to #7083, because this is not supported yet:
```
trait Foo : Send { }

impl <T: Send> Foo for T { }

fn foo<T: Foo>(val: T, chan: std::comm::Chan<T>) {
    chan.send(val);
}
```

cc @nikomatsakis
@bblum bblum closed this as completed in 3c3bfb4 Aug 22, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 22, 2021
…effen

Add lint to check for boolean comparison in assert macro calls

This PR adds a lint to check if an assert macro is using a boolean as "comparison value". For example:

```rust
assert_eq!("a".is_empty(), false);
```

Could be rewritten as:

```rust
assert!(!"a".is_empty());
```

PS: The dev guidelines are amazing. Thanks a lot for writing them!

changelog: Add `bool_assert_comparison` lint
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

3 participants