Don't CoerceUnsized dyn* to dyn*
This commit is contained in:
parent
0af211af67
commit
6e6c49e7ce
@ -779,7 +779,7 @@ fn assemble_candidates_for_unsizing(
|
||||
|
||||
match (source.kind(), target.kind()) {
|
||||
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
|
||||
(&ty::Dynamic(ref data_a, ..), &ty::Dynamic(ref data_b, ..)) => {
|
||||
(&ty::Dynamic(ref data_a, _, ty::Dyn), &ty::Dynamic(ref data_b, _, ty::Dyn)) => {
|
||||
// Upcast coercions permit several things:
|
||||
//
|
||||
// 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`
|
||||
|
@ -1145,7 +1145,7 @@ fn confirm_builtin_unsize_candidate(
|
||||
}));
|
||||
}
|
||||
|
||||
_ => bug!(),
|
||||
_ => bug!("source: {source}, target: {target}"),
|
||||
};
|
||||
|
||||
Ok(ImplSourceBuiltinData { nested })
|
||||
|
26
src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs
Normal file
26
src/test/ui/dyn-star/dont-unsize-coerce-dyn-star.rs
Normal file
@ -0,0 +1,26 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(dyn_star)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait AddOne {
|
||||
fn add1(&mut self) -> usize;
|
||||
}
|
||||
|
||||
impl AddOne for usize {
|
||||
fn add1(&mut self) -> usize {
|
||||
*self += 1;
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
fn add_one(i: &mut (dyn* AddOne + '_)) -> usize {
|
||||
i.add1()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut x = 42usize as dyn* AddOne;
|
||||
|
||||
println!("{}", add_one(&mut x));
|
||||
println!("{}", add_one(&mut x));
|
||||
}
|
Loading…
Reference in New Issue
Block a user