nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: zkat/miette
Pull request #159 (2022-04-23 02:14:26)

fix(graphical): fix issue with duplicate labels when span len is 0
Fixes: https://github.com/zkat/miette/issues/130


Patch:
diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs
index fd1000e..377922f 100644
--- a/src/handlers/graphical.rs
+++ b/src/handlers/graphical.rs
@@ -776,12 +776,13 @@ impl Line {
     }
 
     fn span_applies(&self, span: &FancySpan) -> bool {
+        let spanlen = if span.len() == 0 { 1 } else { span.len() };
         // Span starts in this line
         (span.offset() >= self.offset && span.offset() < self.offset + self.length)
         // Span passes through this line
-        || (span.offset() < self.offset && span.offset() + span.len() > self.offset + self.length) //todo
+        || (span.offset() < self.offset && span.offset() + spanlen > self.offset + self.length) //todo
         // Span ends on this line
-        || (span.offset() + span.len() > self.offset && span.offset() + span.len() <= self.offset + self.length)
+        || (span.offset() + spanlen > self.offset && span.offset() + spanlen <= self.offset + self.length)
     }
 
     // A 'flyby' is a multi-line span that technically covers this line, but


Test patch:
diff --git a/tests/graphical.rs b/tests/graphical.rs
index 53c7d1d..594b3f4 100644
--- a/tests/graphical.rs
+++ b/tests/graphical.rs
@@ -881,3 +881,35 @@ Error: oops::my::bad
     assert_eq!(expected, out);
     Ok(())
 }
+
+#[test]
+fn zero_length_eol_span() {
+    #[derive(Error, Debug, Diagnostic)]
+    #[error("oops!")]
+    #[diagnostic(severity(Error))]
+    struct MyBad {
+        #[source_code]
+        src: NamedSource,
+        #[label("This bit here")]
+        bad_bit: SourceSpan,
+    }
+    let err = MyBad {
+        src: NamedSource::new("issue", "this is the first line\nthis is the second line"),
+        bad_bit: (23, 0).into(),
+    };
+    let out = fmt_report(err.into());
+    println!("Error: {}", out);
+
+    let expected = r#"
+  × oops!
+   ╭─[issue:1:1]
+ 1 │ this is the first line
+ 2 │ this is the second line
+   · ▲
+   · ╰── This bit here
+   ╰────
+"#
+    .to_string();
+
+    assert_eq!(expected, out);
+}
Repository: zkat/miette
Pull request #183 (2022-07-09 01:22:44)

fix(graphical): handle an empty source
In some cases the source can be completely empty -- handle that in a reasonable fashion.


Patch:
diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs
index b0ab478..765a1d2 100644
--- a/src/handlers/graphical.rs
+++ b/src/handlers/graphical.rs
@@ -379,8 +379,9 @@ impl GraphicalReportHandler {
         // numbers need!
         let linum_width = lines[..]
             .last()
-            .expect("get_lines should always return at least one line?")
-            .line_number
+            .map(|line| line.line_number)
+            // It's possible for the source to be an empty string.
+            .unwrap_or(0)
             .to_string()
             .len();
 
@@ -402,7 +403,7 @@ impl GraphicalReportHandler {
                 contents.line() + 1,
                 contents.column() + 1
             )?;
-        } else if lines.len() == 1 {
+        } else if lines.len() <= 1 {
             writeln!(f, "{}", self.theme.characters.hbar.to_string().repeat(3))?;
         } else {
             writeln!(f, "[{}:{}]", contents.line() + 1, contents.column() + 1)?;


Test patch:
diff --git a/tests/graphical.rs b/tests/graphical.rs
index 594b3f4..2c486b9 100644
--- a/tests/graphical.rs
+++ b/tests/graphical.rs
@@ -34,6 +34,39 @@ fn fmt_report(diag: Report) -> String {
     out
 }
 
+#[test]
+fn empty_source() -> Result<(), MietteError> {
+    #[derive(Debug, Diagnostic, Error)]
+    #[error("oops!")]
+    #[diagnostic(code(oops::my::bad), help("try doing it better next time?"))]
+    struct MyBad {
+        #[source_code]
+        src: NamedSource,
+        #[label("this bit here")]
+        highlight: SourceSpan,
+    }
+
+    let src = "".to_string();
+    let err = MyBad {
+        src: NamedSource::new("bad_file.rs", src),
+        highlight: (0, 0).into(),
+    };
+    let out = fmt_report(err.into());
+    println!("Error: {}", out);
+    // For an empty string, the label cannot be rendered.
+    let expected = r#"oops::my::bad
+
+  × oops!
+   ╭─[bad_file.rs:1:1]
+   ╰────
+  help: try doing it better next time?
+"#
+    .trim_start()
+    .to_string();
+    assert_eq!(expected, out);
+    Ok(())
+}
+
 #[test]
 fn single_line_with_wide_char() -> Result<(), MietteError> {
     #[derive(Debug, Diagnostic, Error)]
Repository: rust-lang/rust-analyzer
Pull request #13652 (2022-11-20 08:50:34)

hir-expand: fix compile_error! expansion not unquoting strings
expanding `compile_error!` would not properly unquote strings, leading to quite ugly diagnostic messages:

![image](https://user-images.githubusercontent.com/5489149/202893481-2486ede8-c79a-4972-9713-416d6a704064.png)

this fixes it, using the conveniently placed `unquote_str` function, which now makes errors look like:

![image](https://user-images.githubusercontent.com/5489149/202893466-0763efad-9240-4d55-80a6-6c62000d5d2b.png)

additionally, using `unquote_str` has the cool side-effect of *also* handling raw strings, so this fixes a fixme too! 



Patch:
diff --git a/crates/hir-expand/src/builtin_fn_macro.rs b/crates/hir-expand/src/builtin_fn_macro.rs
index 7b19518e25..985954d44e 100644
--- a/crates/hir-expand/src/builtin_fn_macro.rs
+++ b/crates/hir-expand/src/builtin_fn_macro.rs
@@ -379,15 +379,10 @@ fn compile_error_expand(
     tt: &tt::Subtree,
 ) -> ExpandResult<ExpandedEager> {
     let err = match &*tt.token_trees {
-        [tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => {
-            let text = it.text.as_str();
-            if text.starts_with('"') && text.ends_with('"') {
-                // FIXME: does not handle raw strings
-                ExpandError::Other(text[1..text.len() - 1].into())
-            } else {
-                ExpandError::Other("`compile_error!` argument must be a string".into())
-            }
-        }
+        [tt::TokenTree::Leaf(tt::Leaf::Literal(it))] => match unquote_str(it) {
+            Some(unquoted) => ExpandError::Other(unquoted.into()),
+            None => ExpandError::Other("`compile_error!` argument must be a string".into()),
+        },
         _ => ExpandError::Other("`compile_error!` argument must be a string".into()),
     };
 


Test patch:
diff --git a/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs b/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
index c04cd16519..bb45266725 100644
--- a/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
+++ b/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs
@@ -163,7 +163,8 @@ macro_rules! compile_error {
 }
 
 // This expands to nothing (since it's in item position), but emits an error.
-compile_error!("error!");
+compile_error!("error, with an escaped quote: \"");
+compile_error!(r"this is a raw string");
 "#,
         expect![[r##"
 #[rustc_builtin_macro]
@@ -172,7 +173,8 @@ macro_rules! compile_error {
     ($msg:expr,) => ({ /* compiler built-in */ })
 }
 
-/* error: error! */
+/* error: error, with an escaped quote: " */
+/* error: this is a raw string */
 "##]],
     );
 }
Repository: rust-lang/rust-analyzer
Pull request #13690 (2022-11-28 23:33:46)

feat: Implement vararg parameter type inference
This PR implements the "collection" of the `va_list` type into the function parameter types list.


Patch:
diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs
index 2679a1c360..259fe1327f 100644
--- a/crates/hir-expand/src/name.rs
+++ b/crates/hir-expand/src/name.rs
@@ -419,6 +419,7 @@ pub mod known {
         shr,
         sub_assign,
         sub,
+        va_list
     );
 
     // self/Self cannot be used as an identifier
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 0b3c23f574..112eb5bd84 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -537,8 +537,20 @@ impl<'a> InferenceContext<'a> {
         let data = self.db.function_data(func);
         let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver)
             .with_impl_trait_mode(ImplTraitLoweringMode::Param);
-        let param_tys =
+        let mut param_tys =
             data.params.iter().map(|(_, type_ref)| ctx.lower_ty(type_ref)).collect::<Vec<_>>();
+        // Check if function contains a va_list, if it does then we append it to the parameter types
+        // that are collected from the function data
+        if data.is_varargs() {
+            let va_list_ty = match self.resolve_va_list() {
+                Some(va_list) => TyBuilder::adt(self.db, va_list)
+                    .fill_with_defaults(self.db, || self.table.new_type_var())
+                    .build(),
+                None => self.err_ty(),
+            };
+
+            param_tys.push(va_list_ty)
+        }
         for (ty, pat) in param_tys.into_iter().zip(self.body.params.iter()) {
             let ty = self.insert_type_vars(ty);
             let ty = self.normalize_associated_types_in(ty);
@@ -983,6 +995,11 @@ impl<'a> InferenceContext<'a> {
         let trait_ = self.resolve_ops_index()?;
         self.db.trait_data(trait_).associated_type_by_name(&name![Output])
     }
+
+    fn resolve_va_list(&self) -> Option<AdtId> {
+        let struct_ = self.resolve_lang_item(name![va_list])?.as_struct()?;
+        Some(struct_.into())
+    }
 }
 
 /// When inferring an expression, we propagate downward whatever type hint we


Test patch:
diff --git a/crates/hir-ty/src/tests/patterns.rs b/crates/hir-ty/src/tests/patterns.rs
index 74de33117e..9333e26935 100644
--- a/crates/hir-ty/src/tests/patterns.rs
+++ b/crates/hir-ty/src/tests/patterns.rs
@@ -1080,3 +1080,15 @@ fn my_fn(#[cfg(feature = "feature")] u8: u8, u32: u32) {}
 "#,
     );
 }
+
+#[test]
+fn var_args() {
+    check_types(
+        r#"
+#[lang = "va_list"]
+pub struct VaListImpl<'f>;
+fn my_fn(foo: ...) {}
+       //^^^ VaListImpl
+"#,
+    );
+}
Repository: rust-lang/rust-analyzer
Pull request #13774 (2022-12-14 13:00:00)

fix: resolve all inference vars in `InferenceResult::assoc_resolutions`
I think this fixes '#13773, ~but still haven't found repro. I'll try finding one so we can have a regression test~.

We should resolve every inference variable in `InferenceResult` after inference is done. We started recording `Substitution`s for each resolved associated items in #13725, but failed to do so which causes crash when analyzing source in IDE layer.

lowr: (deliberately not linking to #13773 so we can have OP confirm it's fixed before closing the issue)
Veykril: @bors r+
bors: :pushpin: Commit a4fc84a9e33cee4a5340db8dc5a236e402eff32d has been approved by `Veykril`

It is now in the [queue](https://bors.rust-lang.org/homu/queue/rust-analyzer) for this repository.

<!-- @bors r=Veykril a4fc84a9e33cee4a5340db8dc5a236e402eff32d -->
<!-- homu: {"type":"Approved","sha":"a4fc84a9e33cee4a5340db8dc5a236e402eff32d","approver":"Veykril","queue":"https://bors.rust-lang.org/homu/queue/rust-analyzer"} -->

Patch:
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index a42f8a0ac0..7cf4fb1050 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -535,6 +535,9 @@ impl<'a> InferenceContext<'a> {
         for (_, subst) in result.method_resolutions.values_mut() {
             *subst = table.resolve_completely(subst.clone());
         }
+        for (_, subst) in result.assoc_resolutions.values_mut() {
+            *subst = table.resolve_completely(subst.clone());
+        }
         for adjustment in result.expr_adjustments.values_mut().flatten() {
             adjustment.target = table.resolve_completely(adjustment.target.clone());
         }


Test patch:
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 62404afc4b..3580c45702 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -4079,6 +4079,37 @@ const FOO$0: f64 = 1.0f64;
     );
 }
 
+#[test]
+fn hover_const_eval_in_generic_trait() {
+    // Doesn't compile, but we shouldn't crash.
+    check(
+        r#"
+trait Trait<T> {
+    const FOO: bool = false;
+}
+struct S<T>(T);
+impl<T> Trait<T> for S<T> {
+    const FOO: bool = true;
+}
+
+fn test() {
+    S::FOO$0;
+}
+"#,
+        expect![[r#"
+            *FOO*
+
+            ```rust
+            test
+            ```
+
+            ```rust
+            const FOO: bool = true
+            ```
+        "#]],
+    );
+}
+
 #[test]
 fn hover_const_pat() {
     check(