diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-12-06 12:48:54 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-06 12:48:54 +0900 |
| commit | 1310d9bd2b9283fa311b8706b2bca59a4dff63d5 (patch) | |
| tree | 8ad3b73acdf2d7b239ce2db45401a9418845926c /compiler/rustc_trait_selection/src/traits | |
| parent | e09c71e4c127e4a0fd6644a56ef06a7a0377a215 (diff) | |
| parent | e1649c442f47a8b9d071b5bcca20684b70b393d4 (diff) | |
| download | rust-1310d9bd2b9283fa311b8706b2bca59a4dff63d5.tar.gz rust-1310d9bd2b9283fa311b8706b2bca59a4dff63d5.zip | |
Rollup merge of #105338 - estebank:other-impls, r=compiler-errors
Tweak "the following other types implement trait" When *any* of the suggested impls is an exact match, *only* show the exact matches. This is particularly relevant for integer types. r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 3379279dd15..12cc72d30c8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1810,7 +1810,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { &self, trait_pred: ty::PolyTraitPredicate<'tcx>, ) -> Vec<ImplCandidate<'tcx>> { - self.tcx + let mut candidates: Vec<_> = self + .tcx .all_impls(trait_pred.def_id()) .filter_map(|def_id| { if self.tcx.impl_polarity(def_id) == ty::ImplPolarity::Negative @@ -1826,7 +1827,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false) .map(|similarity| ImplCandidate { trait_ref: imp, similarity }) }) - .collect() + .collect(); + if candidates.iter().any(|c| matches!(c.similarity, CandidateSimilarity::Exact { .. })) { + // If any of the candidates is a perfect match, we don't want to show all of them. + // This is particularly relevant for the case of numeric types (as they all have the + // same cathegory). + candidates.retain(|c| matches!(c.similarity, CandidateSimilarity::Exact { .. })); + } + candidates } fn report_similar_impl_candidates( |
