Skip to content

Commit da1b320

Browse files
Add new tests, fix up old tests
1 parent 3c06ed0 commit da1b320

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
struct Test<T>([T; 1]);
4+
5+
impl<T> std::ops::Deref for Test<T> {
6+
type Target = [T; 1];
7+
8+
fn deref(&self) -> &[T; 1] {
9+
&self.0
10+
}
11+
}
12+
13+
fn main() {
14+
let out = Test([(); 1]);
15+
let blah = out.len();
16+
println!("{}", blah);
17+
}

src/test/ui/coercion/issue-73886.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
fn main() {
2-
let _ = &&[0] as &[_];
3-
//~^ ERROR non-primitive cast: `&&[i32; 1]` as `&[_]`
42
let _ = 7u32 as Option<_>;
53
//~^ ERROR non-primitive cast: `u32` as `Option<_>`
64
}
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
error[E0605]: non-primitive cast: `&&[i32; 1]` as `&[_]`
2-
--> $DIR/issue-73886.rs:2:13
3-
|
4-
LL | let _ = &&[0] as &[_];
5-
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6-
71
error[E0605]: non-primitive cast: `u32` as `Option<_>`
8-
--> $DIR/issue-73886.rs:4:13
2+
--> $DIR/issue-73886.rs:2:13
93
|
104
LL | let _ = 7u32 as Option<_>;
115
| ^^^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Option<_>::from(7u32)`
126
|
137
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
148

15-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1610

1711
For more information about this error, try `rustc --explain E0605`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// check-pass
2+
3+
struct Test<T, const N: usize>([T; N]);
4+
5+
impl<T: Copy + Default, const N: usize> Default for Test<T, N> {
6+
fn default() -> Self {
7+
Self([T::default(); N])
8+
}
9+
}
10+
11+
impl<T, const N: usize> std::ops::Deref for Test<T, N> {
12+
type Target = [T; N];
13+
14+
fn deref(&self) -> &[T; N] {
15+
&self.0
16+
}
17+
}
18+
19+
fn test() -> Test<u64, 16> {
20+
let test = Test::default();
21+
println!("{}", test.len());
22+
test
23+
}
24+
25+
fn main() {
26+
test();
27+
}

0 commit comments

Comments
 (0)