Repository: rust-lang/rust-analyzer
Pull request #12427 (2022-05-31 11:29:07)

fix: Fix VSCode config patching incorrectly patching some configs

Veykril: @bors r+
bors: :pushpin: Commit 3e1b4943ec5ac1b3c2c46916d418a8e39b71bf95 has been approved by `Veykril`

<!-- @bors r=Veykril 3e1b4943ec5ac1b3c2c46916d418a8e39b71bf95 -->
<!-- homu: {"type":"Approved","sha":"3e1b4943ec5ac1b3c2c46916d418a8e39b71bf95","approver":"Veykril"} -->
bors: :hourglass: Testing commit 3e1b4943ec5ac1b3c2c46916d418a8e39b71bf95 with merge 791b9d6c67a4bb799da61941d56993332c6507d8...
<!-- homu: {"type":"BuildStarted","head_sha":"3e1b4943ec5ac1b3c2c46916d418a8e39b71bf95","merge_sha":"791b9d6c67a4bb799da61941d56993332c6507d8"} -->
bors: :broken_heart: Test failed - [checks-actions](https://github.com/rust-lang/rust-analyzer/runs/6669762286?check_suite_focus=true)
<!-- homu: {"type":"BuildFailed","builder_url":"https://github.com/rust-lang/rust-analyzer/runs/6669762286?check_suite_focus=true","builder_name":"checks-actions"} -->

Patch:
diff --git a/crates/hir-def/src/expr.rs b/crates/hir-def/src/expr.rs
index bc06085894..97681abab1 100644
--- a/crates/hir-def/src/expr.rs
+++ b/crates/hir-def/src/expr.rs
@@ -52,7 +52,7 @@ impl FloatTypeWrapper {
 
 impl std::fmt::Display for FloatTypeWrapper {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{:?}", f64::from_bits(self.0))
+        write!(f, "{}", f64::from_bits(self.0))
     }
 }
 
diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs
index af2aa96574..6972db8495 100644
--- a/crates/hir-ty/src/chalk_db.rs
+++ b/crates/hir-ty/src/chalk_db.rs
@@ -410,10 +410,8 @@ pub(crate) fn associated_ty_data_query(
     let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
     let ctx = crate::TyLoweringContext::new(db, &resolver)
         .with_type_param_mode(crate::lower::ParamLoweringMode::Variable);
-    let pro_ty = TyBuilder::assoc_type_projection(db, type_alias)
-        .fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, 0)
-        .build();
-    let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner);
+    let self_ty =
+        TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(Interner);
     let mut bounds: Vec<_> = type_alias_data
         .bounds
         .iter()
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 116c1c480a..910aee7b05 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -117,32 +117,33 @@ pub(crate) fn inlay_hints(
 
     let mut acc = Vec::new();
 
-    if let Some(scope) = sema.scope(&file) {
-        let famous_defs = FamousDefs(&sema, scope.krate());
-
-        let hints = |node| hints(&mut acc, &famous_defs, config, file_id, node);
-        match range_limit {
-            Some(FileRange { range, .. }) => match file.covering_element(range) {
-                NodeOrToken::Token(_) => return acc,
-                NodeOrToken::Node(n) => n
-                    .descendants()
-                    .filter(|descendant| range.intersect(descendant.text_range()).is_some())
-                    .for_each(hints),
-            },
-            None => file.descendants().for_each(hints),
-        };
-    }
+    let hints = |node| hints(&mut acc, &sema, config, file_id, node);
+    match range_limit {
+        Some(FileRange { range, .. }) => match file.covering_element(range) {
+            NodeOrToken::Token(_) => return acc,
+            NodeOrToken::Node(n) => n
+                .descendants()
+                .filter(|descendant| range.intersect(descendant.text_range()).is_some())
+                .for_each(hints),
+        },
+        None => file.descendants().for_each(hints),
+    };
 
     acc
 }
 
 fn hints(
     hints: &mut Vec<InlayHint>,
-    famous_defs @ FamousDefs(sema, _): &FamousDefs,
+    sema: &Semantics<RootDatabase>,
     config: &InlayHintsConfig,
     file_id: FileId,
     node: SyntaxNode,
 ) {
+    let famous_defs = match sema.scope(&node) {
+        Some(it) => FamousDefs(sema, it.krate()),
+        None => return,
+    };
+
     closing_brace_hints(hints, sema, config, file_id, node.clone());
     match_ast! {
         match node {
@@ -167,18 +168,8 @@ fn hints(
                 }
                 Some(())
             },
-            ast::Item(it) => match it {
-                // FIXME: record impl lifetimes so they aren't being reused in assoc item lifetime inlay hints
-                ast::Item::Impl(_) => None,
-                ast::Item::Fn(it) => fn_lifetime_fn_hints(hints, config, it),
-                // static type elisions
-                ast::Item::Static(it) => implicit_static_hints(hints, config, Either::Left(it)),
-                ast::Item::Const(it) => implicit_static_hints(hints, config, Either::Right(it)),
-                _ => None,
-            },
-            // FIXME: fn-ptr type, dyn fn type, and trait object type elisions
-            ast::Type(_) => None,
-            _ => None,
+            ast::Fn(it) => lifetime_fn_hints(hints, config, it),
+            _ => Some(()),
         }
     };
 }
@@ -288,39 +279,7 @@ fn closing_brace_hints(
     None
 }
 
