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

clippy: From instead of Into. #120

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

waywardmonkeys
Copy link
Contributor

I didn't include this in #119 as I wasn't sure if it would require a version bump and therefore be more controversial.

@cuviper
Copy link
Member

cuviper commented Aug 31, 2023

It would be a problem if folks could write their own From<Ratio<Local>> for (Local, Local), but neither Ratio<Local> nor (Local, Local) are considered local to the crate defining Local. So num-rational users can't write this: playground

use num_rational::Ratio;

pub struct N(i32);

impl From<Ratio<N>> for (N, N) {
    fn from(val: Ratio<N>) -> (N, N) {
        (val.numer, val.denom)
    }
}
error[[E0117]](https://doc.rust-lang.org/stable/error_codes/E0117.html): only traits defined in the current crate can be implemented for arbitrary types
 --> src/lib.rs:5:1
  |
5 | impl From<Ratio<N>> for (N, N) {
  | ^^^^^--------------^^^^^------
  | |    |                  |
  | |    |                  this is not defined in the current crate because tuples are always foreign
  | |    `Ratio` is not defined in the current crate
  | impl doesn't use only types from inside the current crate
  |
  = note: define and implement a trait or new type instead

However, it does require Rust 1.41 for RFC 2451. CI on 1.31.0 says:

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
    --> src/lib.rs:1124:1
     |
1124 | impl<T> From<Ratio<T>> for (T, T) {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
     |
     = note: only traits defined in the current crate can be implemented for a type parameter

@cuviper
Copy link
Member

cuviper commented Aug 31, 2023

(We'll eventually bump MSRV -- I just haven't made any specific plans yet...)

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.

None yet

2 participants