librustc: Allow &T to be assigned to *T. r=nmatsakis
This commit is contained in:
parent
07f4031bb4
commit
430583c8b4
@ -136,9 +136,9 @@ priv impl Assign {
|
||||
|
||||
match (a_bnd, b_bnd) {
|
||||
(Some(a_bnd), Some(b_bnd)) => {
|
||||
// check for a case where a non-region pointer (@, ~) is
|
||||
// being assigned to a region pointer:
|
||||
match (ty::get(a_bnd).sty, ty::get(b_bnd).sty) {
|
||||
// check for a case where a non-region pointer (@, ~) is
|
||||
// being assigned to a region pointer:
|
||||
(ty::ty_box(_), ty::ty_rptr(r_b, mt_b)) => {
|
||||
let nr_b = ty::mk_box(self.infcx.tcx,
|
||||
{ty: mt_b.ty, mutbl: m_const});
|
||||
@ -184,8 +184,16 @@ priv impl Assign {
|
||||
a, nr_b, m_imm, b_f.meta.region)
|
||||
}
|
||||
|
||||
// check for &T being assigned to *T:
|
||||
(ty::ty_rptr(_, ref a_t), ty::ty_ptr(ref b_t)) => {
|
||||
match Sub(*self).mts(*a_t, *b_t) {
|
||||
Ok(_) => Ok(None),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, assignment follows normal subtype rules:
|
||||
_ => {
|
||||
// otherwise, assignment follows normal subtype rules:
|
||||
to_ares(Sub(*self).tys(a, b))
|
||||
}
|
||||
}
|
||||
|
12
src/test/run-pass/unsafe-pointer-assignability.rs
Normal file
12
src/test/run-pass/unsafe-pointer-assignability.rs
Normal file
@ -0,0 +1,12 @@
|
||||
fn f(x: *int) {
|
||||
unsafe {
|
||||
assert *x == 3;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
f(&3);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user