mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Fix data_constructor
ignoring generics for struct
This commit is contained in:
parent
a55e8bf09c
commit
0f6842700f
3 changed files with 19 additions and 5 deletions
|
@ -329,7 +329,7 @@ pub fn term_search<DB: HirDatabase>(ctx: &TermSearchCtx<'_, DB>) -> Vec<Expr> {
|
|||
while should_continue() {
|
||||
lookup.new_round();
|
||||
|
||||
solutions.extend(tactics::type_constructor(ctx, &defs, &mut lookup, should_continue));
|
||||
solutions.extend(tactics::data_constructor(ctx, &defs, &mut lookup, should_continue));
|
||||
solutions.extend(tactics::free_function(ctx, &defs, &mut lookup, should_continue));
|
||||
solutions.extend(tactics::impl_method(ctx, &defs, &mut lookup, should_continue));
|
||||
solutions.extend(tactics::struct_projection(ctx, &defs, &mut lookup, should_continue));
|
||||
|
|
|
@ -87,9 +87,9 @@ pub(super) fn trivial<'a, DB: HirDatabase>(
|
|||
})
|
||||
}
|
||||
|
||||
/// # Type constructor tactic
|
||||
/// # Data constructor tactic
|
||||
///
|
||||
/// Attempts different type constructors for enums and structs in scope
|
||||
/// Attempts different data constructors for enums and structs in scope
|
||||
///
|
||||
/// Updates lookup by new types reached and returns iterator that yields
|
||||
/// elements that unify with `goal`.
|
||||
|
@ -99,7 +99,7 @@ pub(super) fn trivial<'a, DB: HirDatabase>(
|
|||
/// * `defs` - Set of items in scope at term search target location
|
||||
/// * `lookup` - Lookup table for types
|
||||
/// * `should_continue` - Function that indicates when to stop iterating
|
||||
pub(super) fn type_constructor<'a, DB: HirDatabase>(
|
||||
pub(super) fn data_constructor<'a, DB: HirDatabase>(
|
||||
ctx: &'a TermSearchCtx<'a, DB>,
|
||||
defs: &'a FxHashSet<ScopeDef>,
|
||||
lookup: &'a mut LookupTable,
|
||||
|
@ -308,7 +308,9 @@ pub(super) fn type_constructor<'a, DB: HirDatabase>(
|
|||
// Early exit if some param cannot be filled from lookup
|
||||
let param_exprs: Vec<Vec<Expr>> = fields
|
||||
.into_iter()
|
||||
.map(|field| lookup.find(db, &field.ty(db)))
|
||||
.map(|field| {
|
||||
lookup.find(db, &field.ty_with_args(db, generics.iter().cloned()))
|
||||
})
|
||||
.collect::<Option<_>>()?;
|
||||
|
||||
// Note that we need special case for 0 param constructors because of multi cartesian
|
||||
|
|
|
@ -278,4 +278,16 @@ fn f() { let a = 1; let b = 0.0; let c: (i32, (i32, f64)) = todo$0!(); }"#,
|
|||
r#"fn f() { let a = 1; let b = 0.0; let c: (i32, (i32, f64)) = (a, (a, b)); }"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_struct_with_generics() {
|
||||
check_assist(
|
||||
term_search,
|
||||
r#"//- minicore: todo, unimplemented
|
||||
struct Foo<T>(T);
|
||||
fn f() { let a = 1; let b: Foo<i32> = todo$0!(); }"#,
|
||||
r#"struct Foo<T>(T);
|
||||
fn f() { let a = 1; let b: Foo<i32> = Foo(a); }"#,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue