File tree 3 files changed +37
-20
lines changed
src/tools/rust-analyzer/crates/hir-ty/src
3 files changed +37
-20
lines changed Original file line number Diff line number Diff line change @@ -768,23 +768,21 @@ pub(crate) fn adt_datum_query(
768
768
phantom_data,
769
769
} ;
770
770
771
- // this slows down rust-analyzer by quite a bit unfortunately, so enabling this is currently not worth it
772
- let _variant_id_to_fields = |id : VariantId | {
771
+ let variant_id_to_fields = |id : VariantId | {
773
772
let variant_data = & id. variant_data ( db. upcast ( ) ) ;
774
- let fields = if variant_data. fields ( ) . is_empty ( ) {
773
+ let fields = if variant_data. fields ( ) . is_empty ( ) || bound_vars_subst . is_empty ( Interner ) {
775
774
vec ! [ ]
776
775
} else {
777
- let field_types = db . field_types ( id ) ;
778
- variant_data
779
- . fields ( )
780
- . iter ( )
781
- . map ( | ( idx , _ ) | field_types [ idx ] . clone ( ) . substitute ( Interner , & bound_vars_subst ) )
782
- . filter ( |it| !it . contains_unknown ( ) )
783
- . collect ( )
776
+ // HACK: provide full struct type info slows down rust-analyzer by quite a bit unfortunately,
777
+ // so we trick chalk into thinking that our struct impl Unsize
778
+ if let Some ( ty ) = bound_vars_subst . at ( Interner , 0 ) . ty ( Interner ) {
779
+ vec ! [ ty . clone ( ) ]
780
+ } else {
781
+ vec ! [ ]
782
+ }
784
783
} ;
785
784
rust_ir:: AdtVariantDatum { fields }
786
785
} ;
787
- let variant_id_to_fields = |_: VariantId | rust_ir:: AdtVariantDatum { fields : vec ! [ ] } ;
788
786
789
787
let ( kind, variants) = match adt_id {
790
788
hir_def:: AdtId :: StructId ( id) => {
Original file line number Diff line number Diff line change @@ -535,17 +535,15 @@ fn test() {
535
535
536
536
#[ test]
537
537
fn coerce_unsize_generic ( ) {
538
- check (
538
+ check_no_mismatches (
539
539
r#"
540
540
//- minicore: coerce_unsized
541
541
struct Foo<T> { t: T };
542
542
struct Bar<T>(Foo<T>);
543
543
544
544
fn test() {
545
545
let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] };
546
- //^^^^^^^^^^^^^^^^^^^^^ expected &'? Foo<[usize]>, got &'? Foo<[i32; 3]>
547
546
let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
548
- //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &'? Bar<[usize]>, got &'? Bar<[i32; 3]>
549
547
}
550
548
"# ,
551
549
) ;
@@ -957,3 +955,24 @@ fn f() {
957
955
"# ,
958
956
) ;
959
957
}
958
+
959
+ #[ test]
960
+ fn coerce_nested_unsized_struct ( ) {
961
+ check_types (
962
+ r#"
963
+ //- minicore: fn, coerce_unsized, dispatch_from_dyn, sized
964
+ use core::marker::Unsize;
965
+
966
+ struct Foo<T: ?Sized>(T);
967
+
968
+ fn need(_: &Foo<dyn Fn(i32) -> i32>) {
969
+ }
970
+
971
+ fn test() {
972
+ let callback = |x| x;
973
+ //^ i32
974
+ need(&Foo(callback));
975
+ }
976
+ "# ,
977
+ )
978
+ }
Original file line number Diff line number Diff line change @@ -4694,21 +4694,21 @@ fn f<T: Send, U>() {
4694
4694
Struct::<T>::IS_SEND;
4695
4695
//^^^^^^^^^^^^^^^^^^^^Yes
4696
4696
Struct::<U>::IS_SEND;
4697
- //^^^^^^^^^^^^^^^^^^^^Yes
4697
+ //^^^^^^^^^^^^^^^^^^^^{unknown}
4698
4698
Struct::<*const T>::IS_SEND;
4699
- //^^^^^^^^^^^^^^^^^^^^^^^^^^^Yes
4699
+ //^^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
4700
4700
Enum::<T>::IS_SEND;
4701
4701
//^^^^^^^^^^^^^^^^^^Yes
4702
4702
Enum::<U>::IS_SEND;
4703
- //^^^^^^^^^^^^^^^^^^Yes
4703
+ //^^^^^^^^^^^^^^^^^^{unknown}
4704
4704
Enum::<*const T>::IS_SEND;
4705
- //^^^^^^^^^^^^^^^^^^^^^^^^^Yes
4705
+ //^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
4706
4706
Union::<T>::IS_SEND;
4707
4707
//^^^^^^^^^^^^^^^^^^^Yes
4708
4708
Union::<U>::IS_SEND;
4709
- //^^^^^^^^^^^^^^^^^^^Yes
4709
+ //^^^^^^^^^^^^^^^^^^^{unknown}
4710
4710
Union::<*const T>::IS_SEND;
4711
- //^^^^^^^^^^^^^^^^^^^^^^^^^^Yes
4711
+ //^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
4712
4712
PhantomData::<T>::IS_SEND;
4713
4713
//^^^^^^^^^^^^^^^^^^^^^^^^^Yes
4714
4714
PhantomData::<U>::IS_SEND;
You can’t perform that action at this time.
0 commit comments