-fn implicit_static_hints(
-    acc: &mut Vec<InlayHint>,
-    config: &InlayHintsConfig,
-    statik_or_const: Either<ast::Static, ast::Const>,
-) -> Option<()> {
-    if config.lifetime_elision_hints != LifetimeElisionHints::Always {
-        return None;
-    }
-
-    if let Either::Right(it) = &statik_or_const {
-        if ast::AssocItemList::can_cast(
-            it.syntax().parent().map_or(SyntaxKind::EOF, |it| it.kind()),
-        ) {
-            return None;
-        }
-    }
-
-    if let Some(ast::Type::RefType(ty)) = statik_or_const.either(|it| it.ty(), |it| it.ty()) {
-        if ty.lifetime().is_none() {
-            let t = ty.amp_token()?;
-            acc.push(InlayHint {
-                range: t.text_range(),
-                kind: InlayKind::LifetimeHint,
-                label: "'static".to_owned(),
-                tooltip: Some(InlayTooltip::String("Elided static lifetime".into())),
-            });
-        }
-    }
-
-    Some(())
-}
-
-fn fn_lifetime_fn_hints(
+fn lifetime_fn_hints(
     acc: &mut Vec<InlayHint>,
     config: &InlayHintsConfig,
     func: ast::Fn,
@@ -2634,30 +2593,6 @@ impl () {
         );
     }
 
-    #[test]
-    fn hints_lifetimes_static() {
-        check_with_config(
-            InlayHintsConfig {
-                lifetime_elision_hints: LifetimeElisionHints::Always,
-                ..TEST_CONFIG
-            },
-            r#"
-trait Trait {}
-static S: &str = "";
-//        ^'static
-const C: &str = "";
-//       ^'static
-const C: &dyn Trait = panic!();
-//       ^'static
-
-impl () {
-    const C: &str = "";
-    const C: &dyn Trait = panic!();
-}
-"#,
-        );
-    }
-
     #[test]
     fn hints_implicit_reborrow() {
         check_with_config(
diff --git a/docs/dev/style.md b/docs/dev/style.md
index 82b6c749e4..13da88044c 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -69,11 +69,11 @@ After you are happy with the state of the code, please use [interactive rebase](
 Avoid @mentioning people in commit messages and pull request descriptions(they are added to commit message by bors).
 Such messages create a lot of duplicate notification traffic during rebases.
 
-If possible, write Pull Request titles and descriptions from the user's perspective:
+If possible, write commit messages from user's perspective:
 
 ```
 # GOOD
-Make goto definition work inside macros
+Goto definition works inside macros
 
 # BAD
 Use original span for FileId
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index d07e47c8de..fd9665b614 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -219,7 +219,7 @@ export async function updateConfig(config: vscode.WorkspaceConfiguration) {
                 },
             ];
             for (const { val, langVal, target } of valMatrix) {
-                const pred = (val: unknown) => {
+                const patch = (val: unknown) => {
                     // some of the updates we do only append "enable" or "custom"
                     // that means on the next run we would find these again, but as objects with
                     // these properties causing us to destroy the config
@@ -229,15 +229,15 @@ export async function updateConfig(config: vscode.WorkspaceConfiguration) {
                         !(
                             typeof val === "object" &&
                             val !== null &&
-                            (val.hasOwnProperty("enable") || val.hasOwnProperty("custom"))
+                            (oldKey === "completion.snippets" || !val.hasOwnProperty("custom"))
                         )
                     );
                 };
-                if (pred(val)) {
+                if (patch(val)) {
                     await config.update(newKey, val, target, false);
                     await config.update(oldKey, undefined, target, false);
                 }
-                if (pred(langVal)) {
+                if (patch(langVal)) {
                     await config.update(newKey, langVal, target, true);
                     await config.update(oldKey, undefined, target, true);
                 }


Test patch:
diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs
index a11b026df5..b1d295ca34 100644
--- a/crates/hir-ty/src/tests/traits.rs
+++ b/crates/hir-ty/src/tests/traits.rs
@@ -1,7 +1,7 @@
 use cov_mark::check;
 use expect_test::expect;
 
-use super::{check, check_infer, check_infer_with_mismatches, check_no_mismatches, check_types};
+use super::{check, check_infer, check_infer_with_mismatches, check_types};
 
 #[test]
 fn infer_await() {
@@ -3316,42 +3316,6 @@ pub trait Deserialize {
     );
 }
 
-#[test]
-fn bin_op_with_rhs_is_self_for_assoc_bound() {
-    check_no_mismatches(
-        r#"//- minicore: eq
-        fn repro<T>(t: T) -> bool
-where
-    T: Request,
-    T::Output: Convertable,
-{
-    let a = execute(&t).convert();
-    let b = execute(&t).convert();
-    a.eq(&b);
-    let a = execute(&t).convert2();
-    let b = execute(&t).convert2();
-    a.eq(&b)
-}
-fn execute<T>(t: &T) -> T::Output
-where
-    T: Request,
-{
-    <T as Request>::output()
-}
-trait Convertable {
-    type TraitSelf: PartialEq<Self::TraitSelf>;
-    type AssocAsDefaultSelf: PartialEq;
-    fn convert(self) -> Self::AssocAsDefaultSelf;
-    fn convert2(self) -> Self::TraitSelf;
-}
-trait Request {
-    type Output;
-    fn output() -> Self::Output;
-}
-     "#,
-    );
-}
-
 #[test]
 fn bin_op_adt_with_rhs_primitive() {
     check_infer_with_mismatches(
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index c95a0e4005..07f224da66 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -3634,7 +3634,7 @@ const FOO$0: f32 = 1f32;
             ```
 
             ```rust
-            const FOO: f32 = 1.0
+            const FOO: f32 = 1
             ```
 
             ---
@@ -3656,7 +3656,7 @@ const FOO$0: f64 = 1.0f64;
             ```
 
             ```rust
-            const FOO: f64 = 1.0
+            const FOO: f64 = 1
             ```
 
             ---