From bec5b664fe4908c06665370f8f2afcf430a63f39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 12 Dec 2018 15:58:27 -0800 Subject: [PATCH 1/2] Deduplicate unsatisfied trait bounds --- src/librustc_typeck/check/method/suggest.rs | 8 +++++--- src/test/ui/issues/issue-31173.stderr | 2 +- src/test/ui/issues/issue-35677.rs | 5 +++++ src/test/ui/issues/issue-35677.stderr | 18 ++++++++++++++++++ .../ui/mismatched_types/issue-36053-2.stderr | 2 +- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/issues/issue-35677.rs create mode 100644 src/test/ui/issues/issue-35677.stderr diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index b76c9101eae02..4e5ceda54d44a 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -424,10 +424,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } if !unsatisfied_predicates.is_empty() { - let bound_list = unsatisfied_predicates.iter() + let mut bound_list = unsatisfied_predicates.iter() .map(|p| format!("`{} : {}`", p.self_ty(), p)) - .collect::>() - .join("\n"); + .collect::>(); + bound_list.sort(); + bound_list.dedup_by(|a, b| a == b); // #35677 + let bound_list = bound_list.join("\n"); err.note(&format!("the method `{}` exists but the following trait bounds \ were not satisfied:\n{}", item_name, diff --git a/src/test/ui/issues/issue-31173.stderr b/src/test/ui/issues/issue-31173.stderr index e2630b5b8ce47..ed6b325a01d4d 100644 --- a/src/test/ui/issues/issue-31173.stderr +++ b/src/test/ui/issues/issue-31173.stderr @@ -14,8 +14,8 @@ LL | .collect(); //~ ERROR no method named `collect` | ^^^^^^^ | = note: the method `collect` exists but the following trait bounds were not satisfied: - `std::iter::Cloned, [closure@$DIR/issue-31173.rs:16:39: 19:6 found_e:_]>> : std::iter::Iterator` `&mut std::iter::Cloned, [closure@$DIR/issue-31173.rs:16:39: 19:6 found_e:_]>> : std::iter::Iterator` + `std::iter::Cloned, [closure@$DIR/issue-31173.rs:16:39: 19:6 found_e:_]>> : std::iter::Iterator` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-35677.rs b/src/test/ui/issues/issue-35677.rs new file mode 100644 index 0000000000000..46d3f7e4af00b --- /dev/null +++ b/src/test/ui/issues/issue-35677.rs @@ -0,0 +1,5 @@ +use std::collections::HashMap; +fn intersect_map(this: &mut HashMap, other: HashMap) -> bool { + this.drain() + //~^ ERROR no method named +} diff --git a/src/test/ui/issues/issue-35677.stderr b/src/test/ui/issues/issue-35677.stderr new file mode 100644 index 0000000000000..dca096b93f5f3 --- /dev/null +++ b/src/test/ui/issues/issue-35677.stderr @@ -0,0 +1,18 @@ +error[E0601]: `main` function not found in crate `issue_35677` + | + = note: consider adding a `main` function to `$DIR/issue-35677.rs` + +error[E0599]: no method named `drain` found for type `&mut std::collections::HashMap` in the current scope + --> $DIR/issue-35677.rs:3:10 + | +LL | this.drain() + | ^^^^^ + | + = note: the method `drain` exists but the following trait bounds were not satisfied: + `K : std::cmp::Eq` + `K : std::hash::Hash` + +error: aborting due to 2 previous errors + +Some errors occurred: E0599, E0601. +For more information about an error, try `rustc --explain E0599`. diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index 86a92a70287e9..1fbac9d688140 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -5,8 +5,8 @@ LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); | ^^^^^ | = note: the method `count` exists but the following trait bounds were not satisfied: - `std::iter::Filter>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator` `&mut std::iter::Filter>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator` + `std::iter::Filter>, [closure@$DIR/issue-36053-2.rs:17:39: 17:53]> : std::iter::Iterator` error[E0631]: type mismatch in closure arguments --> $DIR/issue-36053-2.rs:17:32 From a39f184437243eaa3a37fd5fed2fb02dbd6c607d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 13 Dec 2018 09:36:18 -0800 Subject: [PATCH 2/2] Use `dedup` instead of `dedup_by` Co-Authored-By: estebank --- src/librustc_typeck/check/method/suggest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 4e5ceda54d44a..09063579c4214 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .map(|p| format!("`{} : {}`", p.self_ty(), p)) .collect::>(); bound_list.sort(); - bound_list.dedup_by(|a, b| a == b); // #35677 + bound_list.dedup(); // #35677 let bound_list = bound_list.join("\n"); err.note(&format!("the method `{}` exists but the following trait bounds \ were not satisfied:\n{}",