From e106857e80d1ea304b00b5ff8a3294ca9bacd959 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 7 Oct 2020 12:13:32 +0200 Subject: [PATCH] Shorten iterator hints for std::iter iterators behind references --- crates/assists/src/utils.rs | 2 +- crates/ide/src/inlay_hints.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 92b3c3b009b..c074b8d02f9 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs @@ -308,7 +308,7 @@ fn next(&mut self) -> Option { } } } - pub(crate) mod collect { + pub(crate) mod collect { pub trait IntoIterator { type Item; } diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 279d025417c..7540f56a4b1 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -211,7 +211,9 @@ fn hint_iterator( ty: &Type, ) -> Option { let db = sema.db; - let strukt = ty.as_adt()?; + let strukt = std::iter::successors(Some(ty.clone()), |ty| ty.remove_ref()) + .last() + .and_then(|strukt| strukt.as_adt())?; let krate = strukt.krate(db)?; if krate.declaration_name(db).as_deref() != Some("core") { return None; @@ -1169,7 +1171,7 @@ fn main() { InlayHint { range: 175..225, kind: ChainingHint, - label: "&mut Take<&mut MyIter>", + label: "impl Iterator", }, InlayHint { range: 175..207,