Allow adding partially resolved types
This commit is contained in:
parent
e1099aaa57
commit
03291db801
@ -567,7 +567,27 @@ impl HirDisplay for Ty {
|
|||||||
};
|
};
|
||||||
if !parameters_to_write.is_empty() {
|
if !parameters_to_write.is_empty() {
|
||||||
write!(f, "<")?;
|
write!(f, "<")?;
|
||||||
|
|
||||||
|
if f.display_target.is_source_code() {
|
||||||
|
let mut first = true;
|
||||||
|
for generic_arg in parameters_to_write {
|
||||||
|
if !first {
|
||||||
|
write!(f, ", ")?;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
if generic_arg.ty(Interner).map(|ty| ty.kind(Interner))
|
||||||
|
== Some(&TyKind::Error)
|
||||||
|
{
|
||||||
|
write!(f, "_")?;
|
||||||
|
} else {
|
||||||
|
generic_arg.hir_fmt(f)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
f.write_joined(parameters_to_write, ", ")?;
|
f.write_joined(parameters_to_write, ", ")?;
|
||||||
|
}
|
||||||
|
|
||||||
write!(f, ">")?;
|
write!(f, ">")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio
|
|||||||
}
|
}
|
||||||
.adjusted();
|
.adjusted();
|
||||||
|
|
||||||
// Unresolved or unnameable types can't be annotated
|
// Fully unresolved or unnameable types can't be annotated
|
||||||
if ty.contains_unknown() || ty.is_closure() {
|
if (ty.contains_unknown() && ty.type_arguments().count() == 0) || ty.is_closure() {
|
||||||
cov_mark::hit!(add_explicit_type_not_applicable_if_ty_not_inferred);
|
cov_mark::hit!(add_explicit_type_not_applicable_if_ty_not_inferred);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@ -139,11 +139,34 @@ fn f() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_explicit_type_not_applicable_unresolved() {
|
fn add_explicit_type_not_applicable_for_fully_unresolved() {
|
||||||
cov_mark::check!(add_explicit_type_not_applicable_if_ty_not_inferred);
|
cov_mark::check!(add_explicit_type_not_applicable_if_ty_not_inferred);
|
||||||
check_assist_not_applicable(add_explicit_type, r#"fn f() { let a$0 = None; }"#);
|
check_assist_not_applicable(add_explicit_type, r#"fn f() { let a$0 = None; }"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_explicit_type_applicable_for_partially_unresolved() {
|
||||||
|
check_assist(
|
||||||
|
add_explicit_type,
|
||||||
|
r#"
|
||||||
|
struct Vec<T, V> { t: T, v: V }
|
||||||
|
impl<T> Vec<T, Vec<ZZZ, i32>> {
|
||||||
|
fn new() -> Self {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn f() { let a$0 = Vec::new(); }"#,
|
||||||
|
r#"
|
||||||
|
struct Vec<T, V> { t: T, v: V }
|
||||||
|
impl<T> Vec<T, Vec<ZZZ, i32>> {
|
||||||
|
fn new() -> Self {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn f() { let a: Vec<_, Vec<_, i32>> = Vec::new(); }"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_explicit_type_not_applicable_closure_expr() {
|
fn add_explicit_type_not_applicable_closure_expr() {
|
||||||
check_assist_not_applicable(add_explicit_type, r#"fn f() { let a$0 = || {}; }"#);
|
check_assist_not_applicable(add_explicit_type, r#"fn f() { let a$0 = || {}; }"#);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user