From 194814065c5c1763db3cff3ac8d7fc260d0631f5 Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Tue, 4 Jun 2019 17:22:03 +0200 Subject: [PATCH] Added a test for coherence when a generic type param has a default value from an associated type --- .../auxiliary/re_rebalance_coherence_lib.rs | 9 +++++++ ...herence-default-generic-associated-type.rs | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs diff --git a/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs b/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs index 41b9d64d5f71e..9a191bad8b0bf 100644 --- a/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs +++ b/src/test/run-pass/coherence/auxiliary/re_rebalance_coherence_lib.rs @@ -20,3 +20,12 @@ pub struct BatchInsert<'a, T: 'a, Tab> { impl<'a, T:'a, Tab, DB> QueryFragment for BatchInsert<'a, T, Tab> where DB: SupportsDefaultKeyword + Backend, {} + +pub trait LibToOwned { + type Owned; +} + +pub struct LibCow::Owned> { + pub t: T, + pub o: Owned, +} diff --git a/src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs b/src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs new file mode 100644 index 0000000000000..4168b7a6146a9 --- /dev/null +++ b/src/test/run-pass/coherence/re-rebalance-coherence-default-generic-associated-type.rs @@ -0,0 +1,27 @@ +// run-pass +// aux-build:re_rebalance_coherence_lib.rs + +#![allow(dead_code)] +#![feature(re_rebalance_coherence)] +// check that a generic type with a default value from an associated type can be used without +// specifying the value, and without invoking coherence errors. + +extern crate re_rebalance_coherence_lib as lib; +use lib::*; + +struct MyString {} + +impl LibToOwned for MyString { + type Owned = String; +} + +impl PartialEq for LibCow { + fn eq(&self, _other: &MyString) -> bool { + // Test that the default type is used. + let _s: &String = &self.o; + + false + } +} + +fn main() {}