mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Merge pull request #19173 from rust-lang/revert-19122-master
Revert "pass struct fields to chalk"
This commit is contained in:
		
						commit
						957d3450da
					
				@ -768,21 +768,23 @@ pub(crate) fn adt_datum_query(
 | 
			
		||||
        phantom_data,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let variant_id_to_fields = |id: VariantId| {
 | 
			
		||||
    // 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_data = &id.variant_data(db.upcast());
 | 
			
		||||
        let fields = if variant_data.fields().is_empty() || bound_vars_subst.is_empty(Interner) {
 | 
			
		||||
        let fields = if variant_data.fields().is_empty() {
 | 
			
		||||
            vec![]
 | 
			
		||||
        } else {
 | 
			
		||||
            // 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) {
 | 
			
		||||
                vec![ty.clone()]
 | 
			
		||||
            } else {
 | 
			
		||||
                vec![]
 | 
			
		||||
            }
 | 
			
		||||
            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()
 | 
			
		||||
        };
 | 
			
		||||
        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) => {
 | 
			
		||||
 | 
			
		||||
@ -535,7 +535,7 @@ fn test() {
 | 
			
		||||
 | 
			
		||||
#[test]
 | 
			
		||||
fn coerce_unsize_generic() {
 | 
			
		||||
    check_no_mismatches(
 | 
			
		||||
    check(
 | 
			
		||||
        r#"
 | 
			
		||||
//- minicore: coerce_unsized
 | 
			
		||||
struct Foo<T> { t: T };
 | 
			
		||||
@ -543,7 +543,9 @@ struct Bar<T>(Foo<T>);
 | 
			
		||||
 | 
			
		||||
fn test() {
 | 
			
		||||
    let _: &Foo<[usize]> = &Foo { t: [1, 2, 3] };
 | 
			
		||||
                         //^^^^^^^^^^^^^^^^^^^^^ expected &'? Foo<[usize]>, got &'? Foo<[i32; 3]>
 | 
			
		||||
    let _: &Bar<[usize]> = &Bar(Foo { t: [1, 2, 3] });
 | 
			
		||||
                         //^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &'? Bar<[usize]>, got &'? Bar<[i32; 3]>
 | 
			
		||||
}
 | 
			
		||||
"#,
 | 
			
		||||
    );
 | 
			
		||||
@ -955,24 +957,3 @@ 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));
 | 
			
		||||
}
 | 
			
		||||
"#,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4694,21 +4694,21 @@ fn f<T: Send, U>() {
 | 
			
		||||
    Struct::<T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Struct::<U>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^{unknown}
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Struct::<*const T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Enum::<T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Enum::<U>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^{unknown}
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Enum::<*const T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Union::<T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Union::<U>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^{unknown}
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    Union::<*const T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^^{unknown}
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    PhantomData::<T>::IS_SEND;
 | 
			
		||||
  //^^^^^^^^^^^^^^^^^^^^^^^^^Yes
 | 
			
		||||
    PhantomData::<U>::IS_SEND;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user