From b4f5ddba67d2fa81f90bfaadbb8ec83321dd3dcc Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 2 Jan 2016 04:57:55 -0500 Subject: Make coherence more tolerant of error types. Fixes #29857. Fixes #30589. --- .../coherence-projection-conflict-orphan.rs | 28 +++++++++++++++++++++ .../compile-fail/coherence-projection-conflict.rs | 27 ++++++++++++++++++++ .../compile-fail/coherence-projection-ok-orphan.rs | 29 ++++++++++++++++++++++ src/test/compile-fail/coherence-projection-ok.rs | 28 +++++++++++++++++++++ src/test/compile-fail/issue-29857.rs | 27 ++++++++++++++++++++ src/test/compile-fail/issue-30589.rs | 19 ++++++++++++++ 6 files changed, 158 insertions(+) create mode 100644 src/test/compile-fail/coherence-projection-conflict-orphan.rs create mode 100644 src/test/compile-fail/coherence-projection-conflict.rs create mode 100644 src/test/compile-fail/coherence-projection-ok-orphan.rs create mode 100644 src/test/compile-fail/coherence-projection-ok.rs create mode 100644 src/test/compile-fail/issue-29857.rs create mode 100644 src/test/compile-fail/issue-30589.rs (limited to 'src/test') diff --git a/src/test/compile-fail/coherence-projection-conflict-orphan.rs b/src/test/compile-fail/coherence-projection-conflict-orphan.rs new file mode 100644 index 00000000000..3de79454398 --- /dev/null +++ b/src/test/compile-fail/coherence-projection-conflict-orphan.rs @@ -0,0 +1,28 @@ +// Copyright 2016 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(rustc_attrs)] + +// Here we expect a coherence conflict because, even though `i32` does +// not implement `Iterator`, we cannot rely on that negative reasoning +// due to the orphan rules. Therefore, `A::Item` may yet turn out to +// be `i32`. + +pub trait Foo

{} + +pub trait Bar { + type Output: 'static; +} + +impl Foo for i32 { } //~ ERROR E0119 + +impl Foo for A { } + +fn main() {} diff --git a/src/test/compile-fail/coherence-projection-conflict.rs b/src/test/compile-fail/coherence-projection-conflict.rs new file mode 100644 index 00000000000..2236e71b53f --- /dev/null +++ b/src/test/compile-fail/coherence-projection-conflict.rs @@ -0,0 +1,27 @@ +// Copyright 2016 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. + +use std::marker::PhantomData; + +pub trait Foo

{} + +pub trait Bar { + type Output: 'static; +} + +impl Foo for i32 { } //~ ERROR E0119 + +impl Foo for A { } + +impl Bar for i32 { + type Output = i32; +} + +fn main() {} diff --git a/src/test/compile-fail/coherence-projection-ok-orphan.rs b/src/test/compile-fail/coherence-projection-ok-orphan.rs new file mode 100644 index 00000000000..a52af0873a8 --- /dev/null +++ b/src/test/compile-fail/coherence-projection-ok-orphan.rs @@ -0,0 +1,29 @@ +// Copyright 2016 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(rustc_attrs)] +#![allow(dead_code)] + +// Here we do not get a coherence conflict because `Baz: Iterator` +// does not hold and (due to the orphan rules), we can rely on that. + +pub trait Foo

{} + +pub trait Bar { + type Output: 'static; +} + +struct Baz; +impl Foo for Baz { } + +impl Foo for A { } + +#[rustc_error] +fn main() {} //~ ERROR compilation successful diff --git a/src/test/compile-fail/coherence-projection-ok.rs b/src/test/compile-fail/coherence-projection-ok.rs new file mode 100644 index 00000000000..af88f3744ea --- /dev/null +++ b/src/test/compile-fail/coherence-projection-ok.rs @@ -0,0 +1,28 @@ +// Copyright 2016 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(rustc_attrs)] + +pub trait Foo

{} + +pub trait Bar { + type Output: 'static; +} + +impl Foo for i32 { } + +impl Foo for A { } + +impl Bar for i32 { + type Output = u32; +} + +#[rustc_error] +fn main() {} //~ ERROR compilation successful diff --git a/src/test/compile-fail/issue-29857.rs b/src/test/compile-fail/issue-29857.rs new file mode 100644 index 00000000000..b46246cd216 --- /dev/null +++ b/src/test/compile-fail/issue-29857.rs @@ -0,0 +1,27 @@ +// Copyright 2016 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. + +use std::marker::PhantomData; + +pub trait Foo

{} + +impl > Foo

for Option {} //~ ERROR E0119 + +pub struct Qux (PhantomData<*mut T>); + +impl Foo<*mut T> for Option> {} + +pub trait Bar { + type Output: 'static; +} + +impl> Foo<*mut T> for W {} + +fn main() {} diff --git a/src/test/compile-fail/issue-30589.rs b/src/test/compile-fail/issue-30589.rs new file mode 100644 index 00000000000..32765d5acb4 --- /dev/null +++ b/src/test/compile-fail/issue-30589.rs @@ -0,0 +1,19 @@ +// Copyright 2016 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. + +use std::fmt; + +impl fmt::Display for DecoderError { //~ ERROR E0412 + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Missing data: {}", self.0) + } +} +fn main() { +} -- cgit 1.4.1-3-g733a5