Skip to content

Commit 3e25bcb

Browse files
committed
Mention implementations that satisfy the trait
1 parent b3fba5e commit 3e25bcb

File tree

6 files changed

+40
-3
lines changed

6 files changed

+40
-3
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
980980
trait_ref,
981981
obligation.cause.body_id,
982982
&mut err,
983+
true,
983984
) {
984985
// This is *almost* equivalent to
985986
// `obligation.cause.code().peel_derives()`, but it gives us the
@@ -1015,6 +1016,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10151016
trait_ref,
10161017
obligation.cause.body_id,
10171018
&mut err,
1019+
true,
10181020
);
10191021
}
10201022
}
@@ -1432,6 +1434,7 @@ trait InferCtxtPrivExt<'tcx> {
14321434
trait_ref: ty::PolyTraitRef<'tcx>,
14331435
body_id: hir::HirId,
14341436
err: &mut Diagnostic,
1437+
other: bool,
14351438
) -> bool;
14361439

14371440
/// Gets the parent trait chain start
@@ -1887,7 +1890,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
18871890
trait_ref: ty::PolyTraitRef<'tcx>,
18881891
body_id: hir::HirId,
18891892
err: &mut Diagnostic,
1893+
other: bool,
18901894
) -> bool {
1895+
let other = if other { "other " } else { "" };
18911896
let report = |mut candidates: Vec<TraitRef<'tcx>>, err: &mut Diagnostic| {
18921897
candidates.sort();
18931898
candidates.dedup();
@@ -1938,7 +1943,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19381943
candidates.dedup();
19391944
let end = if candidates.len() <= 9 { candidates.len() } else { 8 };
19401945
err.help(&format!(
1941-
"the following other types implement trait `{}`:{}{}",
1946+
"the following {other}types implement trait `{}`:{}{}",
19421947
trait_ref.print_only_trait_path(),
19431948
candidates[..end].join(""),
19441949
if len > 9 { format!("\nand {} others", len - 8) } else { String::new() }
@@ -2179,14 +2184,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21792184
trait_ref.skip_binder().substs.types().any(|t| !t.is_ty_infer());
21802185
// It doesn't make sense to talk about applicable impls if there are more
21812186
// than a handful of them.
2182-
if impls.len() > 1 && impls.len() < 5 && has_non_region_infer {
2187+
if impls.len() > 1 && impls.len() < 10 && has_non_region_infer {
21832188
self.annotate_source_of_ambiguity(&mut err, &impls, predicate);
21842189
} else {
21852190
if self.tainted_by_errors().is_some() {
21862191
err.cancel();
21872192
return;
21882193
}
21892194
err.note(&format!("cannot satisfy `{}`", predicate));
2195+
let impl_candidates = self.find_similar_impl_candidates(
2196+
predicate.to_opt_poly_trait_pred().unwrap(),
2197+
);
2198+
if impl_candidates.len() < 10 {
2199+
self.report_similar_impl_candidates(
2200+
impl_candidates,
2201+
trait_ref,
2202+
body_id.map(|id| id.hir_id).unwrap_or(obligation.cause.body_id),
2203+
&mut err,
2204+
false,
2205+
);
2206+
}
21902207
}
21912208
}
21922209
_ => {

src/test/ui/const-generics/generic_arg_infer/issue-91614.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ LL | let y = Mask::<_, _>::splat(false);
55
| ^ ------------------- type must be known at this point
66
|
77
= note: cannot satisfy `_: MaskElement`
8+
= help: the following types implement trait `MaskElement`:
9+
i16
10+
i32
11+
i64
12+
i8
13+
isize
814
note: required by a bound in `Mask::<T, LANES>::splat`
915
--> $SRC_DIR/core/src/../../portable-simd/crates/core_simd/src/masks.rs:LL:COL
1016
|

src/test/ui/const-generics/generic_const_exprs/issue-72787.min.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ LL | IsLessOrEqual<I, 8>: True,
4141
| ^^^^
4242
|
4343
= note: cannot satisfy `IsLessOrEqual<I, 8>: True`
44+
= help: the trait `True` is implemented for `IsLessOrEqual<LHS, RHS>`
4445

4546
error[E0283]: type annotations needed: cannot satisfy `IsLessOrEqual<I, 8>: True`
4647
--> $DIR/issue-72787.rs:21:26
@@ -49,6 +50,7 @@ LL | IsLessOrEqual<I, 8>: True,
4950
| ^^^^
5051
|
5152
= note: cannot satisfy `IsLessOrEqual<I, 8>: True`
53+
= help: the trait `True` is implemented for `IsLessOrEqual<LHS, RHS>`
5254

5355
error: aborting due to 6 previous errors
5456

src/test/ui/lifetimes/issue-34979.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | &'a (): Foo,
55
| ^^^
66
|
77
= note: cannot satisfy `&'a (): Foo`
8+
= help: the trait `Foo` is implemented for `&'a T`
89

910
error: aborting due to previous error
1011

src/test/ui/traits/issue-77982.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(0u32.into())).collect(
4646
| |
4747
| required by a bound introduced by this call
4848
|
49-
= note: cannot satisfy `u32: From<_>`
49+
= note: multiple `impl`s satisfying `u32: From<_>` found in the following crates: `core`, `std`:
50+
- impl From<Ipv4Addr> for u32;
51+
- impl From<NonZeroU32> for u32;
52+
- impl From<bool> for u32;
53+
- impl From<char> for u32;
54+
- impl From<u16> for u32;
55+
- impl From<u8> for u32;
56+
- impl<T> From<!> for T;
57+
- impl<T> From<T> for T;
5058
help: try using a fully qualified path to specify the expected types
5159
|
5260
LL | let ips: Vec<_> = (0..100_000).map(|_| u32::from(<u32 as Into<T>>::into(0u32))).collect();

src/test/ui/traits/issue-85735.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ LL | T: FnMut(&'a ()),
55
| ^^^^^^^^^^^^^
66
|
77
= note: cannot satisfy `T: FnMut<(&'a (),)>`
8+
= help: the following types implement trait `FnMut<Args>`:
9+
&F
10+
&mut F
811

912
error: aborting due to previous error
1013

0 commit comments

Comments
 (0)