Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak "the following other types implement trait" #105338

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
11 changes: 3 additions & 8 deletions src/test/ui/binop/binop-mul-i32-f32.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ LL | x * y
|
= help: the trait `Mul<f32>` is not implemented for `i32`
= help: the following other types implement trait `Mul<Rhs>`:
<&'a f32 as Mul<f32>>
<&'a f64 as Mul<f64>>
<&'a i128 as Mul<i128>>
<&'a i16 as Mul<i16>>
<&'a i32 as Mul<i32>>
<&'a i64 as Mul<i64>>
<&'a i8 as Mul<i8>>
<&'a isize as Mul<isize>>
and 49 others
<&i32 as Mul<&i32>>
<i32 as Mul<&i32>>
<i32 as Mul>

error: aborting due to previous error

Expand Down
8 changes: 2 additions & 6 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ LL |
LL | 1_u32
| ----- return type was inferred to be `u32` here
|
= help: the following other types implement trait `Traitor<N, M>`:
<u32 as Traitor<N, 2>>
<u64 as Traitor<1, 2>>
= help: the trait `Traitor<N, 2>` is implemented for `u32`

error[E0277]: the trait bound `u64: Traitor` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:21:13
Expand All @@ -31,9 +29,7 @@ LL |
LL | 1_u64
| ----- return type was inferred to be `u64` here
|
= help: the following other types implement trait `Traitor<N, M>`:
<u32 as Traitor<N, 2>>
<u64 as Traitor<1, 2>>
= help: the trait `Traitor<1, 2>` is implemented for `u64`

error: aborting due to 3 previous errors

Expand Down
11 changes: 3 additions & 8 deletions src/test/ui/consts/const-eval/const-eval-overflow-3b.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ LL | = [0; (i8::MAX + 1u8) as usize];
|
= help: the trait `~const Add<u8>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
<&'a i8 as Add<i8>>
<&'a isize as Add<isize>>
and 48 others
<&i8 as Add<&i8>>
<i8 as Add<&i8>>
<i8 as Add>

error: aborting due to 2 previous errors

Expand Down
11 changes: 3 additions & 8 deletions src/test/ui/consts/const-eval/const-eval-overflow-4b.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ LL | : [u32; (i8::MAX as i8 + 1u8) as usize]
|
= help: the trait `~const Add<u8>` is not implemented for `i8`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
<&'a i8 as Add<i8>>
<&'a isize as Add<isize>>
and 48 others
<&i8 as Add<&i8>>
<i8 as Add<&i8>>
<i8 as Add>

error[E0604]: only `u8` can be cast as `char`, not `i8`
--> $DIR/const-eval-overflow-4b.rs:22:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ LL | Foo::<i32>::bar(&1i8);
<i8 as Foo<u32>>
<i8 as Foo<u64>>
<i8 as Foo<u8>>
<u8 as Foo<bool>>
<u8 as Foo<u16>>
<u8 as Foo<u32>>
<u8 as Foo<u64>>

error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
--> $DIR/issue-39802-show-5-trait-impls.rs:25:21
Expand All @@ -26,11 +22,6 @@ LL | Foo::<i32>::bar(&1u8);
| required by a bound introduced by this call
|
= help: the following other types implement trait `Foo<B>`:
<i8 as Foo<bool>>
<i8 as Foo<u16>>
<i8 as Foo<u32>>
<i8 as Foo<u64>>
<i8 as Foo<u8>>
<u8 as Foo<bool>>
<u8 as Foo<u16>>
<u8 as Foo<u32>>
Expand Down
13 changes: 4 additions & 9 deletions src/test/ui/impl-trait/equality.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ LL | n + sum_to(n - 1)
|
= help: the trait `Add<impl Foo>` is not implemented for `u32`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
<&'a i8 as Add<i8>>
<&'a isize as Add<isize>>
and 48 others
<&'a u32 as Add<u32>>
<&u32 as Add<&u32>>
<u32 as Add<&u32>>
<u32 as Add>

error: aborting due to 2 previous errors; 1 warning emitted

Expand Down
11 changes: 3 additions & 8 deletions src/test/ui/issues/issue-24352.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ LL | 1.0f64 - 1
|
= help: the trait `Sub<{integer}>` is not implemented for `f64`
= help: the following other types implement trait `Sub<Rhs>`:
<&'a f32 as Sub<f32>>
<&'a f64 as Sub<f64>>
<&'a i128 as Sub<i128>>
<&'a i16 as Sub<i16>>
<&'a i32 as Sub<i32>>
<&'a i64 as Sub<i64>>
<&'a i8 as Sub<i8>>
<&'a isize as Sub<isize>>
and 48 others
<&f64 as Sub<&f64>>
<f64 as Sub<&f64>>
<f64 as Sub>
help: consider using a floating-point literal by writing it with `.0`
|
LL | 1.0f64 - 1.0
Expand Down
22 changes: 2 additions & 20 deletions src/test/ui/kindck/kindck-copy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ error[E0277]: the trait bound `&'static mut isize: Copy` is not satisfied
LL | assert_copy::<&'static mut isize>();
| ^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `&'static mut isize`
|
= help: the following other types implement trait `Copy`:
f32
f64
i128
i16
i32
i64
i8
isize
and 6 others
= help: the trait `Copy` is implemented for `isize`
note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18
|
Expand All @@ -26,16 +17,7 @@ error[E0277]: the trait bound `&'a mut isize: Copy` is not satisfied
LL | assert_copy::<&'a mut isize>();
| ^^^^^^^^^^^^^ the trait `Copy` is not implemented for `&'a mut isize`
|
= help: the following other types implement trait `Copy`:
f32
f64
i128
i16
i32
i64
i8
isize
and 6 others
= help: the trait `Copy` is implemented for `isize`
note: required by a bound in `assert_copy`
--> $DIR/kindck-copy.rs:5:18
|
Expand Down
18 changes: 8 additions & 10 deletions src/test/ui/lexer/lex-bad-char-literals-6.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ LL | if x == y {}
<&'a str as PartialEq<OsString>>
<&'a str as PartialEq<String>>
<&'b str as PartialEq<Cow<'a, str>>>
<String as PartialEq<&'a str>>
<String as PartialEq<Cow<'a, str>>>
<String as PartialEq<str>>
<String as PartialEq>
<str as PartialEq<Cow<'a, str>>>
and 4 others
<str as PartialEq<OsStr>>
<str as PartialEq<OsString>>
<str as PartialEq<String>>
<str as PartialEq>

