-
Notifications
You must be signed in to change notification settings - Fork 1.8k
pass struct fields to chalk #19122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pass struct fields to chalk #19122
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -768,23 +768,21 @@ pub(crate) fn adt_datum_query( | |
phantom_data, | ||
}; | ||
|
||
// this slows down rust-analyzer by quite a bit unfortunately, so enabling this is currently not worth it | ||
let _variant_id_to_fields = |id: VariantId| { | ||
let variant_id_to_fields = |id: VariantId| { | ||
let variant_data = &id.variant_data(db.upcast()); | ||
let fields = if variant_data.fields().is_empty() { | ||
let fields = if variant_data.fields().is_empty() || bound_vars_subst.is_empty(Interner) { | ||
vec![] | ||
} else { | ||
let field_types = db.field_types(id); | ||
variant_data | ||
.fields() | ||
.iter() | ||
.map(|(idx, _)| field_types[idx].clone().substitute(Interner, &bound_vars_subst)) | ||
.filter(|it| !it.contains_unknown()) | ||
.collect() | ||
// HACK: provide full struct type info slows down rust-analyzer by quite a bit unfortunately, | ||
// so we trick chalk into thinking that our struct impl Unsize | ||
if let Some(ty) = bound_vars_subst.at(Interner, 0).ty(Interner) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the first bound var in this context? (has been a while since I touched this here) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the first generic of this struct struct Foo<T, U, V>
//^ this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically this is make chalk believe every struct with generic type is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this could cause other issues, also wouldn't this only work out where the first supplied parameter type is actually unsizable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe, but since other tests passed, I guess it's fine so far
Yes but I believe r-a and chalk already handled that. |
||
vec![ty.clone()] | ||
} else { | ||
vec![] | ||
} | ||
}; | ||
rust_ir::AdtVariantDatum { fields } | ||
}; | ||
let variant_id_to_fields = |_: VariantId| rust_ir::AdtVariantDatum { fields: vec![] }; | ||
|
||
let (kind, variants) = match adt_id { | ||
hir_def::AdtId::StructId(id) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -536,17 +536,15 @@ fn test() { | |
|
||
#[test] | ||
fn coerce_unsize_generic() { | ||
check( | ||
check_no_mismatches( | ||
r#" | ||
//- minicore: coerce_unsized | ||
struct Foo<T> { t: T }; | ||
struct Bar<T>(Foo<T>); | ||
|
||
fn test() { | ||
let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] }; | ||
//^^^^^^^^^^^^^^^^^^^^^ expected &'? Foo<[usize]>, got &'? Foo<[i32; 3]> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case is effectively the same with the added one, just different kind of coerce unsized |
||
let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] }); | ||
//^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &'? Bar<[usize]>, got &'? Bar<[i32; 3]> | ||
} | ||
"#, | ||
); | ||
|
@@ -958,3 +956,24 @@ fn f() { | |
"#, | ||
); | ||
} | ||
|
||
#[test] | ||
fn coerce_nested_unsized_struct() { | ||
check_types( | ||
r#" | ||
//- minicore: fn, coerce_unsized, dispatch_from_dyn, sized | ||
use core::marker::Unsize; | ||
|
||
struct Foo<T: ?Sized>(T); | ||
|
||
fn need(_: &Foo<dyn Fn(i32) -> i32>) { | ||
} | ||
|
||
fn test() { | ||
let callback = |x| x; | ||
//^ i32 | ||
need(&Foo(callback)); | ||
} | ||
"#, | ||
) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.