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
Replacing the sed ... with wc -l gives 77, i.e. there are approximately 77 #[derive]s to look at (nearly 25% of which are in core::iter, hence it being listed separately).
Comment below if you wish to handle some of these.
The only dubious implementation is the #[derive(Clone)] for std::thread::Thread. I (very vaguely) recall that there was some discussion about changing the internals of Thread to not have the Arc (I could very easily be misremembering). This may make the Clone impossible in future.
All #[derive]s seem fine. Although there are a few cases of Debug not necessarily having the output we want, long term (e.g. collections::string::FromUtf8Error will print a whole raw Vec<u8> with the [ , , , ] syntax) but its not clear what guarantees we want to give about the precise output of Debug (not many, IMO).
The only dubious implementation is the #[derive(Clone)] for std::thread::Thread. I (very vaguely) recall that there was some discussion about changing the internals of Thread to not have the Arc (I could very easily be misremembering). This may make the Clone impossible in future.
Hm I feel like this was some other structure we may remove the Arc from. I think that this handle must fundamentally have an Arc as it's handed out to other threads for park and unpark. That being said we could also be more conservative for now!
/// This structure represents a safely precompiled version of a format string
/// and its arguments. This cannot be generated at runtime because it cannot
/// safely be done so, so no constructors are given and the fields are private
/// to prevent modification.
///
/// The `format_args!` macro will safely create an instance of this structure
/// and pass it to a function or closure, passed as the first argument. The
/// macro validates the format string at compile-time so usage of the `write`
/// and `format` functions can be safely performed.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy)]
pubstructArguments<'a>{
// Format string pieces to print.
pieces:&'a[&'astr],
// Placeholder specs, or `None` if all specs are default (as in "{}{}").
fmt:Option<&'a[rt::v1::Argument]>,
// Dynamic arguments for interpolation, to be interleaved with string
// pieces. (Every argument is preceded by a string piece.)
args:&'a[ArgumentV1<'a>],
}
I believe that we used to pass the structure by reference but we now pass it by value sometimes necessitating the Copy bound. I would also be fine going back to passing it by reference by convention (I believe there's also an issue about the codegen of pass-by-value which is tangentially related)
RangeFull and RangeTo are Copy but Range and RangeFrom are not.
Either None < Some() or None > Some() (similarly for Result) is arbitrary. Should they really implement PartialOrd at all?
I think so: it is useful for generic code (e.g. when storing things in a tree, the details of the ordering usually don't matter, as long as one exists) and #[derive], e.g. one might have
The first two fields will usually completely distinguish instances of Foo and the last just serves as a tie-break. As we found with Path and #[derive(Show)] previously, being forced to write out the impl manually in cases like this is very annoying. (FWIW, Haskell's Maybe and Either both implement Ord.)
It’s not quite the same as Option, but FWIW None in Python 2 is less than all other objects. In Python 3, it was changed to be non-comparable to other objects.
The only dubious implementation is the #[derive(Clone)] for std::thread::Thread. I (very vaguely) recall that there was some discussion about changing the internals of Thread to not have the Arc (I could very easily be misremembering). This may make the Clone impossible in future.
Hm I feel like this was some other structure we may remove the Arc from. I think that this handle must fundamentally have an Arc as it's handed out to other threads for park and unpark. That being said we could also be more conservative for now!
The Clone is definitely wanted here, and the Arc is intended -- as you say, you want to be able to hand out copies of the handle to place in data structures for use with park and unpark.
Activity
huonw commentedon Mar 2, 2015
cc @aturon, @alexcrichton
stdThe only dubious implementation is the
#[derive(Clone)]forstd::thread::Thread. I (very vaguely) recall that there was some discussion about changing the internals ofThreadto not have theArc(I could very easily be misremembering). This may make theCloneimpossible in future.huonw commentedon Mar 2, 2015
collectionsAll
#[derive]s seem fine. Although there are a few cases ofDebugnot necessarily having the output we want, long term (e.g.collections::string::FromUtf8Errorwill print a whole rawVec<u8>with the[ , , , ]syntax) but its not clear what guarantees we want to give about the precise output ofDebug(not many, IMO).huonw commentedon Mar 2, 2015
coreWhy is
core::fmt::ArgumentsCopy?rust/src/libcore/fmt/mod.rs
Lines 212 to 233 in 1576142
RangeFullandRangeToareCopybutRangeandRangeFromare not.The
Ordering/PartialOrdering ofOptionandResultis inconsistent (in the sense ofOption<T>≅Result<T, ()>):None < Some(_), butErr(_) > Ok(_).huonw commentedon Mar 2, 2015
core::iterAll seems fine: they're essentially all just
#[derive(Clone)]s.(Although I did notice #22950 in the process.)
SimonSapin commentedon Mar 2, 2015
Either
None < Some(_)orNone > Some(_)(similarly forResult) is arbitrary. Should they really implementPartialOrdat all?alexcrichton commentedon Mar 2, 2015
Hm I feel like this was some other structure we may remove the
Arcfrom. I think that this handle must fundamentally have anArcas it's handed out to other threads forparkandunpark. That being said we could also be more conservative for now!I believe that we used to pass the structure by reference but we now pass it by value sometimes necessitating the
Copybound. I would also be fine going back to passing it by reference by convention (I believe there's also an issue about the codegen of pass-by-value which is tangentially related)cc #21846
aturon commentedon Mar 5, 2015
cc me
huonw commentedon Mar 5, 2015
I think so: it is useful for generic code (e.g. when storing things in a tree, the details of the ordering usually don't matter, as long as one exists) and
#[derive], e.g. one might haveThe first two fields will usually completely distinguish instances of
Fooand the last just serves as a tie-break. As we found withPathand#[derive(Show)]previously, being forced to write out theimplmanually in cases like this is very annoying. (FWIW, Haskell'sMaybeandEitherboth implementOrd.)SimonSapin commentedon Mar 5, 2015
It’s not quite the same as
Option, but FWIWNonein Python 2 is less than all other objects. In Python 3, it was changed to be non-comparable to other objects.aturon commentedon Mar 5, 2015
The
Cloneis definitely wanted here, and theArcis intended -- as you say, you want to be able to hand out copies of the handle to place in data structures for use withparkandunpark.aturon commentedon Mar 5, 2015
@huonw
Ugh that's bad. Hopefully the Pod/Copy RFC will help us clean this up.
emberian commentedon Mar 31, 2015
@aturon #21846 is related.
aturon commentedon Apr 1, 2015
I'm going to close this as complete. Thanks for heading this up, @huonw!
Merge pull request rust-lang#22511 from veluca93/optimize-attribute