Skip to content

Commit

Permalink
Rollup merge of #102628 - H4x5:master, r=scottmcm
Browse files Browse the repository at this point in the history
Change the parameter name of From::from to `value`

The `From` trait is currently defined as:
```rust
pub trait From<T>: Sized {
    fn from(_: T) -> Self;
}
```

The name of the argument is `_`. I am proposing to change it to `value`, ie.
```rust
pub trait From<T>: Sized {
    fn from(value: T) -> Self;
}
```

This would be more consistent with the `TryFrom`, which looks like this:
```rust
pub trait TryFrom<T>: Sized {
    type Error;
    fn try_from(value: T) -> Result<Self, Self::Error>;
}
```

The reason for this proposal is twofold:
1. Consistency with the rest of the standard library. The `TryFrom` trait uses `value`, and no `From` implementation uses the default name (as it is quite useless).
2. When generating trait implementations with rust-analyzer/IntelliJ, the parameter name is copied, and it always has to be changed.

Optionally, another name like `x` could be used. I only propose `value` for consistency with `TryFrom`.

Changing parameter names is not a breaking change.

Note: this was originally posted as an internals thread [here](https://internals.rust-lang.org/t/change-the-argument-name-of-from-from/17480)
  • Loading branch information
matthiaskrgr authored Oct 4, 2022
2 parents cdb114e + 8dcecdb commit 17c6582
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ pub trait From<T>: Sized {
#[lang = "from"]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn from(_: T) -> Self;
fn from(value: T) -> Self;
}

/// An attempted conversion that consumes `self`, which may or may not be
Expand Down

0 comments on commit 17c6582

Please sign in to comment.