You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the (reduced) code below, I don't understand why B needs to implement the Debug trait, as we are only interested in the Debug trait for the associated type Bar::Bartype, and Bar doesn't even appear in the output if we add the Debug constraint and derivation to it.
Rustc emmits the following error messages:
minmal.rs:42:14: 42:23 error: the trait `core::fmt::Debug` is not implemented for the type `B` [E0277]
minmal.rs:42 impl<B: Bar> Framework for Dummy<B> {
^~~~~~~~~
minmal.rs:42:14: 42:23 help: run `rustc --explain E0277` to see a detailed explanation
minmal.rs:42:14: 42:23 note: `B` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
minmal.rs:42:14: 42:23 note: required by `Framework`
And here is the listing:
use std::fmt::Debug;
pub trait Bar {
/// Only real interesting point here, the associated type
type Bartype : Debug;
fn neu() -> Self::Bartype;
}
pub trait Framework {
/// The important part here is the Debug constraint
/// on the associated type
type FrameType : Debug;
fn do_stuff(&self);
}
/// uncomment next line to make it compile
// #[derive(Debug)]
struct ABar { dummy: u32 }
impl Bar for ABar {
type Bartype = u32;
fn neu() -> Self::Bartype { 0 as u32 }
}
struct Dummy<B : Bar> { dummy: B::Bartype }
impl<B:Bar> Dummy<B> {
fn new() -> Dummy<B> {
Dummy { dummy: B::neu() }
}
}
/// If a real Debug constraint would by required, it would
/// be nice to get the error here.
#[derive(Debug)]
struct Foo<B : Bar> { a_field: B::Bartype }
impl<B:Bar> Foo<B> {
fn new() -> Foo<B> {
Foo { a_field: B::neu() }
}
}
/// Why does B needs the Debug trait?
/// uncomment + Debug to make it compile
impl<B: Bar /* + Debug */> Framework for Dummy<B> {
type FrameType = Foo<B>;
fn do_stuff(&self) {
print!("{:?}", Foo::<B>::new())
}
}
fn main() {
let dumm = Dummy::<ABar>::new();
dumm.do_stuff();
print!("\n{:?}\n", dumm.dummy)
}
I would expect that the B parameter of Dummy didn't require the instantiation of the Debug trait for it, as the associated type clearly has the Debug contraint on it.
Using the (reduced) code below, I don't understand why B needs to implement the Debug trait, as we are only interested in the Debug trait for the associated type Bar::Bartype, and Bar doesn't even appear in the output if we add the Debug constraint and derivation to it.
Rustc emmits the following error messages:
And here is the listing:
I would expect that the B parameter of Dummy didn't require the instantiation of the Debug trait for it, as the associated type clearly has the Debug contraint on it.
Meta
The text was updated successfully, but these errors were encountered: