Skip to content

Commit d6f7aad

Browse files
committed
Make Default const and add some const Default impls
Full list of `impl const Default` types: - () - bool - char - Cell - std::ascii::Char - usize - u8 - u16 - u32 - u64 - u128 - i8 - i16 - i32 - i64 - i128 - f16 - f32 - f64 - f128 - std::marker::PhantomData<T> - Option<T> - std::iter::Empty<T> - std::ptr::Alignment - &[T] - &mut [T] - &str - &mut str - String - Vec<T>
1 parent 9ac0901 commit d6f7aad

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

tests/ui/or_fun_call.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ fn fn_call_in_nested_expr() {
406406
val: String::from("123"),
407407
});
408408

409-
let _ = opt_foo.unwrap_or_else(|| Foo { val: String::default() });
410-
//~^ or_fun_call
409+
// ok, `String::default()` is now `const`
410+
let _ = opt_foo.unwrap_or(Foo { val: String::default() });
411411
}
412412

413413
mod result_map_or {

tests/ui/or_fun_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ fn fn_call_in_nested_expr() {
406406
val: String::from("123"),
407407
});
408408

409+
// ok, `String::default()` is now `const`
409410
let _ = opt_foo.unwrap_or(Foo { val: String::default() });
410-
//~^ or_fun_call
411411
}
412412

413413
mod result_map_or {

tests/ui/or_fun_call.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ error: use of `unwrap_or` to construct default value
240240
LL | let _ = opt.unwrap_or({ i32::default() });
241241
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
242242

243-
error: function call inside of `unwrap_or`
244-
--> tests/ui/or_fun_call.rs:409:21
245-
|
246-
LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() });
247-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })`
248-
249243
error: function call inside of `map_or`
250244
--> tests/ui/or_fun_call.rs:424:19
251245
|
@@ -264,5 +258,5 @@ error: function call inside of `get_or_insert`
264258
LL | let _ = x.get_or_insert(g());
265259
| ^^^^^^^^^^^^^^^^^^ help: try: `get_or_insert_with(g)`
266260

267-
error: aborting due to 41 previous errors
261+
error: aborting due to 40 previous errors
268262

0 commit comments

Comments
 (0)