Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use rustc_middle::ty::print::{
with_forced_trimmed_paths,
};
use rustc_middle::ty::{
self, TraitRef, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
Upcast,
self, GenericArgKind, TraitRef, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt, Upcast,
};
use rustc_middle::{bug, span_bug};
use rustc_span::{BytePos, DUMMY_SP, STDLIB_STABLE_CRATES, Span, Symbol, sym};
Expand Down Expand Up @@ -2316,7 +2316,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
cand
})
.collect();
impl_candidates.sort_by_key(|cand| (cand.similarity, cand.trait_ref.to_string()));
impl_candidates.sort_by_key(|cand| {
let len = if let GenericArgKind::Type(ty) = cand.trait_ref.args[0].kind()
&& let ty::Array(_, len) = ty.kind()
&& let Some(len) = len.try_to_target_usize(self.tcx)
Comment on lines +2320 to +2322
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider leaving a comment here about why we are doing this

{
len
} else {
0
};

(cand.similarity, len, cand.trait_ref.to_string())
});
let mut impl_candidates: Vec<_> =
impl_candidates.into_iter().map(|cand| cand.trait_ref).collect();
impl_candidates.dedup();
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/consts/missing-larger-array-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ LL | <[X; 35] as Default>::default();
&[T]
&mut [T]
[T; 0]
[T; 10]
[T; 11]
[T; 12]
[T; 13]
[T; 14]
[T; 1]
[T; 2]
[T; 3]
[T; 4]
[T; 5]
and 27 others

error: aborting due to 1 previous error
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/suggestions/issue-71394-no-from-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ LL | let _: &[i8] = data.into();
| ^^^^ the trait `From<&[u8]>` is not implemented for `&[i8]`
|
= help: the following other types implement trait `From<T>`:
`[T; 10]` implements `From<(T, T, T, T, T, T, T, T, T, T)>`
`[T; 11]` implements `From<(T, T, T, T, T, T, T, T, T, T, T)>`
`[T; 12]` implements `From<(T, T, T, T, T, T, T, T, T, T, T, T)>`
`[T; N]` implements `From<Simd<T, N>>`
`[bool; N]` implements `From<Mask<T, N>>`
`[T; 1]` implements `From<(T,)>`
`[T; 2]` implements `From<(T, T)>`
`[T; 3]` implements `From<(T, T, T)>`
`[T; 4]` implements `From<(T, T, T, T)>`
`[T; 5]` implements `From<(T, T, T, T, T)>`
`[T; 6]` implements `From<(T, T, T, T, T, T)>`
Comment on lines +8 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm. I'm not entirely sure if we should let parameterized array types appear on this list first.

and 6 others
= note: required for `&[u8]` to implement `Into<&[i8]>`

Expand Down
Loading