Rollup merge of #102628 - H4x5:master, r=scottmcm

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)
This commit is contained in:
Matthias Krüger 2022-10-04 06:14:12 +02:00 committed by GitHub
commit 17c65826d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -545,7 +545,7 @@ pub trait From<T>: Sized {
#[lang = "from"] #[lang = "from"]
#[must_use] #[must_use]
#[stable(feature = "rust1", since = "1.0.0")] #[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 /// An attempted conversion that consumes `self`, which may or may not be