From d04c027e9333d632a9ee0dcfbdf0d79dfddf0318 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Fri, 13 Jan 2017 11:40:44 -0800 Subject: Use multiline Diagnostic for "relevant impl" list Provide the following output: ``` error[E0277]: the trait bound `Bar: Foo` is not satisfied --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8 | 38 | f1.foo(1usize); | ^^^ the trait `Foo` is not implemented for `Bar` | = help: the following implementations were found: > > > > and 2 others error: aborting due to previous error ``` instead of ``` error[E0277]: the trait bound `Bar: Foo` is not satisfied --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8 | 38 | f1.foo(1usize); | ^^^ the trait `Foo` is not implemented for `Bar` | = help: the following implementations were found: = help: > = help: > = help: > = help: > = help: and 2 others error: aborting due to previous error ``` --- src/librustc/traits/error_reporting.rs | 18 +++++---- .../issue-21659-show-relevant-trait-impls-1.rs | 39 ------------------ .../issue-21659-show-relevant-trait-impls-2.rs | 46 ---------------------- .../issue-21659-show-relevant-trait-impls-1.rs | 39 ++++++++++++++++++ .../issue-21659-show-relevant-trait-impls-1.stderr | 12 ++++++ .../issue-21659-show-relevant-trait-impls-2.rs | 46 ++++++++++++++++++++++ .../issue-21659-show-relevant-trait-impls-2.stderr | 15 +++++++ src/test/ui/span/multiline-span-simple.stderr | 8 ++-- 8 files changed, 126 insertions(+), 97 deletions(-) delete mode 100644 src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs delete mode 100644 src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs create mode 100644 src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.rs create mode 100644 src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr create mode 100644 src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.rs create mode 100644 src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr (limited to 'src') diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index ab8c552d561..5cc9875e801 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -366,15 +366,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return; } - err.help(&format!("the following implementations were found:")); - let end = cmp::min(4, impl_candidates.len()); - for candidate in &impl_candidates[0..end] { - err.help(&format!(" {:?}", candidate)); - } - if impl_candidates.len() > 4 { - err.help(&format!("and {} others", impl_candidates.len()-4)); - } + err.help(&format!("the following implementations were found:{}{}", + &impl_candidates[0..end].iter().map(|candidate| { + format!("\n {:?}", candidate) + }).collect::(), + if impl_candidates.len() > 4 { + format!("\nand {} others", impl_candidates.len() - 4) + } else { + "".to_owned() + } + )); } /// Reports that an overflow has occurred and halts compilation. We diff --git a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs deleted file mode 100644 index 99035209e14..00000000000 --- a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-1.rs +++ /dev/null @@ -1,39 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait Foo { - fn foo(&self, a: A) -> A { - a - } -} - -trait NotRelevant { - fn nr(&self, a: A) -> A { - a - } -} - -struct Bar; - -impl Foo for Bar {} - -impl Foo for Bar {} - -impl NotRelevant for Bar {} - -fn main() { - let f1 = Bar; - - f1.foo(1usize); - //~^ error: the trait bound `Bar: Foo` is not satisfied - //~| help: the following implementations were found: - //~| help: > - //~| help: > -} diff --git a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs b/src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs deleted file mode 100644 index 2009c32c854..00000000000 --- a/src/test/compile-fail/issue-21659-show-relevant-trait-impls-2.rs +++ /dev/null @@ -1,46 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait Foo { - fn foo(&self, a: A) -> A { - a - } -} - -trait NotRelevant { - fn nr(&self, a: A) -> A { - a - } -} - -struct Bar; - -impl Foo for Bar {} -impl Foo for Bar {} -impl Foo for Bar {} - -impl Foo for Bar {} -impl Foo for Bar {} -impl Foo for Bar {} - -impl NotRelevant for Bar {} - -fn main() { - let f1 = Bar; - - f1.foo(1usize); - //~^ error: the trait bound `Bar: Foo` is not satisfied - //~| help: the following implementations were found: - //~| help: > - //~| help: > - //~| help: > - //~| help: > - //~| help: and 2 others -} diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.rs b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.rs new file mode 100644 index 00000000000..99035209e14 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.rs @@ -0,0 +1,39 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(&self, a: A) -> A { + a + } +} + +trait NotRelevant { + fn nr(&self, a: A) -> A { + a + } +} + +struct Bar; + +impl Foo for Bar {} + +impl Foo for Bar {} + +impl NotRelevant for Bar {} + +fn main() { + let f1 = Bar; + + f1.foo(1usize); + //~^ error: the trait bound `Bar: Foo` is not satisfied + //~| help: the following implementations were found: + //~| help: > + //~| help: > +} diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr new file mode 100644 index 00000000000..9010de081da --- /dev/null +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-1.stderr @@ -0,0 +1,12 @@ +error[E0277]: the trait bound `Bar: Foo` is not satisfied + --> $DIR/issue-21659-show-relevant-trait-impls-1.rs:34:8 + | +34 | f1.foo(1usize); + | ^^^ the trait `Foo` is not implemented for `Bar` + | + = help: the following implementations were found: + > + > + +error: aborting due to previous error + diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.rs b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.rs new file mode 100644 index 00000000000..2009c32c854 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.rs @@ -0,0 +1,46 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn foo(&self, a: A) -> A { + a + } +} + +trait NotRelevant { + fn nr(&self, a: A) -> A { + a + } +} + +struct Bar; + +impl Foo for Bar {} +impl Foo for Bar {} +impl Foo for Bar {} + +impl Foo for Bar {} +impl Foo for Bar {} +impl Foo for Bar {} + +impl NotRelevant for Bar {} + +fn main() { + let f1 = Bar; + + f1.foo(1usize); + //~^ error: the trait bound `Bar: Foo` is not satisfied + //~| help: the following implementations were found: + //~| help: > + //~| help: > + //~| help: > + //~| help: > + //~| help: and 2 others +} diff --git a/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr new file mode 100644 index 00000000000..e9591a64784 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-21659-show-relevant-trait-impls-2.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `Bar: Foo` is not satisfied + --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8 + | +38 | f1.foo(1usize); + | ^^^ the trait `Foo` is not implemented for `Bar` + | + = help: the following implementations were found: + > + > + > + > + and 2 others + +error: aborting due to previous error + diff --git a/src/test/ui/span/multiline-span-simple.stderr b/src/test/ui/span/multiline-span-simple.stderr index b801325114c..85c11c05b9f 100644 --- a/src/test/ui/span/multiline-span-simple.stderr +++ b/src/test/ui/span/multiline-span-simple.stderr @@ -10,10 +10,10 @@ error[E0277]: the trait bound `u32: std::ops::Add<()>` is not satisfied | |______________^ ...ending here: the trait `std::ops::Add<()>` is not implemented for `u32` | = help: the following implementations were found: - = help: - = help: <&'a u32 as std::ops::Add> - = help: > - = help: <&'b u32 as std::ops::Add<&'a u32>> + + <&'a u32 as std::ops::Add> + > + <&'b u32 as std::ops::Add<&'a u32>> error: aborting due to previous error -- cgit 1.4.1-3-g733a5