Closed
Description
This code:
pub trait A<T : B> { fn foo(self) -> T; }
pub struct AImpl;
impl<BImpl> A<BImpl> for AImpl {
fn foo(self) -> BImpl { unimplemented!(); }
}
pub trait B { fn bar(self); }
pub struct BImpl;
impl B for BImpl {
fn bar(self) { unimplemented!(); }
}
...give me this error:
Compiling testproject v0.0.1 (file:///home/virtlink/projects/orion/testproject)
src/lib.rs:6:1: 8:2 error: the trait `B` is not implemented for the type `BImpl` [E0277]
src/lib.rs:6 impl<BImpl> A<BImpl> for AImpl {
src/lib.rs:7 fn foo(self) -> BImpl { unimplemented!(); }
src/lib.rs:8 }
error: aborting due to previous error
Could not compile `testproject`.
This is confusing. The trait B
is implemented for the type BImpl
.
Instead, I have to change this:
impl<BImpl> A<BImpl> for AImpl
...into this:
impl A<BImpl> for AImpl
The error should make that clear.
rustc 1.0.0-nightly (c89de2c56 2015-03-28) (built 2015-03-29)
binary: rustc
commit-hash: c89de2c56baeb61e7cc434924dcc8bedd32b26b8
commit-date: 2015-03-28
build-date: 2015-03-29
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
Activity
apasel422 commentedon Jul 19, 2015
I'm not really sure what the compiler can do here, as there is both a type parameter and a type named
BImpl
. The compiler's error message is correct, in that the type parameterBImpl
does not implementB
. Maybe there could be a lint for shadowing a type with a type parameter?Emilgardis commentedon Jan 21, 2017
I believe this should be closed, the new error messages give a good explanation of what is happening.
Link to Playground: https://is.gd/D44BaU
Mark-Simulacrum commentedon May 20, 2017
Today we give the following; ideally I think we would have a span on
BImpl
inimpl<BImpl>
which we'd reference with something like "this generic must implementB
because of the bound on traitA
." This is likely quite hard though.estebank commentedon Jan 28, 2018
Related to #47319. Once that ticket is fixed, pointing at
BImpl
becomes feasible.Rollup merge of rust-lang#65192 - estebank:restrict-bound, r=matthewj…
Rollup merge of rust-lang#65192 - estebank:restrict-bound, r=matthewj…