Auto merge of #17192 - roife:fix-issue-17179, r=lnicola
Fix source_range for INT_NUMBER in completion
fix #17179.
Previously r-a use `TextRange::empty(self.position.offset)` as `source_range` for `INT_NUMBER`, so the `text_edit` would always be an insertion, which results in #17179.
This PR changed it by using `text_range` of `original_token` (same as `IDENT`).
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index f1315f6..04ace38 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -1311,11 +1311,10 @@
bounds,
lifetime: match lifetime {
Some(it) => match it.bound_var(Interner) {
- Some(bound_var) => LifetimeData::BoundVar(BoundVar::new(
- DebruijnIndex::INNERMOST,
- bound_var.index,
- ))
- .intern(Interner),
+ Some(bound_var) => bound_var
+ .shifted_out_to(DebruijnIndex::new(2))
+ .map(|bound_var| LifetimeData::BoundVar(bound_var).intern(Interner))
+ .unwrap_or(it),
None => it,
},
None => static_lifetime(),
diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs
index 7a31887..18fc8af 100644
--- a/crates/hir-ty/src/tests/traits.rs
+++ b/crates/hir-ty/src/tests/traits.rs
@@ -4803,3 +4803,24 @@
"#,
);
}
+
+#[test]
+fn dyn_trait_with_lifetime_in_rpit() {
+ check_types(
+ r#"
+//- minicore: future
+pub struct Box<T> {}
+
+trait Trait {}
+
+pub async fn foo_async<'a>() -> Box<dyn Trait + 'a> {
+ Box {}
+}
+
+fn foo() {
+ foo_async();
+ //^^^^^^^^^^^impl Future<Output = Box<dyn Trait>> + ?Sized
+}
+"#,
+ )
+}