Merge pull request #20212 from ChayimFriedman2/dyn-hint

fix: Fixes for `dyn` inlay hint
This commit is contained in:
Shoyu Vanilla (Flint) 2025-07-10 04:57:57 +00:00 committed by GitHub
commit eede8f1f4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,8 +17,12 @@ pub(super) fn hints(
let parent = path.syntax().parent()?;
let range = match path {
Either::Left(path) => {
let paren =
parent.ancestors().take_while(|it| ast::ParenType::can_cast(it.kind())).last();
let paren = parent
.ancestors()
.take_while(|it| {
ast::ParenType::can_cast(it.kind()) || ast::ForType::can_cast(it.kind())
})
.last();
let parent = paren.as_ref().and_then(|it| it.parent()).unwrap_or(parent);
if ast::TypeBound::can_cast(parent.kind())
|| ast::TypeAnchor::can_cast(parent.kind())
@ -34,7 +38,7 @@ pub(super) fn hints(
return None;
}
sema.resolve_trait(&path.path()?)?;
paren.map_or_else(|| path.syntax().text_range(), |it| it.text_range())
path.syntax().text_range()
}
Either::Right(dyn_) => {
if dyn_.dyn_token().is_some() {
@ -89,7 +93,7 @@ fn foo(_: &T, _: for<'a> T) {}
impl T {}
// ^ dyn
impl T for (T) {}
// ^^^ dyn
// ^ dyn
impl T
"#,
);
@ -112,7 +116,7 @@ fn foo(
_: &mut (T + T)
// ^^^^^ dyn
_: *mut (T),
// ^^^ dyn
// ^ dyn
) {}
"#,
);
@ -136,4 +140,26 @@ fn foo(
"#]],
);
}
#[test]
fn hrtb_bound_does_not_add_dyn() {
check(
r#"
//- minicore: fn
fn test<F>(f: F) where F: for<'a> FnOnce(&'a i32) {}
// ^: Sized
"#,
);
}
#[test]
fn with_parentheses() {
check(
r#"
trait T {}
fn foo(v: &(T)) {}
// ^ dyn
"#,
);
}
}