10097: fix: Allow inherent impls for arrays r=jonas-schievink a=jonas-schievink

Part of https://github.com/rust-analyzer/rust-analyzer/issues/9992 (method resolution of these methods still does not work)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-08-31 12:17:50 +00:00 committed by GitHub
commit bda50a1b46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -348,6 +348,7 @@ pub fn def_crates(
}
TyKind::Str => lang_item_crate!("str_alloc", "str"),
TyKind::Slice(_) => lang_item_crate!("slice_alloc", "slice"),
TyKind::Array(..) => lang_item_crate!("array"),
TyKind::Raw(Mutability::Not, _) => lang_item_crate!("const_ptr"),
TyKind::Raw(Mutability::Mut, _) => lang_item_crate!("mut_ptr"),
TyKind::Dyn(_) => {

View file

@ -36,6 +36,24 @@ fn infer_slice_method() {
);
}
#[test]
fn infer_array_inherent_impl() {
check_types(
r#"
#[lang = "array"]
impl<T, const N: usize> [T; N] {
fn foo(&self) -> T {
loop {}
}
}
fn test(x: &[u8; 0]) {
<[_; 0]>::foo(x);
//^^^^^^^^^^^^^^^^ u8
}
"#,
);
}
#[test]
fn infer_associated_method_struct() {
check_infer(