librustc: Allow &T to be assigned to *T. r=nmatsakis
This commit is contained in:
parent
07f4031bb4
commit
430583c8b4
2 changed files with 23 additions and 3 deletions
|
@ -136,9 +136,9 @@ priv impl Assign {
|
||||||
|
|
||||||
match (a_bnd, b_bnd) {
|
match (a_bnd, b_bnd) {
|
||||||
(Some(a_bnd), Some(b_bnd)) => {
|
(Some(a_bnd), Some(b_bnd)) => {
|
||||||
|
match (ty::get(a_bnd).sty, ty::get(b_bnd).sty) {
|
||||||
// check for a case where a non-region pointer (@, ~) is
|
// check for a case where a non-region pointer (@, ~) is
|
||||||
// being assigned to a region pointer:
|
// being assigned to a region pointer:
|
||||||
match (ty::get(a_bnd).sty, ty::get(b_bnd).sty) {
|
|
||||||
(ty::ty_box(_), ty::ty_rptr(r_b, mt_b)) => {
|
(ty::ty_box(_), ty::ty_rptr(r_b, mt_b)) => {
|
||||||
let nr_b = ty::mk_box(self.infcx.tcx,
|
let nr_b = ty::mk_box(self.infcx.tcx,
|
||||||
{ty: mt_b.ty, mutbl: m_const});
|
{ty: mt_b.ty, mutbl: m_const});
|
||||||
|
@ -184,8 +184,16 @@ priv impl Assign {
|
||||||
a, nr_b, m_imm, b_f.meta.region)
|
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))
|
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…
Add table
Add a link
Reference in a new issue