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

Type-mismatch error boxed Trait #11818

Closed
villem opened this issue Mar 25, 2022 · 3 comments
Closed

Type-mismatch error boxed Trait #11818

villem opened this issue Mar 25, 2022 · 3 comments

Comments

@villem
Copy link

villem commented Mar 25, 2022

Hi,

The latest nightly 3-25-2022 ( 0.3.989) on Mac vscode gives me this error. Cargo build this is ok. Also the RA build 0.3.986 don't
give this error. rustc -V
rustc 1.58.0 (02072b482 2022-01-11)

[{
"resource": "/Users/ville.mattila/src/smc_umbrella/backend/src/manager/policy.rs",
"owner": "rustc",
"code": {
"value": "type-mismatch",
"target": {
"$mid": 1,
"external": "https://rust-analyzer.github.io/manual.html#type-mismatch",
"path": "/manual.html",
"scheme": "https",
"authority": "rust-analyzer.github.io",
"fragment": "type-mismatch"
}
},
"severity": 8,
"message": "expected Box<dyn Foo<FooItem = ::BarItem>, Global>, found Box<F, Global>",
"source": "rust-analyzer",
"startLineNumber": 33,
"startColumn": 26,
"endLineNumber": 33,
"endColumn": 39
}]

Here is source code. I grant this may be most correct rust, but it works for me. You can give suggestion better code too :-) ,
but RA should not give error, where rustc is happy.

trait Foo {
    type FooItem;
}

trait Bar {
    type BarItem: Foo;
    fn add_foo(&self, bar: Box<dyn Foo<FooItem=Self::BarItem>>) {

    }
}

struct Baz<B> {
    bar: B,
}

impl<B:Bar>  Baz<B> {
    fn add_rule<F: 'static>(&mut self, mut foo: F)
    where F: Foo<FooItem = <B as Bar>::BarItem> {
        self.bar.add_foo(Box::new(foo)); // <<-- THIS line give RA Error now
    }
}
@flodiebold
Copy link
Member

This will be fixed by rust-lang/chalk#754 once that gets merged. Also, #11809 will hide the diagnostic unless you explicitly enable experimental errors 🙂

@flodiebold
Copy link
Member

Considering that, let's close this already.

@villem
Copy link
Author

villem commented Mar 25, 2022

Ok thanks!

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

2 participants