-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c06ed0
commit da1b320
Showing
4 changed files
with
46 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// check-pass | ||
|
||
struct Test<T>([T; 1]); | ||
|
||
impl<T> std::ops::Deref for Test<T> { | ||
type Target = [T; 1]; | ||
|
||
fn deref(&self) -> &[T; 1] { | ||
&self.0 | ||
} | ||
} | ||
|
||
fn main() { | ||
let out = Test([(); 1]); | ||
let blah = out.len(); | ||
println!("{}", blah); | ||
} |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
fn main() { | ||
let _ = &&[0] as &[_]; | ||
//~^ ERROR non-primitive cast: `&&[i32; 1]` as `&[_]` | ||
let _ = 7u32 as Option<_>; | ||
//~^ ERROR non-primitive cast: `u32` as `Option<_>` | ||
} |
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 |
---|---|---|
@@ -1,17 +1,11 @@ | ||
error[E0605]: non-primitive cast: `&&[i32; 1]` as `&[_]` | ||
--> $DIR/issue-73886.rs:2:13 | ||
| | ||
LL | let _ = &&[0] as &[_]; | ||
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object | ||
|
||
error[E0605]: non-primitive cast: `u32` as `Option<_>` | ||
--> $DIR/issue-73886.rs:4:13 | ||
--> $DIR/issue-73886.rs:2:13 | ||
| | ||
LL | let _ = 7u32 as Option<_>; | ||
| ^^^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Option<_>::from(7u32)` | ||
| | ||
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0605`. |
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,27 @@ | ||
// check-pass | ||
|
||
struct Test<T, const N: usize>([T; N]); | ||
|
||
impl<T: Copy + Default, const N: usize> Default for Test<T, N> { | ||
fn default() -> Self { | ||
Self([T::default(); N]) | ||
} | ||
} | ||
|
||
impl<T, const N: usize> std::ops::Deref for Test<T, N> { | ||
type Target = [T; N]; | ||
|
||
fn deref(&self) -> &[T; N] { | ||
&self.0 | ||
} | ||
} | ||
|
||
fn test() -> Test<u64, 16> { | ||
let test = Test::default(); | ||
println!("{}", test.len()); | ||
test | ||
} | ||
|
||
fn main() { | ||
test(); | ||
} |