Skip to content

Commit 0af211a

Browse files
Don't allow implement CoerceUnsized into dyn-star
1 parent a3c0a02 commit 0af211a

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
840840
}
841841

842842
// `T` -> `Trait`
843-
(_, &ty::Dynamic(..)) => {
843+
(_, &ty::Dynamic(_, _, ty::Dyn)) => {
844844
candidates.vec.push(BuiltinUnsizeCandidate);
845845
}
846846

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(dyn_star)]
2+
#![allow(incomplete_features)]
3+
4+
use std::fmt::Debug;
5+
6+
fn main() {
7+
let i = 42 as &dyn* Debug;
8+
//~^ ERROR non-primitive cast: `i32` as `&dyn* Debug`
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0605]: non-primitive cast: `i32` as `&dyn* Debug`
2+
--> $DIR/unsize-into-ref-dyn-star.rs:7:13
3+
|
4+
LL | let i = 42 as &dyn* Debug;
5+
| ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0605`.

0 commit comments

Comments
 (0)