mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 19:23:50 +00:00
Make path start with a QualifiedPathType
This commit is contained in:
parent
609bdbc4dd
commit
8ad536f2d1
@ -52,18 +52,24 @@ pub(crate) fn into_to_qualified_from(acc: &mut Assists, ctx: &AssistContext<'_>)
|
||||
== FamousDefs(sema, scope.krate()).core_convert_Into()?
|
||||
{
|
||||
let type_call = sema.type_of_expr(&method_call.clone().into())?;
|
||||
let type_call_disp =
|
||||
type_call.adjusted().display_source_code(db, scope.module().into(), true).ok()?;
|
||||
let adjusted_tc = type_call.adjusted();
|
||||
|
||||
if adjusted_tc.is_unknown() && adjusted_tc.contains_unknown() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let qualified_from = format!(
|
||||
"<{}>::from({})",
|
||||
adjusted_tc.display_source_code(db, scope.module().into(), true).ok()?,
|
||||
receiver
|
||||
);
|
||||
|
||||
acc.add(
|
||||
AssistId("into_to_qualified_from", AssistKind::Generate),
|
||||
"Convert `into` to fully qualified `from`",
|
||||
nameref.syntax().text_range(),
|
||||
|edit| {
|
||||
edit.replace(
|
||||
method_call.syntax().text_range(),
|
||||
format!("{}::from({})", type_call_disp, receiver),
|
||||
);
|
||||
edit.replace(method_call.syntax().text_range(), qualified_from);
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -106,7 +112,7 @@ impl From<A> for B {
|
||||
|
||||
fn main() -> () {
|
||||
let a: A = A;
|
||||
let b: B = B::from(a);
|
||||
let b: B = <B>::from(a);
|
||||
}"#,
|
||||
)
|
||||
}
|
||||
@ -154,7 +160,7 @@ mod C {
|
||||
|
||||
fn main() -> () {
|
||||
let a: A = A;
|
||||
let b: B = B::from(a);
|
||||
let b: B = <B>::from(a);
|
||||
}"#,
|
||||
)
|
||||
}
|
||||
@ -198,7 +204,67 @@ mod C {
|
||||
|
||||
fn main() -> () {
|
||||
let a: A = A;
|
||||
let b: C::B = C::B::from(a);
|
||||
let b: C::B = <C::B>::from(a);
|
||||
}"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preceding_type_qualifier() {
|
||||
check_assist(
|
||||
into_to_qualified_from,
|
||||
r#"
|
||||
//- minicore: from
|
||||
impl From<(i32,i32)> for [i32;2] {
|
||||
fn from(value: (i32,i32)) -> Self {
|
||||
[value.0, value.1]
|
||||
}
|
||||
}
|
||||
|
||||
fn tuple_to_array() -> [i32; 2] {
|
||||
(0,1).in$0to()
|
||||
}"#,
|
||||
r#"
|
||||
impl From<(i32,i32)> for [i32;2] {
|
||||
fn from(value: (i32,i32)) -> Self {
|
||||
[value.0, value.1]
|
||||
}
|
||||
}
|
||||
|
||||
fn tuple_to_array() -> [i32; 2] {
|
||||
<[i32; 2]>::from((0,1))
|
||||
}"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn type_with_gens() {
|
||||
check_assist(
|
||||
into_to_qualified_from,
|
||||
r#"
|
||||
//- minicore: from
|
||||
struct StructA<Gen>(Gen);
|
||||
|
||||
impl From<i32> for StructA<i32> {
|
||||
fn from(value: i32) -> Self {
|
||||
StructA(value + 1)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> () {
|
||||
let a: StructA<i32> = 3.in$0to();
|
||||
}"#,
|
||||
r#"
|
||||
struct StructA<Gen>(Gen);
|
||||
|
||||
impl From<i32> for StructA<i32> {
|
||||
fn from(value: i32) -> Self {
|
||||
StructA(value + 1)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> () {
|
||||
let a: StructA<i32> = <StructA<i32>>::from(3);
|
||||
}"#,
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user