about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-10-04 06:14:12 +0200
committerGitHub <noreply@github.com>2022-10-04 06:14:12 +0200
commit17c65826d34e88d545415f0a735c7916d0e98371 (patch)
tree6781780b6151d3675c040bd98b79a2ba97091f76
parentcdb114ea826689442534f606189ca57b13811941 (diff)
parent8dcecdb4876e6f4ddc9ea392c0191874676f80de (diff)
downloadrust-17c65826d34e88d545415f0a735c7916d0e98371.tar.gz
rust-17c65826d34e88d545415f0a735c7916d0e98371.zip
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)
-rw-r--r--library/core/src/convert/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs
index 223695c2bec..33493964bad 100644
--- a/library/core/src/convert/mod.rs
+++ b/library/core/src/convert/mod.rs
@@ -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