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

Unusual request for a Sized bound #18258

Closed
alexcrichton opened this issue Oct 23, 2014 · 8 comments
Closed

Unusual request for a Sized bound #18258

alexcrichton opened this issue Oct 23, 2014 · 8 comments

Comments

@alexcrichton
Copy link
Member

In the code below, if type parameters are explicitly specified then the compilation succeeds, but if left to inference the compilation will fail.

use std::cell::Cell;
use std::sync::Arc;

pub trait PoolManager<C>: Send+Sync {}

struct InnerPool<C, M> {
    f: Option<C>,
}

pub struct Pool<C, M> where M: PoolManager<C> {
    helper_chan: Cell<()>,
    inner: Arc<InnerPool<C, M>>
}

impl<C, M> Pool<C, M>
        where C: Send + Sync, M: PoolManager<C> {
    pub fn new(manager: M) -> Pool<C, M> {
        let inner = Arc::new(InnerPool {
            f: None,
        });

        Pool {
            helper_chan: Cell::new(()),
            inner: inner,
        }
    }
}

#[cfg(bad)]
fn helper_task<C, M>(inner: Arc<InnerPool<C, M>>)
        where C: Send + Sync, M: PoolManager<C> {
    add_connection(&*inner);
}

#[cfg(good)]
fn helper_task<C, M>(inner: Arc<InnerPool<C, M>>)
        where C: Send + Sync, M: PoolManager<C> {
    add_connection::<C, M>(&*inner);
}

fn add_connection<C, M>(inner: &InnerPool<C, M>) where M: PoolManager<C> {
}
$ rustc lib.rs --crate-type lib --cfg bad
lib.rs:32:5: 32:19 error: the trait `core::kinds::Sized` is not implemented for the type `C`
lib.rs:32     add_connection(&*inner);
              ^~~~~~~~~~~~~~
lib.rs:32:5: 32:19 note: the trait `core::kinds::Sized` must be implemented because it is required by `add_connectio
n`
lib.rs:32     add_connection(&*inner);
              ^~~~~~~~~~~~~~
lib.rs:32:5: 32:19 error: the trait `core::kinds::Sized` is not implemented for the type `M`
lib.rs:32     add_connection(&*inner);
              ^~~~~~~~~~~~~~
lib.rs:32:5: 32:19 note: the trait `core::kinds::Sized` must be implemented because it is required by `add_connectio
n`
lib.rs:32     add_connection(&*inner);
              ^~~~~~~~~~~~~~
lib.rs:32:20: 32:27 error: mismatched types: expected `&InnerPool<C,M>`, found `&InnerPool<C,M>` (expected type para
meter, found type parameter)
lib.rs:32     add_connection(&*inner);
                             ^~~~~~~
error: aborting due to 3 previous errors
$ rustc lib.rs --crate-type lib --cfg good
... warnings
@alexcrichton
Copy link
Member Author

This was also a recent regression, the code used to compile.

@aturon
Copy link
Member

aturon commented Oct 23, 2014

cc @nick29581

@nrc
Copy link
Member

nrc commented Oct 23, 2014

cc @nikomatsakis if this is a recent regression, I suspect more multi-dispatch issues

@nikomatsakis
Copy link
Contributor

weird.

@nikomatsakis
Copy link
Contributor

This seems to be the most interesting part:

lib.rs:32:20: 32:27 error: mismatched types: expected `&InnerPool<C,M>`, found `&InnerPool<C,M>` (expected type parameter, found type parameter)

@nikomatsakis
Copy link
Contributor

Sounds like a missing substitution somewhere.

@nikomatsakis
Copy link
Contributor

Possible dup of #18209.

@nikomatsakis
Copy link
Contributor

Verified dup of #18209

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

4 participants