Skip to content

Commit bda50a1

Browse files
Merge #10097
10097: fix: Allow inherent impls for arrays r=jonas-schievink a=jonas-schievink Part of #9992 (method resolution of these methods still does not work) bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents f700862 + 418b163 commit bda50a1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

crates/hir_ty/src/method_resolution.rs

+1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ pub fn def_crates(
348348
}
349349
TyKind::Str => lang_item_crate!("str_alloc", "str"),
350350
TyKind::Slice(_) => lang_item_crate!("slice_alloc", "slice"),
351+
TyKind::Array(..) => lang_item_crate!("array"),
351352
TyKind::Raw(Mutability::Not, _) => lang_item_crate!("const_ptr"),
352353
TyKind::Raw(Mutability::Mut, _) => lang_item_crate!("mut_ptr"),
353354
TyKind::Dyn(_) => {

crates/hir_ty/src/tests/method_resolution.rs

+18
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ fn infer_slice_method() {
3636
);
3737
}
3838

39+
#[test]
40+
fn infer_array_inherent_impl() {
41+
check_types(
42+
r#"
43+
#[lang = "array"]
44+
impl<T, const N: usize> [T; N] {
45+
fn foo(&self) -> T {
46+
loop {}
47+
}
48+
}
49+
fn test(x: &[u8; 0]) {
50+
<[_; 0]>::foo(x);
51+
//^^^^^^^^^^^^^^^^ u8
52+
}
53+
"#,
54+
);
55+
}
56+
3957
#[test]
4058
fn infer_associated_method_struct() {
4159
check_infer(

0 commit comments

Comments
 (0)