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_db/src/helpers.rs | 4 ++++ crates/ide_db/src/helpers/famous_defs_fixture.rs | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index 9992a92bd..66798ea3a 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs @@ -93,6 +93,10 @@ impl FamousDefs<'_, '_> { self.find_trait("core:convert:From") } + pub fn core_convert_Into(&self) -> Option { + self.find_trait("core:convert:Into") + } + pub fn core_option_Option(&self) -> Option { self.find_enum("core:option:Option") } diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs index d3464ae17..4d79e064e 100644 --- a/crates/ide_db/src/helpers/famous_defs_fixture.rs +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs @@ -14,6 +14,10 @@ pub mod convert { pub trait From { fn from(t: T) -> Self; } + + pub trait Into { + pub fn into(self) -> T; + } } pub mod default { @@ -120,7 +124,7 @@ pub mod option { pub mod prelude { pub use crate::{ cmp::Ord, - convert::From, + convert::{From, Into}, default::Default, iter::{IntoIterator, Iterator}, ops::{Fn, FnMut, FnOnce}, -- cgit v1.2.3