Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up#[deriving(Show)] handles its interior fundamentally incorrectly #12128
Comments
huonw
added
A-syntaxext
labels
Feb 9, 2014
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Another option we have is the Additionally formatting for |
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton that sounds reasonable; would you think that a deriving(Show)'d type would use the |
This comment has been minimized.
This comment has been minimized.
|
one potential advantage of a separate trait rather than using the E.g. the sample code illustrating impl fmt::Show for Vector2D {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "({}, {})", self.x, self.y)
}
}this would have to be changed to something like: fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.flags & (1 << FlagAlternate) {
write!(f.buf, "({:#}, {:#})", self.x, self.y)
} else {
write!(f.buf, "({}, {})", self.x, self.y)
}
}which may not be the most obvious thing to write. But then again, if |
This comment has been minimized.
This comment has been minimized.
|
A more principled way of stating my previous comment is: How much code does one expect to be shared between the two control paths? If sharing is unlikely, then two distinct traits seems sensible. But I actually can believe that there is potential for much sharing, depending on how one architects one's implementation of |
This comment has been minimized.
This comment has been minimized.
|
I don't expect many implementations to custom handle the Most formatting flags are completely ignored for all but the primitive implementations anyway, so I wouldn't imagine that starting to recognize the |
This comment has been minimized.
This comment has been minimized.
|
I've long thought that it makes sense to support I think it's fine to put this into I am mildly concerned about the inability to easily propagate this flag in manually-written |
This comment has been minimized.
This comment has been minimized.
|
If we had the scoped task locals (aka thread-local fluids, aka dynamic parameters) that we have occasionally discussed (and that the old condition system embedded), then we could use that for the I wonder if there is an issue somewhere for this (library) feature |
This comment has been minimized.
This comment has been minimized.
|
Today, the equivalent code with
|
huonw commentedFeb 9, 2014
e.g.
prints
Foo { x: bar } }, butFoo { x: ~"bar }" }orFoo { x: "bar }" }would be far more reasonable.Our
Showdiffers from Haskell's (which also hasderiving (Show)) in thatshow stringputs quotes around it, while our{}is puts it straight inline (i.e. they're actually different operations).Proposal: create (yet another) formatting trait
Reprand replace#[deriving(Show)]withRepr. This would mean thatprintln!("{:r}", "foo")would be printed as"foo"rather than justfoolike{}does. I feel like this is a more accurate description of what it's doing: it's a raw representation of a type, while{}is meant to be more polished.