error[E0308]: mismatched types
--> $DIR/lex-bad-char-literals-6.rs:15:20
Expand All @@ -68,12 +67,11 @@ LL | if x == z {}
<&'a str as PartialEq<OsString>>
<&'a str as PartialEq<String>>
<&'b str as PartialEq<Cow<'a, str>>>
<String as PartialEq<&'a str>>
<String as PartialEq<Cow<'a, str>>>
<String as PartialEq<str>>
<String as PartialEq>
<str as PartialEq<Cow<'a, str>>>
and 4 others
<str as PartialEq<OsStr>>
<str as PartialEq<OsString>>
<str as PartialEq<String>>
<str as PartialEq>

error: aborting due to 6 previous errors

Expand Down
13 changes: 4 additions & 9 deletions src/test/ui/mismatched_types/binops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@ LL | 2 as usize - Some(1);
|
= help: the trait `Sub<Option<{integer}>>` is not implemented for `usize`
= help: the following other types implement trait `Sub<Rhs>`:
<&'a f32 as Sub<f32>>
<&'a f64 as Sub<f64>>
<&'a i128 as Sub<i128>>
<&'a i16 as Sub<i16>>
<&'a i32 as Sub<i32>>
<&'a i64 as Sub<i64>>
<&'a i8 as Sub<i8>>
<&'a isize as Sub<isize>>
and 48 others
<&'a usize as Sub<usize>>
<&usize as Sub<&usize>>
<usize as Sub<&usize>>
<usize as Sub>

error[E0277]: cannot multiply `{integer}` by `()`
--> $DIR/binops.rs:4:7
Expand Down
13 changes: 4 additions & 9 deletions src/test/ui/never_type/issue-13352.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ LL | 2_usize + (loop {});
|
= help: the trait `Add<()>` is not implemented for `usize`
= help: the following other types implement trait `Add<Rhs>`:
<&'a f32 as Add<f32>>
<&'a f64 as Add<f64>>
<&'a i128 as Add<i128>>
<&'a i16 as Add<i16>>
<&'a i32 as Add<i32>>
<&'a i64 as Add<i64>>
<&'a i8 as Add<i8>>
<&'a isize as Add<isize>>
and 48 others
<&'a usize as Add<usize>>
<&usize as Add<&usize>>
<usize as Add<&usize>>
<usize as Add>

error: aborting due to previous error

Expand Down
Loading