diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2016-11-09 20:51:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-11-09 20:51:16 +0200 |
| commit | 7f2853fda3773d4f9ec28484ba3592d5e825ca59 (patch) | |
| tree | e1e75573b26d35b20c4682d4008b1f8e835476ca /src/test/ui/span | |
| parent | 6c7b43375ad70b9b134973b461854bbe60313ffc (diff) | |
| parent | 40c2c0f833c0480c3cf3904fa3614cb0a01d7f87 (diff) | |
| download | rust-7f2853fda3773d4f9ec28484ba3592d5e825ca59.tar.gz rust-7f2853fda3773d4f9ec28484ba3592d5e825ca59.zip | |
Rollup merge of #37370 - estebank:signature-2-empire-strikes-back, r=nikomatsakis
Include type of missing trait methods in error Provide either a span pointing to the original definition of missing trait items, or a message with the inferred definitions. Fixes #24626. Follow up to PR #36371. If PR #37369 lands, missing trait items that present a multiline span will be able to show the entirety of the item definition on the error itself, instead of just the first line.
Diffstat (limited to 'src/test/ui/span')
| -rw-r--r-- | src/test/ui/span/E0046.rs | 23 | ||||
| -rw-r--r-- | src/test/ui/span/E0046.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/span/impl-wrong-item-for-trait.rs | 56 | ||||
| -rw-r--r-- | src/test/ui/span/impl-wrong-item-for-trait.stderr | 64 | ||||
| -rw-r--r-- | src/test/ui/span/issue-23729.rs | 45 | ||||
| -rw-r--r-- | src/test/ui/span/issue-23729.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/span/issue-23827.rs | 45 | ||||
| -rw-r--r-- | src/test/ui/span/issue-23827.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/span/issue-24356.rs | 41 | ||||
| -rw-r--r-- | src/test/ui/span/issue-24356.stderr | 10 |
10 files changed, 315 insertions, 0 deletions
diff --git a/src/test/ui/span/E0046.rs b/src/test/ui/span/E0046.rs new file mode 100644 index 00000000000..9e757860a85 --- /dev/null +++ b/src/test/ui/span/E0046.rs @@ -0,0 +1,23 @@ +// 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 <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. + +trait Foo { + fn foo(); + //~^ NOTE `foo` from trait +} + +struct Bar; + +impl Foo for Bar {} +//~^ ERROR E0046 +//~| NOTE missing `foo` in implementation + +fn main() { +} diff --git a/src/test/ui/span/E0046.stderr b/src/test/ui/span/E0046.stderr new file mode 100644 index 00000000000..729a5156124 --- /dev/null +++ b/src/test/ui/span/E0046.stderr @@ -0,0 +1,11 @@ +error[E0046]: not all trait items implemented, missing: `foo` + --> $DIR/E0046.rs:18:1 + | +12 | fn foo(); + | --------- `foo` from trait +... +18 | impl Foo for Bar {} + | ^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation + +error: aborting due to previous error + diff --git a/src/test/ui/span/impl-wrong-item-for-trait.rs b/src/test/ui/span/impl-wrong-item-for-trait.rs new file mode 100644 index 00000000000..54ed42af5d5 --- /dev/null +++ b/src/test/ui/span/impl-wrong-item-for-trait.rs @@ -0,0 +1,56 @@ +// Copyright 2015 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(associated_consts)] + +use std::fmt::Debug; + +trait Foo { + fn bar(&self); + const MY_CONST: u32; +} + +pub struct FooConstForMethod; + +impl Foo for FooConstForMethod { + //~^ ERROR E0046 + //~| NOTE missing `bar` in implementation + const bar: u64 = 1; + //~^ ERROR E0323 + //~| NOTE does not match trait + const MY_CONST: u32 = 1; +} + +pub struct FooMethodForConst; + +impl Foo for FooMethodForConst { + //~^ ERROR E0046 + //~| NOTE missing `MY_CONST` in implementation + fn bar(&self) {} + fn MY_CONST() {} + //~^ ERROR E0324 + //~| NOTE does not match trait +} + +pub struct FooTypeForMethod; + +impl Foo for FooTypeForMethod { + //~^ ERROR E0046 + //~| NOTE missing `bar` in implementation + type bar = u64; + //~^ ERROR E0325 + //~| NOTE does not match trait + const MY_CONST: u32 = 1; +} + +impl Debug for FooTypeForMethod { +} + +fn main () {} diff --git a/src/test/ui/span/impl-wrong-item-for-trait.stderr b/src/test/ui/span/impl-wrong-item-for-trait.stderr new file mode 100644 index 00000000000..244285e3584 --- /dev/null +++ b/src/test/ui/span/impl-wrong-item-for-trait.stderr @@ -0,0 +1,64 @@ +error[E0323]: item `bar` is an associated const, which doesn't match its trait `<FooConstForMethod as Foo>` + --> $DIR/impl-wrong-item-for-trait.rs:25:5 + | +16 | fn bar(&self); + | -------------- item in trait +... +25 | const bar: u64 = 1; + | ^^^^^^^^^^^^^^^^^^^ does not match trait + +error[E0046]: not all trait items implemented, missing: `bar` + --> $DIR/impl-wrong-item-for-trait.rs:22:1 + | +16 | fn bar(&self); + | -------------- `bar` from trait +... +22 | impl Foo for FooConstForMethod { + | ^ missing `bar` in implementation + +error[E0324]: item `MY_CONST` is an associated method, which doesn't match its trait `<FooMethodForConst as Foo>` + --> $DIR/impl-wrong-item-for-trait.rs:37:5 + | +17 | const MY_CONST: u32; + | -------------------- item in trait +... +37 | fn MY_CONST() {} + | ^^^^^^^^^^^^^^^^ does not match trait + +error[E0046]: not all trait items implemented, missing: `MY_CONST` + --> $DIR/impl-wrong-item-for-trait.rs:33:1 + | +17 | const MY_CONST: u32; + | -------------------- `MY_CONST` from trait +... +33 | impl Foo for FooMethodForConst { + | ^ missing `MY_CONST` in implementation + +error[E0325]: item `bar` is an associated type, which doesn't match its trait `<FooTypeForMethod as Foo>` + --> $DIR/impl-wrong-item-for-trait.rs:47:5 + | +16 | fn bar(&self); + | -------------- item in trait +... +47 | type bar = u64; + | ^^^^^^^^^^^^^^^ does not match trait + +error[E0046]: not all trait items implemented, missing: `bar` + --> $DIR/impl-wrong-item-for-trait.rs:44:1 + | +16 | fn bar(&self); + | -------------- `bar` from trait +... +44 | impl Foo for FooTypeForMethod { + | ^ missing `bar` in implementation + +error[E0046]: not all trait items implemented, missing: `fmt` + --> $DIR/impl-wrong-item-for-trait.rs:53:1 + | +53 | impl Debug for FooTypeForMethod { + | ^ missing `fmt` in implementation + | + = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>` + +error: aborting due to 7 previous errors + diff --git a/src/test/ui/span/issue-23729.rs b/src/test/ui/span/issue-23729.rs new file mode 100644 index 00000000000..66134a03baf --- /dev/null +++ b/src/test/ui/span/issue-23729.rs @@ -0,0 +1,45 @@ +// Copyright 2015 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. + +// Regression test for #23729 + +fn main() { + let fib = { + struct Recurrence { + mem: [u64; 2], + pos: usize, + } + + impl Iterator for Recurrence { + //~^ ERROR E0046 + //~| NOTE missing `Item` in implementation + //~| NOTE `Item` from trait: `type Item;` + #[inline] + fn next(&mut self) -> Option<u64> { + if self.pos < 2 { + let next_val = self.mem[self.pos]; + self.pos += 1; + Some(next_val) + } else { + let next_val = self.mem[0] + self.mem[1]; + self.mem[0] = self.mem[1]; + self.mem[1] = next_val; + Some(next_val) + } + } + } + + Recurrence { mem: [0, 1], pos: 0 } + }; + + for e in fib.take(10) { + println!("{}", e) + } +} diff --git a/src/test/ui/span/issue-23729.stderr b/src/test/ui/span/issue-23729.stderr new file mode 100644 index 00000000000..493ca01778b --- /dev/null +++ b/src/test/ui/span/issue-23729.stderr @@ -0,0 +1,10 @@ +error[E0046]: not all trait items implemented, missing: `Item` + --> $DIR/issue-23729.rs:20:9 + | +20 | impl Iterator for Recurrence { + | ^ missing `Item` in implementation + | + = note: `Item` from trait: `type Item;` + +error: aborting due to previous error + diff --git a/src/test/ui/span/issue-23827.rs b/src/test/ui/span/issue-23827.rs new file mode 100644 index 00000000000..a5ab443597b --- /dev/null +++ b/src/test/ui/span/issue-23827.rs @@ -0,0 +1,45 @@ +// Copyright 2015 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. + +// Regression test for #23827 + +#![feature(core, unboxed_closures)] + +pub struct Prototype { + pub target: u32 +} + +trait Component { + fn apply(self, e: u32); +} + +impl<C: Component> Fn<(C,)> for Prototype { + extern "rust-call" fn call(&self, (comp,): (C,)) -> Prototype { + comp.apply(self.target); + *self + } +} + +impl<C: Component> FnMut<(C,)> for Prototype { + extern "rust-call" fn call_mut(&mut self, (comp,): (C,)) -> Prototype { + Fn::call(*&self, (comp,)) + } +} + +impl<C: Component> FnOnce<(C,)> for Prototype { + //~^ ERROR E0046 + //~| NOTE missing `Output` in implementation + //~| NOTE `Output` from trait: `type Output;` + extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype { + Fn::call(&self, (comp,)) + } +} + +fn main() {} diff --git a/src/test/ui/span/issue-23827.stderr b/src/test/ui/span/issue-23827.stderr new file mode 100644 index 00000000000..5130bb53a19 --- /dev/null +++ b/src/test/ui/span/issue-23827.stderr @@ -0,0 +1,10 @@ +error[E0046]: not all trait items implemented, missing: `Output` + --> $DIR/issue-23827.rs:36:1 + | +36 | impl<C: Component> FnOnce<(C,)> for Prototype { + | ^ missing `Output` in implementation + | + = note: `Output` from trait: `type Output;` + +error: aborting due to previous error + diff --git a/src/test/ui/span/issue-24356.rs b/src/test/ui/span/issue-24356.rs new file mode 100644 index 00000000000..0997dc802f8 --- /dev/null +++ b/src/test/ui/span/issue-24356.rs @@ -0,0 +1,41 @@ +// Copyright 2015 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. + +// Regression test for #24356 + +// ignore-tidy-linelength + +fn main() { + { + use std::ops::Deref; + + struct Thing(i8); + + /* + // Correct impl + impl Deref for Thing { + type Target = i8; + fn deref(&self) -> &i8 { &self.0 } + } + */ + + // Causes ICE + impl Deref for Thing { + //~^ ERROR E0046 + //~| NOTE missing `Target` in implementation + //~| NOTE `Target` from trait: `type Target;` + fn deref(&self) -> i8 { self.0 } + } + + let thing = Thing(72); + + *thing + }; +} diff --git a/src/test/ui/span/issue-24356.stderr b/src/test/ui/span/issue-24356.stderr new file mode 100644 index 00000000000..906ef25ca0e --- /dev/null +++ b/src/test/ui/span/issue-24356.stderr @@ -0,0 +1,10 @@ +error[E0046]: not all trait items implemented, missing: `Target` + --> $DIR/issue-24356.rs:30:9 + | +30 | impl Deref for Thing { + | ^ missing `Target` in implementation + | + = note: `Target` from trait: `type Target;` + +error: aborting due to previous error + |
