Why isn't Debug implemented by default?

So, there are a couple of traits in Rust, such as Send or Sync, which are automatically implemented whenever the compiler feels safe doing so. Why isn't it the case for Debug, which every type is supposed to implement? It makes it all too easy to forget a #[derive(Debug)], while the benefits are not obvious to me...

1 Like

https://github.com/rust-lang/rust/issues/28185

In short, backward compatibility.

1 Like

I hope it's in the list of changes for Rust 2.0 :slight_smile:

4 Likes

What happens for types which don't really make sense to get a debug representation for? For example, a File handle or a TcpStream.

Or what if the default debug impl will blast stdout with so much output its hard to find what you want? e.g. your struct has a field which is a 10,000 element vector, or it's an entire AST.

2 Likes

Nothing stops you from overriding the Debug implementation (default impl is a thing). As for types that don't have debug representations... well, they simply don't. Just like a type that contains non-Send types is not Send, so a type with non-Debug types is not Debug.

1 Like

I assumed it was to reduce amount of auto-generated code.

2 Likes