Skip to content

Commit 7efab3e

Browse files
Merge #6723
6723: Use correct, full substs for self type in impl r=flodiebold a=flodiebold Without arbitrary self types, the self type could never refer to the method type parameters, so this wasn't a problem; but with arbitrary self types, it can. This fixes the crash from #6668; but it doesn't make method resolution work for these methods. Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2 parents 6943b53 + e5fd550 commit 7efab3e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

crates/hir_ty/src/method_resolution.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,13 @@ fn transform_receiver_ty(
720720
.push(self_ty.value.clone())
721721
.fill_with_unknown()
722722
.build(),
723-
AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
723+
AssocContainerId::ImplId(impl_id) => {
724+
let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?;
725+
Substs::build_for_def(db, function_id)
726+
.use_parent_substs(&impl_substs)
727+
.fill_with_unknown()
728+
.build()
729+
}
724730
AssocContainerId::ContainerId(_) => unreachable!(),
725731
};
726732
let sig = db.callable_item_signature(function_id.into());

crates/hir_ty/src/tests/method_resolution.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1087,3 +1087,22 @@ fn method_resolution_foreign_opaque_type() {
10871087
"#]],
10881088
);
10891089
}
1090+
1091+
#[test]
1092+
fn method_with_allocator_box_self_type() {
1093+
check_types(
1094+
r#"
1095+
struct Slice<T> {}
1096+
struct Box<T, A> {}
1097+
1098+
impl<T> Slice<T> {
1099+
pub fn into_vec<A>(self: Box<Self, A>) { }
1100+
}
1101+
1102+
fn main() {
1103+
let foo: Slice<u32>;
1104+
(foo.into_vec()); // we don't actually support arbitrary self types, but we shouldn't crash at least
1105+
} //^ {unknown}
1106+
"#,
1107+
);
1108+
}

0 commit comments

Comments
 (0)