about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Richey <davidrichey@fb.com>2024-08-18 15:09:41 -0500
committerDavid Richey <davidrichey@fb.com>2024-08-18 15:12:01 -0500
commit74db4d309a99c632dfb7f38d90bfcb14d4e62d87 (patch)
treead36c7cf41a617f638bd07701e9a3eebe1b8e791
parent51e3775fafb4187e3d3d61b2babdf92c77ae1020 (diff)
downloadrust-74db4d309a99c632dfb7f38d90bfcb14d4e62d87.tar.gz
rust-74db4d309a99c632dfb7f38d90bfcb14d4e62d87.zip
Include generics when lowering extern type
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lower.rs10
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs16
2 files changed, 21 insertions, 5 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
index 79b096068da..5824c59c5a5 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
@@ -1976,13 +1976,13 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
         .with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
         .with_type_param_mode(ParamLoweringMode::Variable);
     let type_alias_data = db.type_alias_data(t);
-    if type_alias_data.is_extern {
-        Binders::empty(Interner, TyKind::Foreign(crate::to_foreign_def_id(t)).intern(Interner))
+    let inner = if type_alias_data.is_extern {
+        TyKind::Foreign(crate::to_foreign_def_id(t)).intern(Interner)
     } else {
         let type_ref = &type_alias_data.type_ref;
-        let inner = ctx.lower_ty(type_ref.as_deref().unwrap_or(&TypeRef::Error));
-        make_binders(db, &generics, inner)
-    }
+        ctx.lower_ty(type_ref.as_deref().unwrap_or(&TypeRef::Error))
+    };
+    make_binders(db, &generics, inner)
 }
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
index 01862aa2a37..d6e034b0184 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
@@ -2195,3 +2195,19 @@ impl<'a, T: Deref<Target = impl Trait>> Struct<'a, T> {
         "#]],
     );
 }
+
+#[test]
+fn issue_17767() {
+    check_infer(
+        r#"
+extern "C" {
+    type Foo<T>;
+}
+
+fn f() -> Foo {}
+"#,
+        expect![[r#"
+            47..49 '{}': Foo
+        "#]],
+    );
+}