Skip to content

Cleaned up, documented, wrote tests for std::bool #10007

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

Merged
merged 1 commit into from
Oct 24, 2013

Conversation

Kimundi
Copy link
Member

@Kimundi Kimundi commented Oct 21, 2013

Additionally:

  • Sorted the prelude reexports
  • Removed unused import warning in std::mem and cleaned it up too

(I was bored 👻 )

@thestinger
Copy link
Contributor

I think the value of duplicating the standard operator traits is questionable but I've never been sure enough to go ahead and remove these functions.


/////////////////////////////////////////////////////////////////////////////
// Trait impls on `bool`
/////////////////////////////////////////////////////////////////////////////
Copy link
Member

Choose a reason for hiding this comment

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

I think that this may show up with a lot of slashes on the documentation of FromStr for bool, could you check to make sure that this doesn't show up?

@alexcrichton
Copy link
Member

Looks good to me! So long as the rustdoc documentation looks OK, r+

/// assert_eq!(std::bool::is_true(false), false);
/// ```
#[inline]
pub fn is_true(v: bool) -> bool { v }
Copy link
Member

Choose a reason for hiding this comment

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

This function seems extremely removable, as does is_false and the various operator wrappers.

Copy link
Member

Choose a reason for hiding this comment

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

Especially now that we have a trait & they are methods.

@Kimundi
Copy link
Member Author

Kimundi commented Oct 22, 2013

The rustdocs look fine, those kinds of comment decorators get filtered out. :)

@Kimundi
Copy link
Member Author

Kimundi commented Oct 22, 2013

A general note to the 'useless' functions and methods and, or, xor, is_false, is_true etc:

I completely agree that they serve no practical purpose for anyone who has used a C-like language for more than half an hour. But I think their existence can still be justified:

  • They serve as an excellent example for newcomers of how you can add methods to even build-in primitive types
  • They can be useful for function compositions
  • They are very low maintenance
  • They are good for example and toy code
  • Sometimes an foo().is_true() reads better, even if it is not necessary.

Ideally we could just implement the freestanding functions as methods on bool directly once, and call them like freestanding ones using unified function call syntax, but we're not there yet. The lack of unified call syntax is also the reason why I kept both sets of functions and methods for now; otherwise they would become even less useful than they already are.

If those are weak reasons, I might also just remove them, but I don't see any harm in keeping them.


Related, I added the BitAnd, BitOr and BitXor impls so that bools can be used in generic code that uses them. I though that was in general how we handle the situation with types that implement an operator natively?

@huonw
Copy link
Member

huonw commented Oct 22, 2013

They serve as an excellent example for newcomers of how you can add methods to even build-in primitive types

They are good for example and toy code

Probably better served by examples written expressly for these purposes (e.g. in a trait tutorial).

They can be useful for function compositions

You mean like foo().and(bar().or(baz()) rather than foo() & (bar() | baz())?

They are very low maintenance

But it's non-zero: e.g. keeping the doc examples up-to-date.

Sometimes an foo().is_true() reads better, even if it is not necessary.

This is a little like people doing if blah() == True: in Python... I think this is an ugly & pointless antipattern. (... this would also leave us with

if (blah().is_true() == is_true(true)) == is_false(true.is_true()) { ... }

being legal.)

I don't see any harm in keeping them

They make this file 600 lines with a plethora of weird and wonderful and useless functions & methods, rather than keeping it simple, and the bool API really doesn't need to be huge and complicated like this.

I though that was in general how we handle the situation with types that implement an operator natively?

This is correct.


I'm not too fussed about keeping the .and, .xor and .or methods, since they make the eagerness properties clearer, but I definitely think the freestanding functions and the is_ functions need to go.

@Kimundi
Copy link
Member Author

Kimundi commented Oct 22, 2013

Okay then, removed the unnecessary functions and methods.

Nothing else used them anyway, and we'll probably get unified function call syntax before someone wants to.

@adrientetar
Copy link
Contributor

@Kimundi Can you squash your changes in one commit?
If we were to merge this in its current state we'd have a commit that adds stuff that gets removed by the commit that follows, in other words, ghost changes. This is dirty and should be avoided.

Removed unused import warning in std::mem and cleaned it up too

Removed is_true and is_false from std::bool

Removed freestanding functions in std::bool
@Kimundi
Copy link
Member Author

Kimundi commented Oct 24, 2013

@adridu59: Done.

bors added a commit that referenced this pull request Oct 24, 2013
Additionally:
- Sorted the prelude reexports
- Removed unused import warning in std::mem and cleaned it up too

(I was bored 👻 )
@bors bors closed this Oct 24, 2013
@bors bors merged commit e53aae4 into rust-lang:master Oct 24, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 1, 2022
Fix ICE in `result_large_err` with uninhabited enums

fixes rust-lang#10005
changelog: `result_large_err`: Fix ICE with uninhabited enums
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants