nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: rust-analyzer/rust-analyzer
Pull request #11782 (2022-03-21 18:42:09)

fix: Fix flyimport showing functions in pattern position
bors r+


Patch:
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 6c8878a7bb..ee751f9f77 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -141,15 +141,18 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
         &ctx.sema,
     )?;
 
+    let path_kind = match ctx.path_kind() {
+        Some(kind) => Some(kind),
+        None if ctx.pattern_ctx.is_some() => Some(PathKind::Pat),
+        None => None,
+    };
     let ns_filter = |import: &LocatedImport| {
-        let path_kind = match ctx.path_kind() {
-            Some(kind) => kind,
-            None => {
-                return match import.original_item {
-                    ItemInNs::Macros(mac) => mac.is_fn_like(ctx.db),
-                    _ => true,
-                }
-            }
+        let path_kind = match path_kind {
+            Some(path_kind) => path_kind,
+            None => match import.original_item {
+                ItemInNs::Macros(mac) => return mac.is_fn_like(ctx.db),
+                _ => return true,
+            },
         };
         match (path_kind, import.original_item) {
             // Aren't handled in flyimport
diff --git a/crates/ide_db/src/imports/import_assets.rs b/crates/ide_db/src/imports/import_assets.rs
index 9a09c40ee6..3963d4d79a 100644
--- a/crates/ide_db/src/imports/import_assets.rs
+++ b/crates/ide_db/src/imports/import_assets.rs
@@ -66,7 +66,7 @@ pub struct FirstSegmentUnresolved {
 /// A name that will be used during item lookups.
 #[derive(Debug, Clone)]
 pub enum NameToImport {
-    /// Requires items with names that exactly match the given string, bool indicatse case-sensitivity.
+    /// Requires items with names that exactly match the given string, bool indicates case-sensitivity.
     Exact(String, bool),
     /// Requires items with names that case-insensitively contain all letters from the string,
     /// in the same order, but not necessary adjacent.


Test patch:
diff --git a/crates/ide_completion/src/tests/flyimport.rs b/crates/ide_completion/src/tests/flyimport.rs
index c996a5f01f..4a0fcf3442 100644
--- a/crates/ide_completion/src/tests/flyimport.rs
+++ b/crates/ide_completion/src/tests/flyimport.rs
@@ -1030,15 +1030,18 @@ fn flyimport_pattern() {
     check(
         r#"
 mod module {
-    pub struct Struct;
+    pub struct FooStruct {}
+    pub const FooConst: () = ();
+    pub fn foo_fun() {}
 }
 fn function() {
-    let Str$0
+    let foo$0
 }
 "#,
         expect![[r#"
-                st Struct (use module::Struct)
-            "#]],
+            ct FooConst (use module::FooConst)
+            st FooStruct (use module::FooStruct)
+        "#]],
     );
 }
Repository: rust-analyzer/rust-analyzer
Pull request #11931 (2022-04-07 18:05:07)

fix: flyimport: omit types when completing where-clause
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11918

bors r+


Patch:
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 2154a1b3cb..fb857aeccd 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -1,5 +1,5 @@
 //! See [`import_on_the_fly`].
-use hir::ItemInNs;
+use hir::{ItemInNs, ModuleDef};
 use ide_db::imports::{
     import_assets::{ImportAssets, ImportCandidate, LocatedImport},
     insert_use::ImportScope,
@@ -9,6 +9,7 @@ use syntax::{AstNode, SyntaxNode, T};
 
 use crate::{
     context::{CompletionContext, PathKind},
+    patterns::ImmediateLocation,
     render::{render_resolution_with_import, RenderContext},
 };
 
@@ -170,7 +171,13 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
             (PathKind::Pat, ItemInNs::Types(_)) => true,
             (PathKind::Pat, ItemInNs::Values(def)) => matches!(def, hir::ModuleDef::Const(_)),
 
-            (PathKind::Type, ItemInNs::Types(_)) => true,
+            (PathKind::Type, ItemInNs::Types(ty)) => {
+                if matches!(ctx.completion_location, Some(ImmediateLocation::TypeBound)) {
+                    matches!(ty, ModuleDef::Trait(_))
+                } else {
+                    true
+                }
+            }
             (PathKind::Type, ItemInNs::Values(_)) => false,
 
             (PathKind::Attr { .. }, ItemInNs::Macros(mac)) => mac.is_attr(ctx.db),


Test patch:
diff --git a/crates/ide_completion/src/tests/flyimport.rs b/crates/ide_completion/src/tests/flyimport.rs
index b47a710006..41e6cf7aee 100644
--- a/crates/ide_completion/src/tests/flyimport.rs
+++ b/crates/ide_completion/src/tests/flyimport.rs
@@ -1170,3 +1170,22 @@ struct Foo;
 "#,
     );
 }
+
+#[test]
+fn flyimport_in_type_bound_omits_types() {
+    check(
+        r#"
+mod module {
+    pub struct CompletemeStruct;
+    pub type CompletemeType = ();
+    pub enum CompletemeEnum {}
+    pub trait CompletemeTrait {}
+}
+
+fn f<T>() where T: Comp$0
+"#,
+        expect![[r#"
+            tt CompletemeTrait (use module::CompletemeTrait)
+        "#]],
+    );
+}
Repository: rust-analyzer/rust-analyzer
Pull request #4655 (2020-05-29 21:43:00)

Fix typo in docs/dev/lsp-extensions.md: automagiacally -> automagically
This may be a typo...


Patch:
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs
index 32c7c57cd6..2ee9adb164 100644
--- a/crates/ra_hir_ty/src/infer/coerce.rs
+++ b/crates/ra_hir_ty/src/infer/coerce.rs
@@ -45,7 +45,9 @@ impl<'a> InferenceContext<'a> {
                 self.coerce_merge_branch(&ptr_ty1, &ptr_ty2)
             } else {
                 mark::hit!(coerce_merge_fail_fallback);
-                ty1.clone()
+                // For incompatible types, we use the latter one as result
+                // to be better recovery for `if` without `else`.
+                ty2.clone()
             }
         }
     }
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 68a5df27e7..dbc95be387 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -154,7 +154,7 @@ fn main() {
 }
 ```
 
-`experimental/joinLines` yields (curly braces are automagiacally removed)
+`experimental/joinLines` yields (curly braces are automagically removed)
 
 ```rust
 fn main() {


Test patch:
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs
index 839491b9e2..f1db341604 100644
--- a/crates/ra_hir_ty/src/tests/simple.rs
+++ b/crates/ra_hir_ty/src/tests/simple.rs
@@ -957,7 +957,7 @@ fn main(foo: Foo) {
     51..107 'if tru...     }': ()
     54..58 'true': bool
     59..67 '{      }': ()
-    73..107 'if fal...     }': i32
+    73..107 'if fal...     }': ()
     76..81 'false': bool
     82..107 '{     ...     }': i32
     92..95 'foo': Foo
Repository: rust-analyzer/rust-analyzer
Pull request #8072 (2021-03-17 20:42:37)

Fix "unset `OUT_DIR`" diagnostic when using it in item position
"load out dirs from check" is enabled by default now, but better late than never I guess.

bors r+


Patch:
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index 81cf652b0d..d73f895b7d 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -1469,7 +1469,9 @@ impl ModCollector<'_, '_> {
                     )
                 })
             },
-            &mut |err| error = Some(err),
+            &mut |err| {
+                error.get_or_insert(err);
+            },
         ) {
             Ok(Ok(macro_call_id)) => {
                 self.def_collector.unexpanded_macros.push(MacroDirective {


Test patch:
diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs
index c22ef46fd6..6becd9ff1e 100644
--- a/crates/hir_def/src/nameres/tests/diagnostics.rs
+++ b/crates/hir_def/src/nameres/tests/diagnostics.rs
@@ -200,3 +200,20 @@ fn builtin_macro_fails_expansion() {
         "#,
     );
 }
+
+#[test]
+fn good_out_dir_diagnostic() {
+    check_diagnostics(
+        r#"
+        #[rustc_builtin_macro]
+        macro_rules! include { () => {} }
+        #[rustc_builtin_macro]
+        macro_rules! env { () => {} }
+        #[rustc_builtin_macro]
+        macro_rules! concat { () => {} }
+
+        include!(concat!(env!("OUT_DIR"), "/out.rs"));
+      //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `OUT_DIR` not set, enable "load out dirs from check" to fix
+        "#,
+    );
+}
Repository: rust-analyzer/rust-analyzer
Pull request #8078 (2021-03-18 00:29:56)

Support `#[cfg]` on all associated items
bors r+


Patch:
diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs
index e976e419eb..2c70b3bc0e 100644
--- a/crates/hir_def/src/data.rs
+++ b/crates/hir_def/src/data.rs
@@ -256,17 +256,17 @@ fn collect_items(
 
     let mut items = Vec::new();
     for item in assoc_items {
+        let attrs = item_tree.attrs(db, module.krate, ModItem::from(item).into());
+        if !attrs.is_cfg_enabled(&cfg_options) {
+            continue;
+        }
+
         match item {
             AssocItem::Function(id) => {
                 let item = &item_tree[id];
-                let attrs = item_tree.attrs(db, module.krate, ModItem::from(id).into());
-                if !attrs.is_cfg_enabled(&cfg_options) {
-                    continue;
-                }
                 let def = FunctionLoc { container, id: ItemTreeId::new(file_id, id) }.intern(db);
                 items.push((item.name.clone(), def.into()));
             }
-            // FIXME: cfg?
             AssocItem::Const(id) => {
                 let item = &item_tree[id];
                 let name = match item.name.clone() {


Test patch:
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index f5069eba51..bcc43ed700 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -2545,3 +2545,22 @@ fn test() {
         "#]],
     )
 }
+
+#[test]
+fn cfgd_out_assoc_items() {
+    check_types(
+        r#"
+struct S;
+
+impl S {
+    #[cfg(FALSE)]
+    const C: S = S;
+}
+
+fn f() {
+    S::C;
+  //^^^^ {unknown}
+}
+    "#,
+    )
+}