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

cmp: Use default methods in trait Ord, only require Ord::lt #7765

Closed
wants to merge 1 commit into from
Closed

cmp: Use default methods in trait Ord, only require Ord::lt #7765

wants to merge 1 commit into from

Conversation

bluss
Copy link
Member

@bluss bluss commented Jul 13, 2013

Rust will allow to supply default methods for all four methods, but we
don't have any nice error reporting for the case where at least one
method must be implemented, but it's arbitrary which.

So in this case, we require lt, but allow implementing the others if needed.

* (cf. IEEE 754-2008 section 5.11).
*/
#[allow(default_methods)]
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need this any more, a very recently landed commit now allows these by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it's needed to get past stage0

Copy link
Member

Choose a reason for hiding this comment

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

Oh good point... Could you put in a NOTE to remove it?

@huonw
Copy link
Member

huonw commented Jul 13, 2013

Fwiw, the minimum implementation is often lt (e.g. Haskell). Also, it is normal to provide defaults for all functions (e.g. Haskell again).

@alexcrichton
Copy link
Member

Oh I didn't realize that le was to be implemented. I agree with @huonw that lt should be unimplemented instead of le

@bluss
Copy link
Member Author

bluss commented Jul 13, 2013

Right huonw, however we can't provide a default for all four methods -- realistically, because we fail so hilariously if the user does impl Ord for X {}; we will happily compile mutally infinitely recursive methods.

I chose le because that's what the comment already in place stated.

@alexcrichton
Copy link
Member

Of course don't provide defaults for all of them, but it seems more natural to define lt rather than le imo

@bluss
Copy link
Member Author

bluss commented Jul 13, 2013

I agree about lt, I don't know why @brson wrote le in his comment there.

@bluss
Copy link
Member Author

bluss commented Jul 13, 2013

I find two cases of using "impl Ord" in a pattern of only implementing one method and then reusing it, and those use lt. in Json and in Timespec.

It will be simpler to implement only one method for Ord, while we also
allow implementing all four Ord methods for semantics or performance
reasons.

We only supply three default methods (and not four), because don't have
any nice error reporting for the case where at least one method must be
implemented, but it's arbitrary which.
@huonw
Copy link
Member

huonw commented Jul 13, 2013

Well, it seems that I was wrong, Haskell uses le.

And, fwiw, Haskell actually offers default implementations for all the functions, it is up to the programmer to check that it is coherent. (That said, it should be entirely possible to tell the compiler "at least one of these must be implemented", I opened #7771 about that.)

@emberian
Copy link
Member

I still think Ord is broken and ought to be removed or reformed, as it doesn't adequately express partial order, aiui... there needs to be a third value, for "no comparison."

@emberian
Copy link
Member

(I'd still r+ though)

bors added a commit that referenced this pull request Jul 13, 2013
Rust will allow to supply default methods for all four methods, but we
don't have any nice error reporting for the case where at least one
method must be implemented, but it's arbitrary which.

So in this case, we require `lt`, but allow implementing the others if needed.
@bors bors closed this Jul 13, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 30, 2022
try reading rust-version from Cargo.toml

Cargo.toml can contain a field `rust-version`, that acts like a MSRV of
clippy.toml file: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field
This will try to read that field and use it, if the clippy.toml config
has no `msrv` entry

changelog: respect `rust-version` from `Cargo.toml`

closes rust-lang#8746
closes rust-lang#7765
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.

5 participants