summaryrefslogtreecommitdiffstats
path: root/src/test/ui/on-unimplemented
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/on-unimplemented')
-rw-r--r--src/test/ui/on-unimplemented/auxiliary/no_debug.rs3
-rw-r--r--src/test/ui/on-unimplemented/bad-annotation.rs64
-rw-r--r--src/test/ui/on-unimplemented/bad-annotation.stderr83
-rw-r--r--src/test/ui/on-unimplemented/enclosing-scope.rs27
-rw-r--r--src/test/ui/on-unimplemented/enclosing-scope.stderr86
-rw-r--r--src/test/ui/on-unimplemented/expected-comma-found-token.rs13
-rw-r--r--src/test/ui/on-unimplemented/expected-comma-found-token.stderr10
-rw-r--r--src/test/ui/on-unimplemented/feature-gate-on-unimplemented.rs8
-rw-r--r--src/test/ui/on-unimplemented/feature-gate-on-unimplemented.stderr11
-rw-r--r--src/test/ui/on-unimplemented/impl-substs.rs15
-rw-r--r--src/test/ui/on-unimplemented/impl-substs.stderr14
-rw-r--r--src/test/ui/on-unimplemented/multiple-impls.rs42
-rw-r--r--src/test/ui/on-unimplemented/multiple-impls.stderr75
-rw-r--r--src/test/ui/on-unimplemented/no-debug.rs16
-rw-r--r--src/test/ui/on-unimplemented/no-debug.stderr46
-rw-r--r--src/test/ui/on-unimplemented/on-impl.rs25
-rw-r--r--src/test/ui/on-unimplemented/on-impl.stderr23
-rw-r--r--src/test/ui/on-unimplemented/on-trait.rs32
-rw-r--r--src/test/ui/on-unimplemented/on-trait.stderr29
-rw-r--r--src/test/ui/on-unimplemented/slice-index.rs10
-rw-r--r--src/test/ui/on-unimplemented/slice-index.stderr25
21 files changed, 657 insertions, 0 deletions
diff --git a/src/test/ui/on-unimplemented/auxiliary/no_debug.rs b/src/test/ui/on-unimplemented/auxiliary/no_debug.rs
new file mode 100644
index 000000000..fd3dc0abd
--- /dev/null
+++ b/src/test/ui/on-unimplemented/auxiliary/no_debug.rs
@@ -0,0 +1,3 @@
+#![crate_type = "lib"]
+
+pub struct Bar;
diff --git a/src/test/ui/on-unimplemented/bad-annotation.rs b/src/test/ui/on-unimplemented/bad-annotation.rs
new file mode 100644
index 000000000..f05436b8c
--- /dev/null
+++ b/src/test/ui/on-unimplemented/bad-annotation.rs
@@ -0,0 +1,64 @@
+// ignore-tidy-linelength
+
+#![feature(rustc_attrs)]
+
+#![allow(unused)]
+
+#[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}`"]
+trait Foo<Bar, Baz, Quux>
+{}
+
+#[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an iterator over elements of type `{A}`"]
+trait MyFromIterator<A> {
+ /// Builds a container with elements from an external iterator.
+ fn my_from_iter<T: Iterator<Item=A>>(iterator: T) -> Self;
+}
+
+#[rustc_on_unimplemented]
+//~^ ERROR malformed `rustc_on_unimplemented` attribute
+trait BadAnnotation1
+{}
+
+#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
+//~^ ERROR there is no parameter `C` on trait `BadAnnotation2`
+trait BadAnnotation2<A,B>
+{}
+
+#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
+//~^ only named substitution parameters are allowed
+trait BadAnnotation3<A,B>
+{}
+
+#[rustc_on_unimplemented(lorem="")]
+//~^ this attribute must have a valid
+trait BadAnnotation4 {}
+
+#[rustc_on_unimplemented(lorem(ipsum(dolor)))]
+//~^ this attribute must have a valid
+trait BadAnnotation5 {}
+
+#[rustc_on_unimplemented(message="x", message="y")]
+//~^ this attribute must have a valid
+trait BadAnnotation6 {}
+
+#[rustc_on_unimplemented(message="x", on(desugared, message="y"))]
+//~^ this attribute must have a valid
+trait BadAnnotation7 {}
+
+#[rustc_on_unimplemented(on(), message="y")]
+//~^ empty `on`-clause
+trait BadAnnotation8 {}
+
+#[rustc_on_unimplemented(on="x", message="y")]
+//~^ this attribute must have a valid
+trait BadAnnotation9 {}
+
+#[rustc_on_unimplemented(on(x="y"), message="y")]
+trait BadAnnotation10 {}
+
+#[rustc_on_unimplemented(on(desugared, on(desugared, message="x")), message="y")]
+//~^ this attribute must have a valid
+trait BadAnnotation11 {}
+
+pub fn main() {
+}
diff --git a/src/test/ui/on-unimplemented/bad-annotation.stderr b/src/test/ui/on-unimplemented/bad-annotation.stderr
new file mode 100644
index 000000000..a8d3c8680
--- /dev/null
+++ b/src/test/ui/on-unimplemented/bad-annotation.stderr
@@ -0,0 +1,83 @@
+error: malformed `rustc_on_unimplemented` attribute input
+ --> $DIR/bad-annotation.rs:17:1
+ |
+LL | #[rustc_on_unimplemented]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: the following are the possible correct uses
+ |
+LL | #[rustc_on_unimplemented = "message"]
+ |
+LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
+ |
+
+error[E0230]: there is no parameter `C` on trait `BadAnnotation2`
+ --> $DIR/bad-annotation.rs:22:1
+ |
+LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0231]: only named substitution parameters are allowed
+ --> $DIR/bad-annotation.rs:27:1
+ |
+LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0232]: this attribute must have a valid value
+ --> $DIR/bad-annotation.rs:32:26
+ |
+LL | #[rustc_on_unimplemented(lorem="")]
+ | ^^^^^^^^ expected value here
+ |
+ = note: eg `#[rustc_on_unimplemented(message="foo")]`
+
+error[E0232]: this attribute must have a valid value
+ --> $DIR/bad-annotation.rs:36:26
+ |
+LL | #[rustc_on_unimplemented(lorem(ipsum(dolor)))]
+ | ^^^^^^^^^^^^^^^^^^^ expected value here
+ |
+ = note: eg `#[rustc_on_unimplemented(message="foo")]`
+
+error[E0232]: this attribute must have a valid value
+ --> $DIR/bad-annotation.rs:40:39
+ |
+LL | #[rustc_on_unimplemented(message="x", message="y")]
+ | ^^^^^^^^^^^ expected value here
+ |
+ = note: eg `#[rustc_on_unimplemented(message="foo")]`
+
+error[E0232]: this attribute must have a valid value
+ --> $DIR/bad-annotation.rs:44:39
+ |
+LL | #[rustc_on_unimplemented(message="x", on(desugared, message="y"))]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
+ |
+ = note: eg `#[rustc_on_unimplemented(message="foo")]`
+
+error[E0232]: empty `on`-clause in `#[rustc_on_unimplemented]`
+ --> $DIR/bad-annotation.rs:48:26
+ |
+LL | #[rustc_on_unimplemented(on(), message="y")]
+ | ^^^^ empty on-clause here
+
+error[E0232]: this attribute must have a valid value
+ --> $DIR/bad-annotation.rs:52:26
+ |
+LL | #[rustc_on_unimplemented(on="x", message="y")]
+ | ^^^^^^ expected value here
+ |
+ = note: eg `#[rustc_on_unimplemented(message="foo")]`
+
+error[E0232]: this attribute must have a valid value
+ --> $DIR/bad-annotation.rs:59:40
+ |
+LL | #[rustc_on_unimplemented(on(desugared, on(desugared, message="x")), message="y")]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected value here
+ |
+ = note: eg `#[rustc_on_unimplemented(message="foo")]`
+
+error: aborting due to 10 previous errors
+
+Some errors have detailed explanations: E0230, E0231, E0232.
+For more information about an error, try `rustc --explain E0230`.
diff --git a/src/test/ui/on-unimplemented/enclosing-scope.rs b/src/test/ui/on-unimplemented/enclosing-scope.rs
new file mode 100644
index 000000000..881bff63f
--- /dev/null
+++ b/src/test/ui/on-unimplemented/enclosing-scope.rs
@@ -0,0 +1,27 @@
+// Test scope annotations from `enclosing_scope` parameter
+
+#![feature(rustc_attrs)]
+
+#[rustc_on_unimplemented(enclosing_scope="in this scope")]
+trait Trait{}
+
+struct Foo;
+
+fn f<T: Trait>(x: T) {}
+
+fn main() {
+ let x = || {
+ f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
+ let y = || {
+ f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
+ };
+ };
+
+ {
+ {
+ f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
+ }
+ }
+
+ f(Foo{}); //~ ERROR the trait bound `Foo: Trait` is not satisfied
+}
diff --git a/src/test/ui/on-unimplemented/enclosing-scope.stderr b/src/test/ui/on-unimplemented/enclosing-scope.stderr
new file mode 100644
index 000000000..67759d02a
--- /dev/null
+++ b/src/test/ui/on-unimplemented/enclosing-scope.stderr
@@ -0,0 +1,86 @@
+error[E0277]: the trait bound `Foo: Trait` is not satisfied
+ --> $DIR/enclosing-scope.rs:14:11
+ |
+LL | let x = || {
+ | _____________-
+LL | | f(Foo{});
+ | | - ^^^^^ the trait `Trait` is not implemented for `Foo`
+ | | |
+ | | required by a bound introduced by this call
+LL | | let y = || {
+LL | | f(Foo{});
+LL | | };
+LL | | };
+ | |_____- in this scope
+ |
+note: required by a bound in `f`
+ --> $DIR/enclosing-scope.rs:10:9
+ |
+LL | fn f<T: Trait>(x: T) {}
+ | ^^^^^ required by this bound in `f`
+
+error[E0277]: the trait bound `Foo: Trait` is not satisfied
+ --> $DIR/enclosing-scope.rs:16:15
+ |
+LL | let y = || {
+ | _________________-
+LL | | f(Foo{});
+ | | - ^^^^^ the trait `Trait` is not implemented for `Foo`
+ | | |
+ | | required by a bound introduced by this call
+LL | | };
+ | |_________- in this scope
+ |
+note: required by a bound in `f`
+ --> $DIR/enclosing-scope.rs:10:9
+ |
+LL | fn f<T: Trait>(x: T) {}
+ | ^^^^^ required by this bound in `f`
+
+error[E0277]: the trait bound `Foo: Trait` is not satisfied
+ --> $DIR/enclosing-scope.rs:22:15
+ |
+LL | / fn main() {
+LL | | let x = || {
+LL | | f(Foo{});
+LL | | let y = || {
+... |
+LL | | f(Foo{});
+ | | - ^^^^^ the trait `Trait` is not implemented for `Foo`
+ | | |
+ | | required by a bound introduced by this call
+... |
+LL | | f(Foo{});
+LL | | }
+ | |_- in this scope
+ |
+note: required by a bound in `f`
+ --> $DIR/enclosing-scope.rs:10:9
+ |
+LL | fn f<T: Trait>(x: T) {}
+ | ^^^^^ required by this bound in `f`
+
+error[E0277]: the trait bound `Foo: Trait` is not satisfied
+ --> $DIR/enclosing-scope.rs:26:7
+ |
+LL | / fn main() {
+LL | | let x = || {
+LL | | f(Foo{});
+LL | | let y = || {
+... |
+LL | | f(Foo{});
+ | | - ^^^^^ the trait `Trait` is not implemented for `Foo`
+ | | |
+ | | required by a bound introduced by this call
+LL | | }
+ | |_- in this scope
+ |
+note: required by a bound in `f`
+ --> $DIR/enclosing-scope.rs:10:9
+ |
+LL | fn f<T: Trait>(x: T) {}
+ | ^^^^^ required by this bound in `f`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/on-unimplemented/expected-comma-found-token.rs b/src/test/ui/on-unimplemented/expected-comma-found-token.rs
new file mode 100644
index 000000000..8fb34f211
--- /dev/null
+++ b/src/test/ui/on-unimplemented/expected-comma-found-token.rs
@@ -0,0 +1,13 @@
+// Tests that two closures cannot simultaneously have mutable
+// access to the variable, whether that mutable access be used
+// for direct assignment or for taking mutable ref. Issue #6801.
+
+#![feature(rustc_attrs)]
+
+#[rustc_on_unimplemented(
+ message="the message"
+ label="the label" //~ ERROR expected `,`, found `label`
+)]
+trait T {}
+
+fn main() { }
diff --git a/src/test/ui/on-unimplemented/expected-comma-found-token.stderr b/src/test/ui/on-unimplemented/expected-comma-found-token.stderr
new file mode 100644
index 000000000..048b72ee3
--- /dev/null
+++ b/src/test/ui/on-unimplemented/expected-comma-found-token.stderr
@@ -0,0 +1,10 @@
+error: expected `,`, found `label`
+ --> $DIR/expected-comma-found-token.rs:9:5
+ |
+LL | message="the message"
+ | - expected `,`
+LL | label="the label"
+ | ^^^^^ unexpected token
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/on-unimplemented/feature-gate-on-unimplemented.rs b/src/test/ui/on-unimplemented/feature-gate-on-unimplemented.rs
new file mode 100644
index 000000000..3cc50e349
--- /dev/null
+++ b/src/test/ui/on-unimplemented/feature-gate-on-unimplemented.rs
@@ -0,0 +1,8 @@
+// Test that `#[rustc_on_unimplemented]` is gated by `rustc_attrs` feature gate.
+
+#[rustc_on_unimplemented = "test error `{Self}` with `{Bar}`"]
+//~^ ERROR this is an internal attribute that will never be stable
+trait Foo<Bar>
+{}
+
+fn main() {}
diff --git a/src/test/ui/on-unimplemented/feature-gate-on-unimplemented.stderr b/src/test/ui/on-unimplemented/feature-gate-on-unimplemented.stderr
new file mode 100644
index 000000000..a4b33963f
--- /dev/null
+++ b/src/test/ui/on-unimplemented/feature-gate-on-unimplemented.stderr
@@ -0,0 +1,11 @@
+error[E0658]: this is an internal attribute that will never be stable
+ --> $DIR/feature-gate-on-unimplemented.rs:3:1
+ |
+LL | #[rustc_on_unimplemented = "test error `{Self}` with `{Bar}`"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/on-unimplemented/impl-substs.rs b/src/test/ui/on-unimplemented/impl-substs.rs
new file mode 100644
index 000000000..fe9c50ec3
--- /dev/null
+++ b/src/test/ui/on-unimplemented/impl-substs.rs
@@ -0,0 +1,15 @@
+#![feature(rustc_attrs)]
+
+trait Foo<A> {
+ fn foo(self);
+}
+
+#[rustc_on_unimplemented = "an impl did not match: {A} {B} {C}"]
+impl<A, B, C> Foo<A> for (A, B, C) {
+ fn foo(self) {}
+}
+
+fn main() {
+ Foo::<usize>::foo((1i32, 1i32, 1i32));
+ //~^ ERROR the trait bound `(i32, i32, i32): Foo<usize>` is not satisfied
+}
diff --git a/src/test/ui/on-unimplemented/impl-substs.stderr b/src/test/ui/on-unimplemented/impl-substs.stderr
new file mode 100644
index 000000000..a0fad0acd
--- /dev/null
+++ b/src/test/ui/on-unimplemented/impl-substs.stderr
@@ -0,0 +1,14 @@
+error[E0277]: the trait bound `(i32, i32, i32): Foo<usize>` is not satisfied
+ --> $DIR/impl-substs.rs:13:23
+ |
+LL | Foo::<usize>::foo((1i32, 1i32, 1i32));
+ | ----------------- ^^^^^^^^^^^^^^^^^^ an impl did not match: usize _ _
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Foo<usize>` is not implemented for `(i32, i32, i32)`
+ = help: the trait `Foo<A>` is implemented for `(A, B, C)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/on-unimplemented/multiple-impls.rs b/src/test/ui/on-unimplemented/multiple-impls.rs
new file mode 100644
index 000000000..b74957ebc
--- /dev/null
+++ b/src/test/ui/on-unimplemented/multiple-impls.rs
@@ -0,0 +1,42 @@
+// Test if the on_unimplemented message override works
+
+#![feature(rustc_attrs)]
+
+
+struct Foo<T>(T);
+struct Bar<T>(T);
+
+#[rustc_on_unimplemented = "trait message"]
+trait Index<Idx: ?Sized> {
+ type Output: ?Sized;
+ fn index(&self, index: Idx) -> &Self::Output;
+}
+
+#[rustc_on_unimplemented = "on impl for Foo"]
+impl Index<Foo<usize>> for [i32] {
+ type Output = i32;
+ fn index(&self, _index: Foo<usize>) -> &i32 {
+ loop {}
+ }
+}
+
+#[rustc_on_unimplemented = "on impl for Bar"]
+impl Index<Bar<usize>> for [i32] {
+ type Output = i32;
+ fn index(&self, _index: Bar<usize>) -> &i32 {
+ loop {}
+ }
+}
+
+
+fn main() {
+ Index::index(&[] as &[i32], 2u32);
+ //~^ ERROR E0277
+ //~| ERROR E0277
+ Index::index(&[] as &[i32], Foo(2u32));
+ //~^ ERROR E0277
+ //~| ERROR E0277
+ Index::index(&[] as &[i32], Bar(2u32));
+ //~^ ERROR E0277
+ //~| ERROR E0277
+}
diff --git a/src/test/ui/on-unimplemented/multiple-impls.stderr b/src/test/ui/on-unimplemented/multiple-impls.stderr
new file mode 100644
index 000000000..06e1a222a
--- /dev/null
+++ b/src/test/ui/on-unimplemented/multiple-impls.stderr
@@ -0,0 +1,75 @@
+error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
+ --> $DIR/multiple-impls.rs:33:18
+ |
+LL | Index::index(&[] as &[i32], 2u32);
+ | ------------ ^^^^^^^^^^^^^ trait message
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Index<u32>` is not implemented for `[i32]`
+ = help: the following other types implement trait `Index<Idx>`:
+ <[i32] as Index<Bar<usize>>>
+ <[i32] as Index<Foo<usize>>>
+
+error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
+ --> $DIR/multiple-impls.rs:36:18
+ |
+LL | Index::index(&[] as &[i32], Foo(2u32));
+ | ------------ ^^^^^^^^^^^^^ on impl for Foo
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
+ = help: the following other types implement trait `Index<Idx>`:
+ <[i32] as Index<Bar<usize>>>
+ <[i32] as Index<Foo<usize>>>
+
+error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
+ --> $DIR/multiple-impls.rs:39:18
+ |
+LL | Index::index(&[] as &[i32], Bar(2u32));
+ | ------------ ^^^^^^^^^^^^^ on impl for Bar
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
+ = help: the following other types implement trait `Index<Idx>`:
+ <[i32] as Index<Bar<usize>>>
+ <[i32] as Index<Foo<usize>>>
+
+error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
+ --> $DIR/multiple-impls.rs:33:5
+ |
+LL | Index::index(&[] as &[i32], 2u32);
+ | ^^^^^^^^^^^^ trait message
+ |
+ = help: the trait `Index<u32>` is not implemented for `[i32]`
+ = help: the following other types implement trait `Index<Idx>`:
+ <[i32] as Index<Bar<usize>>>
+ <[i32] as Index<Foo<usize>>>
+
+error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
+ --> $DIR/multiple-impls.rs:36:5
+ |
+LL | Index::index(&[] as &[i32], Foo(2u32));
+ | ^^^^^^^^^^^^ on impl for Foo
+ |
+ = help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
+ = help: the following other types implement trait `Index<Idx>`:
+ <[i32] as Index<Bar<usize>>>
+ <[i32] as Index<Foo<usize>>>
+
+error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
+ --> $DIR/multiple-impls.rs:39:5
+ |
+LL | Index::index(&[] as &[i32], Bar(2u32));
+ | ^^^^^^^^^^^^ on impl for Bar
+ |
+ = help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
+ = help: the following other types implement trait `Index<Idx>`:
+ <[i32] as Index<Bar<usize>>>
+ <[i32] as Index<Foo<usize>>>
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/on-unimplemented/no-debug.rs b/src/test/ui/on-unimplemented/no-debug.rs
new file mode 100644
index 000000000..bdc80c5b3
--- /dev/null
+++ b/src/test/ui/on-unimplemented/no-debug.rs
@@ -0,0 +1,16 @@
+// aux-build:no_debug.rs
+
+extern crate no_debug;
+
+use no_debug::Bar;
+
+struct Foo;
+
+fn main() {
+ println!("{:?} {:?}", Foo, Bar);
+ println!("{} {}", Foo, Bar);
+}
+//~^^^ ERROR `Foo` doesn't implement `Debug`
+//~| ERROR `Bar` doesn't implement `Debug`
+//~^^^^ ERROR `Foo` doesn't implement `std::fmt::Display`
+//~| ERROR `Bar` doesn't implement `std::fmt::Display`
diff --git a/src/test/ui/on-unimplemented/no-debug.stderr b/src/test/ui/on-unimplemented/no-debug.stderr
new file mode 100644
index 000000000..1035da54d
--- /dev/null
+++ b/src/test/ui/on-unimplemented/no-debug.stderr
@@ -0,0 +1,46 @@
+error[E0277]: `Foo` doesn't implement `Debug`
+ --> $DIR/no-debug.rs:10:27
+ |
+LL | println!("{:?} {:?}", Foo, Bar);
+ | ^^^ `Foo` cannot be formatted using `{:?}`
+ |
+ = help: the trait `Debug` is not implemented for `Foo`
+ = note: add `#[derive(Debug)]` to `Foo` or manually `impl Debug for Foo`
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: consider annotating `Foo` with `#[derive(Debug)]`
+ |
+LL | #[derive(Debug)]
+ |
+
+error[E0277]: `Bar` doesn't implement `Debug`
+ --> $DIR/no-debug.rs:10:32
+ |
+LL | println!("{:?} {:?}", Foo, Bar);
+ | ^^^ `Bar` cannot be formatted using `{:?}` because it doesn't implement `Debug`
+ |
+ = help: the trait `Debug` is not implemented for `Bar`
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: `Foo` doesn't implement `std::fmt::Display`
+ --> $DIR/no-debug.rs:11:23
+ |
+LL | println!("{} {}", Foo, Bar);
+ | ^^^ `Foo` cannot be formatted with the default formatter
+ |
+ = help: the trait `std::fmt::Display` is not implemented for `Foo`
+ = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0277]: `Bar` doesn't implement `std::fmt::Display`
+ --> $DIR/no-debug.rs:11:28
+ |
+LL | println!("{} {}", Foo, Bar);
+ | ^^^ `Bar` cannot be formatted with the default formatter
+ |
+ = help: the trait `std::fmt::Display` is not implemented for `Bar`
+ = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+ = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/on-unimplemented/on-impl.rs b/src/test/ui/on-unimplemented/on-impl.rs
new file mode 100644
index 000000000..ab3e67d01
--- /dev/null
+++ b/src/test/ui/on-unimplemented/on-impl.rs
@@ -0,0 +1,25 @@
+// Test if the on_unimplemented message override works
+
+#![feature(rustc_attrs)]
+
+
+#[rustc_on_unimplemented = "invalid"]
+trait Index<Idx: ?Sized> {
+ type Output: ?Sized;
+ fn index(&self, index: Idx) -> &Self::Output;
+}
+
+#[rustc_on_unimplemented = "a usize is required to index into a slice"]
+impl Index<usize> for [i32] {
+ type Output = i32;
+ fn index(&self, index: usize) -> &i32 {
+ &self[index]
+ }
+}
+
+
+fn main() {
+ Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
+ //~^ ERROR E0277
+ //~| ERROR E0277
+}
diff --git a/src/test/ui/on-unimplemented/on-impl.stderr b/src/test/ui/on-unimplemented/on-impl.stderr
new file mode 100644
index 000000000..769a3d77a
--- /dev/null
+++ b/src/test/ui/on-unimplemented/on-impl.stderr
@@ -0,0 +1,23 @@
+error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
+ --> $DIR/on-impl.rs:22:25
+ |
+LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
+ | ------------------- ^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Index<u32>` is not implemented for `[i32]`
+ = help: the trait `Index<usize>` is implemented for `[i32]`
+
+error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
+ --> $DIR/on-impl.rs:22:5
+ |
+LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
+ | ^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice
+ |
+ = help: the trait `Index<u32>` is not implemented for `[i32]`
+ = help: the trait `Index<usize>` is implemented for `[i32]`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/on-unimplemented/on-trait.rs b/src/test/ui/on-unimplemented/on-trait.rs
new file mode 100644
index 000000000..556813cd4
--- /dev/null
+++ b/src/test/ui/on-unimplemented/on-trait.rs
@@ -0,0 +1,32 @@
+// ignore-tidy-linelength
+
+#![feature(rustc_attrs)]
+
+pub mod Bar {
+ #[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}` in `{Foo}`"]
+ pub trait Foo<Bar, Baz, Quux> {}
+}
+
+use Bar::Foo;
+
+fn foobar<U: Clone, T: Foo<u8, U, u32>>() -> T {
+ panic!()
+}
+
+#[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an iterator over elements of type `{A}`"]
+trait MyFromIterator<A> {
+ /// Builds a container with elements from an external iterator.
+ fn my_from_iter<T: Iterator<Item=A>>(iterator: T) -> Self;
+}
+
+fn collect<A, I: Iterator<Item=A>, B: MyFromIterator<A>>(it: I) -> B {
+ MyFromIterator::my_from_iter(it)
+}
+
+pub fn main() {
+ let x = vec![1u8, 2, 3, 4];
+ let y: Option<Vec<u8>> = collect(x.iter()); // this should give approximately the same error for x.iter().collect()
+ //~^ ERROR
+
+ let x: String = foobar(); //~ ERROR
+}
diff --git a/src/test/ui/on-unimplemented/on-trait.stderr b/src/test/ui/on-unimplemented/on-trait.stderr
new file mode 100644
index 000000000..4b040f1ac
--- /dev/null
+++ b/src/test/ui/on-unimplemented/on-trait.stderr
@@ -0,0 +1,29 @@
+error[E0277]: the trait bound `Option<Vec<u8>>: MyFromIterator<&u8>` is not satisfied
+ --> $DIR/on-trait.rs:28:30
+ |
+LL | let y: Option<Vec<u8>> = collect(x.iter()); // this should give approximately the same error for x.iter().collect()
+ | ^^^^^^^ a collection of type `Option<Vec<u8>>` cannot be built from an iterator over elements of type `&u8`
+ |
+ = help: the trait `MyFromIterator<&u8>` is not implemented for `Option<Vec<u8>>`
+note: required by a bound in `collect`
+ --> $DIR/on-trait.rs:22:39
+ |
+LL | fn collect<A, I: Iterator<Item=A>, B: MyFromIterator<A>>(it: I) -> B {
+ | ^^^^^^^^^^^^^^^^^ required by this bound in `collect`
+
+error[E0277]: the trait bound `String: Foo<u8, _, u32>` is not satisfied
+ --> $DIR/on-trait.rs:31:21
+ |
+LL | let x: String = foobar();
+ | ^^^^^^ test error `String` with `u8` `_` `u32` in `Foo`
+ |
+ = help: the trait `Foo<u8, _, u32>` is not implemented for `String`
+note: required by a bound in `foobar`
+ --> $DIR/on-trait.rs:12:24
+ |
+LL | fn foobar<U: Clone, T: Foo<u8, U, u32>>() -> T {
+ | ^^^^^^^^^^^^^^^ required by this bound in `foobar`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/on-unimplemented/slice-index.rs b/src/test/ui/on-unimplemented/slice-index.rs
new file mode 100644
index 000000000..758220d3c
--- /dev/null
+++ b/src/test/ui/on-unimplemented/slice-index.rs
@@ -0,0 +1,10 @@
+// Test new Index error message for slices
+
+use std::ops::Index;
+
+
+fn main() {
+ let x = &[1, 2, 3] as &[i32];
+ x[1i32]; //~ ERROR E0277
+ x[..1i32]; //~ ERROR E0277
+}
diff --git a/src/test/ui/on-unimplemented/slice-index.stderr b/src/test/ui/on-unimplemented/slice-index.stderr
new file mode 100644
index 000000000..72f67a685
--- /dev/null
+++ b/src/test/ui/on-unimplemented/slice-index.stderr
@@ -0,0 +1,25 @@
+error[E0277]: the type `[i32]` cannot be indexed by `i32`
+ --> $DIR/slice-index.rs:8:7
+ |
+LL | x[1i32];
+ | ^^^^ slice indices are of type `usize` or ranges of `usize`
+ |
+ = help: the trait `SliceIndex<[i32]>` is not implemented for `i32`
+ = help: the trait `SliceIndex<[T]>` is implemented for `usize`
+ = note: required because of the requirements on the impl of `Index<i32>` for `[i32]`
+
+error[E0277]: the type `[i32]` cannot be indexed by `RangeTo<i32>`
+ --> $DIR/slice-index.rs:9:7
+ |
+LL | x[..1i32];
+ | ^^^^^^ slice indices are of type `usize` or ranges of `usize`
+ |
+ = help: the trait `SliceIndex<[i32]>` is not implemented for `RangeTo<i32>`
+ = help: the following other types implement trait `SliceIndex<T>`:
+ <RangeTo<usize> as SliceIndex<[T]>>
+ <RangeTo<usize> as SliceIndex<str>>
+ = note: required because of the requirements on the impl of `Index<RangeTo<i32>>` for `[i32]`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.