Skip to content

Commit 4dd368b

Browse files
committed
Normalize associated types in with_field_tys
1 parent 9e4e882 commit 4dd368b

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/librustc/middle/ty.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct CrateAnalysis<'tcx> {
107107
pub glob_map: Option<GlobMap>,
108108
}
109109

110-
#[derive(Copy, PartialEq, Eq, Hash)]
110+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
111111
pub struct field<'tcx> {
112112
pub name: ast::Name,
113113
pub mt: mt<'tcx>
@@ -7212,6 +7212,12 @@ impl<'tcx> HasProjectionTypes for FnSig<'tcx> {
72127212
}
72137213
}
72147214

7215+
impl<'tcx> HasProjectionTypes for field<'tcx> {
7216+
fn has_projection_types(&self) -> bool {
7217+
self.mt.ty.has_projection_types()
7218+
}
7219+
}
7220+
72157221
impl<'tcx> HasProjectionTypes for BareFnTy<'tcx> {
72167222
fn has_projection_types(&self) -> bool {
72177223
self.sig.has_projection_types()
@@ -7311,3 +7317,11 @@ impl<'tcx> Repr<'tcx> for UnboxedClosureUpvar<'tcx> {
73117317
self.ty.repr(tcx))
73127318
}
73137319
}
7320+
7321+
impl<'tcx> Repr<'tcx> for field<'tcx> {
7322+
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
7323+
format!("field({},{})",
7324+
self.name.repr(tcx),
7325+
self.mt.repr(tcx))
7326+
}
7327+
}

src/librustc/middle/ty_fold.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
273273
}
274274
}
275275

276+
impl<'tcx> TypeFoldable<'tcx> for ty::field<'tcx> {
277+
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::field<'tcx> {
278+
ty::field {
279+
name: self.name,
280+
mt: self.mt.fold_with(folder),
281+
}
282+
}
283+
}
284+
276285
impl<'tcx> TypeFoldable<'tcx> for ty::Region {
277286
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Region {
278287
folder.fold_region(*self)

src/librustc_trans/trans/expr.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use trans::debuginfo;
5050
use trans::glue;
5151
use trans::machine;
5252
use trans::meth;
53+
use trans::monomorphize;
5354
use trans::inline;
5455
use trans::tvec;
5556
use trans::type_of;
@@ -1318,7 +1319,9 @@ pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>,
13181319
{
13191320
match ty.sty {
13201321
ty::ty_struct(did, substs) => {
1321-
op(0, struct_fields(tcx, did, substs).index(&FullRange))
1322+
let fields = struct_fields(tcx, did, substs);
1323+
let fields = monomorphize::normalize_associated_type(tcx, &fields);
1324+
op(0, fields.index(&FullRange))
13221325
}
13231326

13241327
ty::ty_tup(ref v) => {
@@ -1340,10 +1343,9 @@ pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>,
13401343
def::DefVariant(enum_id, variant_id, _) => {
13411344
let variant_info = ty::enum_variant_with_id(
13421345
tcx, enum_id, variant_id);
1343-
op(variant_info.disr_val,
1344-
struct_fields(tcx,
1345-
variant_id,
1346-
substs).index(&FullRange))
1346+
let fields = struct_fields(tcx, variant_id, substs);
1347+
let fields = monomorphize::normalize_associated_type(tcx, &fields);
1348+
op(variant_info.disr_val, fields.index(&FullRange))
13471349
}
13481350
_ => {
13491351
tcx.sess.bug("resolve didn't map this expr to a \

0 commit comments

Comments
 (0)