Commit 5584f04
committed
Add deprecated
Since `RngCore` has been renamed to `Rng`, and `TryRngCore` to `TryRng`,
this adds some deprecated stub traits with the old names that have a
`note` about the new names.
They have supertrait bounds on the new names, along with blanket impls
for the new names:
- `RngCore: Rng`
- `TryRngCore: TryRng`
These can be released in v0.10.x and removed before v1.x.
Though they don't have any methods, due to an odd quirk of how Rust
resolves methods in a generic context (effectively uniting a trait and
all of its supertraits into a single logical method table), the methods
of the new traits are callable from a generic context even without the
new traits in the bounds or even in scope whatsoever:
use rand_core::RngCore;
pub fn foo<R: RngCore>(mut rng: R) -> [u8; 8] {
let mut ret = [0u8; 8];
rng.fill_bytes(&mut ret);
ret
}
This will actually compile with the following warnings:
warning: use of deprecated trait `rand_core::RngCore`: use `Rng` instead
--> src/main.rs:1:16
|
1 | use rand_core::RngCore;
| ^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
warning: use of deprecated trait `rand_core::RngCore`: use `Rng` instead
--> src/main.rs:3:15
|
3 | pub fn foo<R: RngCore>(mut rng: R) -> [u8; 8] {
| ^^^^^^^
I think this will help people upgrade because it will allow a
significant amount of code to continue to compile while also informing
people of the new names and what code needs to be changed.RngCore/TryRngCore forwarding traits1 parent ae88096 commit 5584f04
1 file changed
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
0 commit comments