From 0a77a588578b69497caac7a507f875c8f258c9aa Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 16 May 2017 15:04:32 +0200 Subject: [PATCH] Add test cases for cyclic specialization graph construction --- .../coherence-inherited-assoc-ty-cycle-err.rs | 34 +++++++++++++++++++ .../specialization/assoc-ty-graph-cycle.rs | 33 ++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/test/compile-fail/coherence-inherited-assoc-ty-cycle-err.rs create mode 100644 src/test/run-pass/specialization/assoc-ty-graph-cycle.rs diff --git a/src/test/compile-fail/coherence-inherited-assoc-ty-cycle-err.rs b/src/test/compile-fail/coherence-inherited-assoc-ty-cycle-err.rs new file mode 100644 index 00000000000..5d7f3396740 --- /dev/null +++ b/src/test/compile-fail/coherence-inherited-assoc-ty-cycle-err.rs @@ -0,0 +1,34 @@ +// Copyright 2017 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. + +// Formerly this ICEd with the following message: +// Tried to project an inherited associated type during coherence checking, +// which is currently not supported. +// +// No we expect to run into a more user-friendly cycle error instead. + +#![feature(specialization)] + +trait Trait { type Assoc; } +//~^ unsupported cyclic reference between types/traits detected [E0391] + +impl Trait for Vec { + type Assoc = (); +} + +impl Trait for Vec {} + +impl Trait for String { + type Assoc = (); +} + +impl Trait< as Trait>::Assoc> for String {} + +fn main() {} diff --git a/src/test/run-pass/specialization/assoc-ty-graph-cycle.rs b/src/test/run-pass/specialization/assoc-ty-graph-cycle.rs new file mode 100644 index 00000000000..a65dcf33d85 --- /dev/null +++ b/src/test/run-pass/specialization/assoc-ty-graph-cycle.rs @@ -0,0 +1,33 @@ +// Copyright 2017 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. + +// Make sure we don't crash with a cycle error during coherence. + +#![feature(specialization)] + +trait Trait { + type Assoc; +} + +impl Trait for Vec { + default type Assoc = (); +} + +impl Trait for Vec { + type Assoc = u8; +} + +impl Trait for String { + type Assoc = (); +} + +impl Trait< as Trait>::Assoc> for String {} + +fn main() {}