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

Missing Clone bound causes compilation of 0.3.5 to fail #2

Closed
phrohdoh opened this issue Jul 26, 2017 · 6 comments
Closed

Missing Clone bound causes compilation of 0.3.5 to fail #2

phrohdoh opened this issue Jul 26, 2017 · 6 comments
Assignees

Comments

@phrohdoh
Copy link

   Compiling fraction v0.3.5
error[E0277]: the trait bound `T: std::clone::Clone` is not satisfied
   --> /Users/thill/.cargo/registry/src/github.com-1ecc6299db9ec823/fraction-0.3.5/src/lib.rs:149:21
    |
149 |     Rational (Sign, Ratio<T>),
    |                     ^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `T`
    |
    = help: consider adding a `where T: std::clone::Clone` bound
    = note: required because of the requirements on the impl of `std::hash::Hash` for `num::rational::Ratio<T>`
    = note: required by `std::hash::Hash::hash`

error[E0277]: the trait bound `T: num::Integer` is not satisfied
   --> /Users/thill/.cargo/registry/src/github.com-1ecc6299db9ec823/fraction-0.3.5/src/lib.rs:149:21
    |
149 |     Rational (Sign, Ratio<T>),
    |                     ^^^^^^^^^ the trait `num::Integer` is not implemented for `T`
    |
    = help: consider adding a `where T: num::Integer` bound
    = note: required because of the requirements on the impl of `std::hash::Hash` for `num::rational::Ratio<T>`
    = note: required by `std::hash::Hash::hash`

error: aborting due to previous error(s)
error: Could not compile `fraction`.
Build failed, waiting for other jobs to finish...
error: build failed
@phrohdoh
Copy link
Author

These changes fixed compilation but I do not know if they are the correct, desired changes:

diff --git a/src/lib.rs b/src/lib.rs
index ed12b8c..778d3fe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -145,7 +145,9 @@ impl fmt::Display for Sign {
 /// assert_eq! (first + second, F::new (3, 4));
 /// ```
 #[derive (Clone, Hash, Debug)]
-pub enum GenericFraction<T> {
+pub enum GenericFraction<T>
+    where T: Clone + Integer
+{
     Rational (Sign, Ratio<T>),
     Infinity (Sign),
     NaN
@@ -154,7 +156,7 @@ pub enum GenericFraction<T> {
 
 
 /// Copy semantics to be applied for the target type, but only if T also has it.
-impl<T> Copy for GenericFraction<T> where T: Copy {}
+impl<T> Copy for GenericFraction<T> where T: Copy + Integer {}
 
 
 
@@ -1522,7 +1524,7 @@ impl<T: Clone + Integer> /*Float for*/ GenericFraction<T> {
 
 
 
-impl<T: fmt::Display + Eq + One> fmt::Display for GenericFraction<T> {
+impl<T: fmt::Display + Eq + One + Clone + Integer> fmt::Display for GenericFraction<T> {
     fn fmt (&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             GenericFraction::NaN => write! (f, "NaN"),

@dnsl48 dnsl48 self-assigned this Jul 26, 2017
@dnsl48
Copy link
Owner

dnsl48 commented Jul 26, 2017

Woah, it seems like in spite of having a dependency num = 0.1.37, cargo is still trying to install the latest 0.1.40, which seems to have some breaking changes around Ratio requirements.

@phrohdoh
Copy link
Author

To require exactly 0.1.37 you want num = "=0.1.37" I believe.

@dnsl48
Copy link
Owner

dnsl48 commented Jul 26, 2017

Yes, that is so. However, even that doesn't help in this particular case, since num itself does only apply semver requirements for its subpackages - so the latest ratio module is going to be installed every time.

@dnsl48
Copy link
Owner

dnsl48 commented Jul 26, 2017

Anyway, the fix seems to be correct, since we can only operate with integers. I'll make the patch, thank you!

@dnsl48
Copy link
Owner

dnsl48 commented Jul 26, 2017

v0.3.6 with the fix has been published

@dnsl48 dnsl48 closed this as completed Jul 26, 2017
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

No branches or pull requests

2 participants