mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #20212 from ChayimFriedman2/dyn-hint
fix: Fixes for `dyn` inlay hint
This commit is contained in:
commit
eede8f1f4e
@ -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
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user