From 93974cb09e2670eb4debfb3a9081844ba21799f4 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 25 Jul 2018 10:47:59 +0200 Subject: [PATCH] Fix associated existentials for generic traits --- src/librustc/traits/project.rs | 3 +- ...sociated-existential-type-generic-trait.rs | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/impl-trait/associated-existential-type-generic-trait.rs diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index a8ece34825e..1ce60d8f055 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -1517,7 +1517,8 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>( } let substs = translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.node); let ty = if let ty::AssociatedKind::Existential = assoc_ty.item.kind { - tcx.mk_anon(assoc_ty.item.def_id, substs) + let item_substs = Substs::identity_for_item(tcx, assoc_ty.item.def_id); + tcx.mk_anon(assoc_ty.item.def_id, item_substs) } else { tcx.type_of(assoc_ty.item.def_id) }; diff --git a/src/test/ui/impl-trait/associated-existential-type-generic-trait.rs b/src/test/ui/impl-trait/associated-existential-type-generic-trait.rs new file mode 100644 index 00000000000..c9bf7b87ef4 --- /dev/null +++ b/src/test/ui/impl-trait/associated-existential-type-generic-trait.rs @@ -0,0 +1,40 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(existential_type)] +// compile-pass + +trait Bar {} +struct Dummy(U); +impl Bar for Dummy {} + +trait Foo { + type Assoc: Bar; + fn foo(t: T) -> Self::Assoc; +} + +impl Foo for i32 { + existential type Assoc: Bar; + fn foo(w: W) -> Self::Assoc { + Dummy(w) + } +} + +struct NonGeneric; +impl Bar for NonGeneric {} + +impl Foo for u32 { + existential type Assoc: Bar; + fn foo(_: W) -> Self::Assoc { + NonGeneric + } +} + +fn main() {} -- 2.44.0