Skip to content

Instantly share code, notes, and snippets.

@m4rw3r
Created September 6, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4rw3r/9128819a56db444ba402 to your computer and use it in GitHub Desktop.
Save m4rw3r/9128819a56db444ba402 to your computer and use it in GitHub Desktop.
diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs
index b752e04..ad8d197 100644
--- a/src/librustc/middle/infer/mod.rs
+++ b/src/librustc/middle/infer/mod.rs
@@ -484,6 +484,7 @@ pub fn normalize_associated_type<'a, 'tcx, T>(infcx: &InferCtxt<'a,'tcx>, value:
where T : TypeFoldable<'tcx> + HasTypeFlags
{
debug!("normalize_associated_type(t={:?})", value);
+ debug!("normalize_associated_types(infcx.deanonymize={:?})", infcx.deanonymize);
let value = erase_regions(infcx.tcx, value);
diff --git a/src/librustc/middle/traits/project.rs b/src/librustc/middle/traits/project.rs
index 3ab4332..6362b1d 100644
--- a/src/librustc/middle/traits/project.rs
+++ b/src/librustc/middle/traits/project.rs
@@ -240,6 +240,8 @@ impl<'a,'b,'tcx> AssociatedTypeNormalizer<'a,'b,'tcx> {
fn fold<T:TypeFoldable<'tcx> + HasTypeFlags>(&mut self, value: &T) -> T {
let value = self.selcx.infcx().resolve_type_vars_if_possible(value);
+ debug!("AssociatedTypeNormalizer::fold(value={:?}, has_projection_types={:?}, deanonymize={:?}, has_associated_types={:?})", value, value.has_projection_types(), self.selcx.infcx().deanonymize(), value.has_anonymized_types());
+
if value.has_projection_types() ||
self.selcx.infcx().deanonymize() && value.has_anonymized_types() {
value.fold_with(self)
@@ -255,6 +257,7 @@ impl<'a,'b,'tcx> TypeFolder<'tcx> for AssociatedTypeNormalizer<'a,'b,'tcx> {
}
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
+ debug!("AssociatedTypeNormalizer::fold_ty(ty={:?})", ty);
// We don't want to normalize associated types that occur inside of region
// binders, because they may contain bound regions, and we can't cope with that.
//
@@ -269,6 +272,7 @@ impl<'a,'b,'tcx> TypeFolder<'tcx> for AssociatedTypeNormalizer<'a,'b,'tcx> {
let ty = ty_fold::super_fold_ty(self, ty);
match ty.sty {
ty::TyProjection(ref data) if !data.has_escaping_regions() => { // (*)
+ debug!("AssociatedTypeNormalizer::fold_ty(TyProjection={:?})", data);
// (*) This is kind of hacky -- we need to be able to
// handle normalization within binders because
@@ -292,7 +296,10 @@ impl<'a,'b,'tcx> TypeFolder<'tcx> for AssociatedTypeNormalizer<'a,'b,'tcx> {
}
ty::TyAnon(def_id, substs, ref data) => {
- if self.selcx.infcx().deanonymize() && !data.principal.has_escaping_regions() {
+ debug!("AssociatedTypeNormalizer::fold_ty(TyAnon(def_id={:?}, substs={:?}, data={:?})", def_id, substs, data);
+ debug!("AssociatedTypeNormalizer::fold_ty(TyAnon, infcx.deanonymize={:?}, has_escaping_regions={:?})", self.selcx.infcx().deanonymize(), data.principal.has_escaping_regions());
+ // if self.selcx.infcx().deanonymize() && !data.principal.has_escaping_regions() {
+ if self.selcx.infcx().deanonymize() {
let generic_ty = self.tcx().lookup_item_type(def_id).ty;
let concrete_ty = generic_ty.subst(self.tcx(), substs);
self.fold_ty(concrete_ty)
diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs
index 61e81d7..2a8b0fd 100644
--- a/src/librustc_trans/trans/base.rs
+++ b/src/librustc_trans/trans/base.rs
@@ -2343,6 +2343,9 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
let val = match item {
ast_map::NodeItem(i) => {
let ty = ccx.tcx().node_id_to_type(i.id);
+ debug!("NodeItem, ty pre: {}, anonymous: {}", ty, ty.has_anonymized_types());
+ let ty = monomorphize::normalize_associated_type(ccx.tcx(), &ty);
+ debug!("NodeItem, ty post: {}, anonymous: {}", ty, ty.has_anonymized_types());
let sym = || exported_name(ccx, id, ty, &i.attrs);
let v = match i.node {
@@ -2452,6 +2455,9 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
};
assert!(!args.is_empty());
let ty = ccx.tcx().node_id_to_type(id);
+ debug!("NodeVariant, ty pre: {}, anonymous: {}", ty, ty.has_anonymized_types());
+ let ty = monomorphize::normalize_associated_type(ccx.tcx(), &ty);
+ debug!("NodeVariant, ty post: {}, anonymous: {}", ty, ty.has_anonymized_types());
let parent = ccx.tcx().map.get_parent(id);
let enm = ccx.tcx().map.expect_item(parent);
let sym = exported_name(ccx,
@@ -2481,6 +2487,9 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
let parent = ccx.tcx().map.get_parent(id);
let struct_item = ccx.tcx().map.expect_item(parent);
let ty = ccx.tcx().node_id_to_type(ctor_id);
+ debug!("NodeStructCtor, ty pre: {}, anonymous: {}", ty, ty.has_anonymized_types());
+ let ty = monomorphize::normalize_associated_type(ccx.tcx(), &ty);
+ debug!("NodeStructCtor, ty post: {}, anonymous: {}", ty, ty.has_anonymized_types());
let sym = exported_name(ccx,
id,
ty,
@@ -2513,6 +2522,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
fn register_method(ccx: &CrateContext, id: ast::NodeId,
attrs: &[ast::Attribute], span: Span) -> ValueRef {
let mty = ccx.tcx().node_id_to_type(id);
+ let mty = monomorphize::normalize_associated_type(ccx.tcx(), &mty);
let sym = exported_name(ccx, id, mty, &attrs);
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 8bcb949..166d1c9 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1705,6 +1705,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
let path = external_path(cx, &fqn.last().unwrap().to_string(),
Some(did), bindings, principal.substs());
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, TypeTrait));
+
Anon(vec![TraitBound(PolyTrait {
trait_: ResolvedPath {
path: path,
@@ -1712,7 +1713,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
did: did,
is_generic: false,
},
- lifetimes: late_bounds
+ lifetimes: vec![],
}, ast::TraitBoundModifier::None)])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment