Ignore Destruct bounds again

This commit is contained in:
Lukas Wirth 2025-07-27 22:31:06 +02:00
parent b398bc6af7
commit afee0710e1
2 changed files with 41 additions and 2 deletions

View file

@ -590,9 +590,14 @@ impl<'a> TyLoweringContext<'a> {
.resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
let pointee_sized = LangItem::PointeeSized
.resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
if meta_sized.is_some_and(|it| it == trait_ref.hir_trait_id()) {
let destruct = LangItem::Destruct
.resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
let hir_trait_id = trait_ref.hir_trait_id();
if meta_sized.is_some_and(|it| it == hir_trait_id)
|| destruct.is_some_and(|it| it == hir_trait_id)
{
// Ignore this bound
} else if pointee_sized.is_some_and(|it| it == trait_ref.hir_trait_id()) {
} else if pointee_sized.is_some_and(|it| it == hir_trait_id) {
// Regard this as `?Sized` bound
ctx.ty_ctx().unsized_types.insert(self_ty);
} else {

View file

@ -2349,3 +2349,37 @@ fn test() {
"#]],
);
}
#[test]
fn rust_destruct_option_clone() {
check_types(
r#"
//- minicore: option, drop
fn test(o: &Option<i32>) {
o.my_clone();
//^^^^^^^^^^^^ Option<i32>
}
pub trait MyClone: Sized {
fn my_clone(&self) -> Self;
}
impl<T> const MyClone for Option<T>
where
T: ~const MyClone + ~const Destruct,
{
fn my_clone(&self) -> Self {
match self {
Some(x) => Some(x.my_clone()),
None => None,
}
}
}
impl const MyClone for i32 {
fn my_clone(&self) -> Self {
*self
}
}
#[lang = "destruct"]
pub trait Destruct {}
"#,
);
}