File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
src/tools/rust-analyzer/crates/hir-ty/src Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -590,9 +590,14 @@ impl<'a> TyLoweringContext<'a> {
590590 . resolve_trait ( ctx. ty_ctx ( ) . db , ctx. ty_ctx ( ) . resolver . krate ( ) ) ;
591591 let pointee_sized = LangItem :: PointeeSized
592592 . resolve_trait ( ctx. ty_ctx ( ) . db , ctx. ty_ctx ( ) . resolver . krate ( ) ) ;
593- if meta_sized. is_some_and ( |it| it == trait_ref. hir_trait_id ( ) ) {
593+ let destruct = LangItem :: Destruct
594+ . resolve_trait ( ctx. ty_ctx ( ) . db , ctx. ty_ctx ( ) . resolver . krate ( ) ) ;
595+ let hir_trait_id = trait_ref. hir_trait_id ( ) ;
596+ if meta_sized. is_some_and ( |it| it == hir_trait_id)
597+ || destruct. is_some_and ( |it| it == hir_trait_id)
598+ {
594599 // Ignore this bound
595- } else if pointee_sized. is_some_and ( |it| it == trait_ref . hir_trait_id ( ) ) {
600+ } else if pointee_sized. is_some_and ( |it| it == hir_trait_id) {
596601 // Regard this as `?Sized` bound
597602 ctx. ty_ctx ( ) . unsized_types . insert ( self_ty) ;
598603 } else {
Original file line number Diff line number Diff line change @@ -2349,3 +2349,37 @@ fn test() {
23492349 "# ] ] ,
23502350 ) ;
23512351}
2352+
2353+ #[ test]
2354+ fn rust_destruct_option_clone ( ) {
2355+ check_types (
2356+ r#"
2357+ //- minicore: option, drop
2358+ fn test(o: &Option<i32>) {
2359+ o.my_clone();
2360+ //^^^^^^^^^^^^ Option<i32>
2361+ }
2362+ pub trait MyClone: Sized {
2363+ fn my_clone(&self) -> Self;
2364+ }
2365+ impl<T> const MyClone for Option<T>
2366+ where
2367+ T: ~const MyClone + ~const Destruct,
2368+ {
2369+ fn my_clone(&self) -> Self {
2370+ match self {
2371+ Some(x) => Some(x.my_clone()),
2372+ None => None,
2373+ }
2374+ }
2375+ }
2376+ impl const MyClone for i32 {
2377+ fn my_clone(&self) -> Self {
2378+ *self
2379+ }
2380+ }
2381+ #[lang = "destruct"]
2382+ pub trait Destruct {}
2383+ "# ,
2384+ ) ;
2385+ }
You can’t perform that action at this time.
0 commit comments