Rollup merge of #113469 - JohnTitor:rm-default-free-fn, r=Amanieu
Remove `default_free_fn` feature Closes #73014 r? ``@Amanieu``
This commit is contained in:
commit
ec479bae7f
@ -133,51 +133,6 @@ pub trait Default: Sized {
|
|||||||
fn default() -> Self;
|
fn default() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the default value of a type according to the `Default` trait.
|
|
||||||
///
|
|
||||||
/// The type to return is inferred from context; this is equivalent to
|
|
||||||
/// `Default::default()` but shorter to type.
|
|
||||||
///
|
|
||||||
/// For example:
|
|
||||||
/// ```
|
|
||||||
/// #![feature(default_free_fn)]
|
|
||||||
///
|
|
||||||
/// use std::default::default;
|
|
||||||
///
|
|
||||||
/// #[derive(Default)]
|
|
||||||
/// struct AppConfig {
|
|
||||||
/// foo: FooConfig,
|
|
||||||
/// bar: BarConfig,
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// #[derive(Default)]
|
|
||||||
/// struct FooConfig {
|
|
||||||
/// foo: i32,
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// #[derive(Default)]
|
|
||||||
/// struct BarConfig {
|
|
||||||
/// bar: f32,
|
|
||||||
/// baz: u8,
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// fn main() {
|
|
||||||
/// let options = AppConfig {
|
|
||||||
/// foo: default(),
|
|
||||||
/// bar: BarConfig {
|
|
||||||
/// bar: 10.1,
|
|
||||||
/// ..default()
|
|
||||||
/// },
|
|
||||||
/// };
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[unstable(feature = "default_free_fn", issue = "73014")]
|
|
||||||
#[must_use]
|
|
||||||
#[inline]
|
|
||||||
pub fn default<T: Default>() -> T {
|
|
||||||
Default::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Derive macro generating an impl of the trait `Default`.
|
/// Derive macro generating an impl of the trait `Default`.
|
||||||
#[rustc_builtin_macro(Default, attributes(default))]
|
#[rustc_builtin_macro(Default, attributes(default))]
|
||||||
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
|
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
# `default_free_fn`
|
|
||||||
|
|
||||||
The tracking issue for this feature is: [#73014]
|
|
||||||
|
|
||||||
[#73014]: https://github.com/rust-lang/rust/issues/73014
|
|
||||||
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
Adds a free `default()` function to the `std::default` module. This function
|
|
||||||
just forwards to [`Default::default()`], but may remove repetition of the word
|
|
||||||
"default" from the call site.
|
|
||||||
|
|
||||||
[`Default::default()`]: ../../std/default/trait.Default.html#tymethod.default
|
|
||||||
|
|
||||||
Here is an example:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
#![feature(default_free_fn)]
|
|
||||||
use std::default::default;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct AppConfig {
|
|
||||||
foo: FooConfig,
|
|
||||||
bar: BarConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct FooConfig {
|
|
||||||
foo: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct BarConfig {
|
|
||||||
bar: f32,
|
|
||||||
baz: u8,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let options = AppConfig {
|
|
||||||
foo: default(),
|
|
||||||
bar: BarConfig {
|
|
||||||
bar: 10.1,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
```
|
|
@ -1,18 +1,3 @@
|
|||||||
error[E0425]: cannot find function `default` in this scope
|
|
||||||
--> $DIR/issue-2356.rs:31:5
|
|
||||||
|
|
|
||||||
LL | default();
|
|
||||||
| ^^^^^^^
|
|
||||||
|
|
|
||||||
help: you might have meant to call the associated function
|
|
||||||
|
|
|
||||||
LL | Self::default();
|
|
||||||
| ~~~~~~~~~~~~~
|
|
||||||
help: consider importing this function
|
|
||||||
|
|
|
||||||
LL + use std::default::default;
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0425]: cannot find value `whiskers` in this scope
|
error[E0425]: cannot find value `whiskers` in this scope
|
||||||
--> $DIR/issue-2356.rs:39:5
|
--> $DIR/issue-2356.rs:39:5
|
||||||
|
|
|
|
||||||
@ -64,6 +49,12 @@ error[E0425]: cannot find function `clone` in this scope
|
|||||||
LL | clone();
|
LL | clone();
|
||||||
| ^^^^^ help: you might have meant to call the method: `self.clone`
|
| ^^^^^ help: you might have meant to call the method: `self.clone`
|
||||||
|
|
||||||
|
error[E0425]: cannot find function `default` in this scope
|
||||||
|
--> $DIR/issue-2356.rs:31:5
|
||||||
|
|
|
||||||
|
LL | default();
|
||||||
|
| ^^^^^^^ help: you might have meant to call the associated function: `Self::default`
|
||||||
|
|
||||||
error[E0425]: cannot find function `shave` in this scope
|
error[E0425]: cannot find function `shave` in this scope
|
||||||
--> $DIR/issue-2356.rs:41:5
|
--> $DIR/issue-2356.rs:41:5
|
||||||
|
|
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user