Skip to content

Commit 6e6c49e

Browse files
Don't CoerceUnsized dyn* to dyn*
1 parent 0af211a commit 6e6c49e

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
779779

780780
match (source.kind(), target.kind()) {
781781
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
782-
(&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => {
782+
(&ty::Dynamic(ref data_a, _, ty::Dyn), &ty::Dynamic(ref data_b, _, ty::Dyn)) => {
783783
// Upcast coercions permit several things:
784784
//
785785
// 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11451145
}));
11461146
}
11471147

1148-
_ => bug!(),
1148+
_ => bug!("source: {source}, target: {target}"),
11491149
};
11501150

11511151
Ok(ImplSourceBuiltinData { nested })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
3+
#![feature(dyn_star)]
4+
#![allow(incomplete_features)]
5+
6+
trait AddOne {
7+
fn add1(&mut self) -> usize;
8+
}
9+
10+
impl AddOne for usize {
11+
fn add1(&mut self) -> usize {
12+
*self += 1;
13+
*self
14+
}
15+
}
16+
17+
fn add_one(i: &mut (dyn* AddOne + '_)) -> usize {
18+
i.add1()
19+
}
20+
21+
fn main() {
22+
let mut x = 42usize as dyn* AddOne;
23+
24+
println!("{}", add_one(&mut x));
25+
println!("{}", add_one(&mut x));
26+
}

0 commit comments

Comments
 (0)