diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-07-25 10:47:59 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-07-25 10:47:59 +0200 |
| commit | 93974cb09e2670eb4debfb3a9081844ba21799f4 (patch) | |
| tree | 6d1a7e81df34d989af90278b22d924c971647089 | |
| parent | 9130efdad336820b3a9fad234915e4dc977a5d93 (diff) | |
| download | rust-93974cb09e2670eb4debfb3a9081844ba21799f4.tar.gz rust-93974cb09e2670eb4debfb3a9081844ba21799f4.zip | |
Fix associated existentials for generic traits
| -rw-r--r-- | src/librustc/traits/project.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/impl-trait/associated-existential-type-generic-trait.rs | 40 |
2 files changed, 42 insertions, 1 deletions
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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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>(U); +impl<V> Bar for Dummy<V> {} + +trait Foo<T> { + type Assoc: Bar; + fn foo(t: T) -> Self::Assoc; +} + +impl<W> Foo<W> for i32 { + existential type Assoc: Bar; + fn foo(w: W) -> Self::Assoc { + Dummy(w) + } +} + +struct NonGeneric; +impl Bar for NonGeneric {} + +impl<W> Foo<W> for u32 { + existential type Assoc: Bar; + fn foo(_: W) -> Self::Assoc { + NonGeneric + } +} + +fn main() {} |
