Skip to content

Commit 78b7390

Browse files
authored
Merge pull request #19173 from rust-lang/revert-19122-master
Revert "pass struct fields to chalk"
2 parents 501471a + 3457775 commit 78b7390

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -768,21 +768,23 @@ pub(crate) fn adt_datum_query(
768768
phantom_data,
769769
};
770770

771-
let variant_id_to_fields = |id: VariantId| {
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| {
772773
let variant_data = &id.variant_data(db.upcast());
773-
let fields = if variant_data.fields().is_empty() || bound_vars_subst.is_empty(Interner) {
774+
let fields = if variant_data.fields().is_empty() {
774775
vec![]
775776
} else {
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-
}
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()
783784
};
784785
rust_ir::AdtVariantDatum { fields }
785786
};
787+
let variant_id_to_fields = |_: VariantId| rust_ir::AdtVariantDatum { fields: vec![] };
786788

787789
let (kind, variants) = match adt_id {
788790
hir_def::AdtId::StructId(id) => {

src/tools/rust-analyzer/crates/hir-ty/src/tests/coercion.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,17 @@ fn test() {
535535

536536
#[test]
537537
fn coerce_unsize_generic() {
538-
check_no_mismatches(
538+
check(
539539
r#"
540540
//- minicore: coerce_unsized
541541
struct Foo<T> { t: T };
542542
struct Bar<T>(Foo<T>);
543543
544544
fn test() {
545545
let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] };
546+
//^^^^^^^^^^^^^^^^^^^^^ expected &'? Foo<[usize]>, got &'? Foo<[i32; 3]>
546547
let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
548+
//^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &'? Bar<[usize]>, got &'? Bar<[i32; 3]>
547549
}
548550
"#,
549551
);
@@ -955,24 +957,3 @@ fn f() {
955957
"#,
956958
);
957959
}
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-
}

src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4694,21 +4694,21 @@ fn f<T: Send, U>() {
46944694
Struct::<T>::IS_SEND;
46954695
//^^^^^^^^^^^^^^^^^^^^Yes
46964696
Struct::<U>::IS_SEND;
4697-
//^^^^^^^^^^^^^^^^^^^^{unknown}
4697+
//^^^^^^^^^^^^^^^^^^^^Yes
46984698
Struct::<*const T>::IS_SEND;
4699-
//^^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
4699+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^Yes
47004700
Enum::<T>::IS_SEND;
47014701
//^^^^^^^^^^^^^^^^^^Yes
47024702
Enum::<U>::IS_SEND;
4703-
//^^^^^^^^^^^^^^^^^^{unknown}
4703+
//^^^^^^^^^^^^^^^^^^Yes
47044704
Enum::<*const T>::IS_SEND;
4705-
//^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
4705+
//^^^^^^^^^^^^^^^^^^^^^^^^^Yes
47064706
Union::<T>::IS_SEND;
47074707
//^^^^^^^^^^^^^^^^^^^Yes
47084708
Union::<U>::IS_SEND;
4709-
//^^^^^^^^^^^^^^^^^^^{unknown}
4709+
//^^^^^^^^^^^^^^^^^^^Yes
47104710
Union::<*const T>::IS_SEND;
4711-
//^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
4711+
//^^^^^^^^^^^^^^^^^^^^^^^^^^Yes
47124712
PhantomData::<T>::IS_SEND;
47134713
//^^^^^^^^^^^^^^^^^^^^^^^^^Yes
47144714
PhantomData::<U>::IS_SEND;

0 commit comments

Comments
 (0)