From ee0384901784b2cbe8d62f259f8598cc0fc7d306 Mon Sep 17 00:00:00 2001 From: Graeme Coupar Date: Fri, 2 Apr 2021 14:00:56 +0100 Subject: Convert Into to From assist This adds a "Convert Into to From" assist, useful since clippy has recently started adding lints on every `Into`. It covers converting the signature, and converting any `self`/`Self` references within the body to the correct types. It does assume that every instance of `Into` can be converted to a `From`, which I _think_ is the case now. Let me know if there's something I'm not thinking of and I can try and make it smarter. --- crates/ide_assists/src/tests/generated.rs | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'crates/ide_assists/src/tests') diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 03b7fb366..27a22ca10 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs @@ -205,6 +205,38 @@ const _: i32 = 0b1010; ) } +#[test] +fn doctest_convert_into_to_from() { + check_doc_test( + "convert_into_to_from", + r#####" +//- /lib.rs crate:core +pub mod convert { pub trait Into { pub fn into(self) -> T; } } +//- /lib.rs crate:main deps:core +use core::convert::Into; +impl $0Into for usize { + fn into(self) -> Thing { + Thing { + b: self.to_string(), + a: self + } + } +} +"#####, + r#####" +use core::convert::Into; +impl From for Thing { + fn from(val: usize) -> Self { + Thing { + b: val.to_string(), + a: val + } + } +} +"#####, + ) +} + #[test] fn doctest_convert_iter_for_each_to_for() { check_doc_test( -- cgit v1.2.3