-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementations for converting boxed slices into boxed arrays
This mirrors the implementations of reference slices into arrays.
- Loading branch information
1 parent
4be0675
commit 32324d2
Showing
9 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/ui/const-generics/array-impls/alloc-types-no-impls-length-33.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// ignore-tidy-linelength | ||
|
||
use std::{convert::TryFrom, rc::Rc, sync::Arc}; | ||
|
||
pub fn no_box() { | ||
let boxed_slice = Box::new([0; 33]) as Box<[i32]>; | ||
let boxed_array = <Box<[i32; 33]>>::try_from(boxed_slice); | ||
//~^ ERROR the trait bound `std::boxed::Box<[i32; 33]>: std::convert::From<std::boxed::Box<[i32]>>` is not satisfied | ||
//~^^ ERROR the trait bound `std::boxed::Box<[i32; 33]>: std::convert::TryFrom<std::boxed::Box<[i32]>>` is not satisfied | ||
} | ||
|
||
pub fn no_rc() { | ||
let boxed_slice = Rc::new([0; 33]) as Rc<[i32]>; | ||
let boxed_array = <Rc<[i32; 33]>>::try_from(boxed_slice); | ||
//~^ ERROR the trait bound `std::rc::Rc<[i32; 33]>: std::convert::From<std::rc::Rc<[i32]>>` is not satisfied | ||
//~^^ ERROR the trait bound `std::rc::Rc<[i32; 33]>: std::convert::TryFrom<std::rc::Rc<[i32]>>` is not satisfied | ||
} | ||
|
||
pub fn no_arc() { | ||
let boxed_slice = Arc::new([0; 33]) as Arc<[i32]>; | ||
let boxed_array = <Arc<[i32; 33]>>::try_from(boxed_slice); | ||
//~^ ERROR the trait bound `std::sync::Arc<[i32; 33]>: std::convert::From<std::sync::Arc<[i32]>>` is not satisfied | ||
//~^^ ERROR the trait bound `std::sync::Arc<[i32; 33]>: std::convert::TryFrom<std::sync::Arc<[i32]>>` is not satisfied | ||
} | ||
|
||
fn main() {} |
75 changes: 75 additions & 0 deletions
75
src/test/ui/const-generics/array-impls/alloc-types-no-impls-length-33.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
error[E0277]: the trait bound `std::boxed::Box<[i32; 33]>: std::convert::From<std::boxed::Box<[i32]>>` is not satisfied | ||
--> $DIR/alloc-types-no-impls-length-33.rs:7:23 | ||
| | ||
LL | let boxed_array = <Box<[i32; 33]>>::try_from(boxed_slice); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::boxed::Box<[i32]>>` is not implemented for `std::boxed::Box<[i32; 33]>` | ||
| | ||
= help: the following implementations were found: | ||
<std::boxed::Box<(dyn std::error::Error + 'a)> as std::convert::From<E>> | ||
<std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<&str>> | ||
<std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<std::borrow::Cow<'a, str>>> | ||
<std::boxed::Box<(dyn std::error::Error + 'static)> as std::convert::From<std::string::String>> | ||
and 16 others | ||
= note: required because of the requirements on the impl of `std::convert::Into<std::boxed::Box<[i32; 33]>>` for `std::boxed::Box<[i32]>` | ||
= note: required because of the requirements on the impl of `std::convert::TryFrom<std::boxed::Box<[i32]>>` for `std::boxed::Box<[i32; 33]>` | ||
|
||
error[E0277]: the trait bound `std::boxed::Box<[i32; 33]>: std::convert::TryFrom<std::boxed::Box<[i32]>>` is not satisfied | ||
--> $DIR/alloc-types-no-impls-length-33.rs:7:23 | ||
| | ||
LL | let boxed_array = <Box<[i32; 33]>>::try_from(boxed_slice); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::TryFrom<std::boxed::Box<[i32]>>` is not implemented for `std::boxed::Box<[i32; 33]>` | ||
| | ||
= help: the following implementations were found: | ||
<std::boxed::Box<[T; _]> as std::convert::TryFrom<std::boxed::Box<[T]>>> | ||
|
||
error[E0277]: the trait bound `std::rc::Rc<[i32; 33]>: std::convert::From<std::rc::Rc<[i32]>>` is not satisfied | ||
--> $DIR/alloc-types-no-impls-length-33.rs:14:23 | ||
| | ||
LL | let boxed_array = <Rc<[i32; 33]>>::try_from(boxed_slice); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::rc::Rc<[i32]>>` is not implemented for `std::rc::Rc<[i32; 33]>` | ||
| | ||
= help: the following implementations were found: | ||
<std::rc::Rc<T> as std::convert::From<T>> | ||
<std::rc::Rc<T> as std::convert::From<std::boxed::Box<T>>> | ||
<std::rc::Rc<[T]> as std::convert::From<&[T]>> | ||
<std::rc::Rc<[T]> as std::convert::From<std::vec::Vec<T>>> | ||
and 8 others | ||
= note: required because of the requirements on the impl of `std::convert::Into<std::rc::Rc<[i32; 33]>>` for `std::rc::Rc<[i32]>` | ||
= note: required because of the requirements on the impl of `std::convert::TryFrom<std::rc::Rc<[i32]>>` for `std::rc::Rc<[i32; 33]>` | ||
|
||
error[E0277]: the trait bound `std::rc::Rc<[i32; 33]>: std::convert::TryFrom<std::rc::Rc<[i32]>>` is not satisfied | ||
--> $DIR/alloc-types-no-impls-length-33.rs:14:23 | ||
| | ||
LL | let boxed_array = <Rc<[i32; 33]>>::try_from(boxed_slice); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::TryFrom<std::rc::Rc<[i32]>>` is not implemented for `std::rc::Rc<[i32; 33]>` | ||
| | ||
= help: the following implementations were found: | ||
<std::rc::Rc<[T; _]> as std::convert::TryFrom<std::rc::Rc<[T]>>> | ||
|
||
error[E0277]: the trait bound `std::sync::Arc<[i32; 33]>: std::convert::From<std::sync::Arc<[i32]>>` is not satisfied | ||
--> $DIR/alloc-types-no-impls-length-33.rs:21:23 | ||
| | ||
LL | let boxed_array = <Arc<[i32; 33]>>::try_from(boxed_slice); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::sync::Arc<[i32]>>` is not implemented for `std::sync::Arc<[i32; 33]>` | ||
| | ||
= help: the following implementations were found: | ||
<std::sync::Arc<T> as std::convert::From<T>> | ||
<std::sync::Arc<T> as std::convert::From<std::boxed::Box<T>>> | ||
<std::sync::Arc<[T]> as std::convert::From<&[T]>> | ||
<std::sync::Arc<[T]> as std::convert::From<std::vec::Vec<T>>> | ||
and 8 others | ||
= note: required because of the requirements on the impl of `std::convert::Into<std::sync::Arc<[i32; 33]>>` for `std::sync::Arc<[i32]>` | ||
= note: required because of the requirements on the impl of `std::convert::TryFrom<std::sync::Arc<[i32]>>` for `std::sync::Arc<[i32; 33]>` | ||
|
||
error[E0277]: the trait bound `std::sync::Arc<[i32; 33]>: std::convert::TryFrom<std::sync::Arc<[i32]>>` is not satisfied | ||
--> $DIR/alloc-types-no-impls-length-33.rs:21:23 | ||
| | ||
LL | let boxed_array = <Arc<[i32; 33]>>::try_from(boxed_slice); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::TryFrom<std::sync::Arc<[i32]>>` is not implemented for `std::sync::Arc<[i32; 33]>` | ||
| | ||
= help: the following implementations were found: | ||
<std::sync::Arc<[T; _]> as std::convert::TryFrom<std::sync::Arc<[T]>>> | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |