Skip to content

Commit 430583c

Browse files
committed
librustc: Allow &T to be assigned to *T. r=nmatsakis
1 parent 07f4031 commit 430583c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/librustc/middle/typeck/infer/assignment.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ priv impl Assign {
136136

137137
match (a_bnd, b_bnd) {
138138
(Some(a_bnd), Some(b_bnd)) => {
139-
// check for a case where a non-region pointer (@, ~) is
140-
// being assigned to a region pointer:
141139
match (ty::get(a_bnd).sty, ty::get(b_bnd).sty) {
140+
// check for a case where a non-region pointer (@, ~) is
141+
// being assigned to a region pointer:
142142
(ty::ty_box(_), ty::ty_rptr(r_b, mt_b)) => {
143143
let nr_b = ty::mk_box(self.infcx.tcx,
144144
{ty: mt_b.ty, mutbl: m_const});
@@ -184,8 +184,16 @@ priv impl Assign {
184184
a, nr_b, m_imm, b_f.meta.region)
185185
}
186186

187+
// check for &T being assigned to *T:
188+
(ty::ty_rptr(_, ref a_t), ty::ty_ptr(ref b_t)) => {
189+
match Sub(*self).mts(*a_t, *b_t) {
190+
Ok(_) => Ok(None),
191+
Err(e) => Err(e)
192+
}
193+
}
194+
195+
// otherwise, assignment follows normal subtype rules:
187196
_ => {
188-
// otherwise, assignment follows normal subtype rules:
189197
to_ares(Sub(*self).tys(a, b))
190198
}
191199
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn f(x: *int) {
2+
unsafe {
3+
assert *x == 3;
4+
}
5+
}
6+
7+
fn main() {
8+
f(&3);
9+
}
10+
11+
12+

0 commit comments

Comments
 (0)