Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace Neg example with something more evocative of negation #35830

Merged
merged 1 commit into from
Aug 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,26 +470,37 @@ rem_impl_float! { f32 f64 }
///
/// # Examples
///
/// A trivial implementation of `Neg`. When `-Foo` happens, it ends up calling
/// `neg`, and therefore, `main` prints `Negating!`.
/// An implementation of `Neg` for `Sign`, which allows the use of `-` to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma might be incorrect here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe so. It's a non-restrictive which clause.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: the comma might be unnecessary, not strictly incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how relevant your avatar is for this PR, given that it's a cyclic set of invertible elements. :P

Copy link
Contributor Author

@matthew-piziak matthew-piziak Aug 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand by the necessity of this comma (Strunk & White II.3), but I certainly won't fight to the death over it. I'm happy to remove it if it truly feels awkward to read.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the comma here, but I also tend to use commas a lot more than most people.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no no, you have convinced me. not that you needed to 😄

/// negate its value.
///
/// ```
/// use std::ops::Neg;
///
/// struct Foo;
/// #[derive(Debug, PartialEq)]
/// enum Sign {
/// Negative,
/// Zero,
/// Positive,
/// }
///
/// impl Neg for Foo {
/// type Output = Foo;
/// impl Neg for Sign {
/// type Output = Sign;
///
/// fn neg(self) -> Foo {
/// println!("Negating!");
/// self
/// fn neg(self) -> Sign {
/// match self {
/// Sign::Negative => Sign::Positive,
/// Sign::Zero => Sign::Zero,
/// Sign::Positive => Sign::Negative,
/// }
/// }
/// }
///
/// fn main() {
/// -Foo;
/// }
/// // a negative positive is a negative
/// assert_eq!(-Sign::Positive, Sign::Negative);
/// // a double negative is a positive
/// assert_eq!(-Sign::Negative, Sign::Positive);
/// // zero is its own negation
/// assert_eq!(-Sign::Zero, Sign::Zero);
/// ```
#[lang = "neg"]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down