Skip to content

Commit 526fed2

Browse files
committed
Fix incorrect dyn hint in impl Trait for
Example --- ```rust trait T {} impl T for {} ``` **Before this PR** ```rust trait T {} impl T for {} // ^ dyn ``` **After this PR** ```rust trait T {} impl T for {} ```
1 parent be6975f commit 526fed2

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

crates/ide/src/inlay_hints/implied_dyn_trait.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl T {}
105105
// ^ dyn
106106
impl T for (T) {}
107107
// ^ dyn
108+
impl T for {}
108109
impl T
109110
"#,
110111
);

crates/syntax/src/ast/node_ext.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -447,24 +447,23 @@ impl ast::UseTreeList {
447447

448448
impl ast::Impl {
449449
pub fn self_ty(&self) -> Option<ast::Type> {
450-
match self.target() {
451-
(Some(t), None) | (_, Some(t)) => Some(t),
452-
_ => None,
453-
}
450+
self.target().1
454451
}
455452

456453
pub fn trait_(&self) -> Option<ast::Type> {
457-
match self.target() {
458-
(Some(t), Some(_)) => Some(t),
459-
_ => None,
460-
}
454+
self.target().0
461455
}
462456

463457
fn target(&self) -> (Option<ast::Type>, Option<ast::Type>) {
464-
let mut types = support::children(self.syntax());
465-
let first = types.next();
466-
let second = types.next();
467-
(first, second)
458+
let mut types = support::children(self.syntax()).peekable();
459+
let for_kw = self.for_token();
460+
let trait_ = types.next_if(|trait_: &ast::Type| {
461+
for_kw.is_some_and(|for_kw| {
462+
trait_.syntax().text_range().start() < for_kw.text_range().start()
463+
})
464+
});
465+
let self_ty = types.next();
466+
(trait_, self_ty)
468467
}
469468

470469
pub fn for_trait_name_ref(name_ref: &ast::NameRef) -> Option<ast::Impl> {

0 commit comments

Comments
 (0)