Repository: rust-lang/rust-analyzer
Pull request #12430 (2022-05-31 18:22:29)

minor: Remove unused code


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-completion/src/context.rs b/crates/ide-completion/src/context.rs
index b70d6f9e8d..f3e316ff3c 100644
--- a/crates/ide-completion/src/context.rs
+++ b/crates/ide-completion/src/context.rs
@@ -383,7 +383,6 @@ impl<'a> CompletionContext<'a> {
     // FIXME: This shouldn't exist
     pub(crate) fn is_path_disallowed(&self) -> bool {
         !self.qualifier_ctx.none()
-            || matches!(self.prev_sibling, Some(ImmediatePrevSibling::Visibility))
             || (matches!(self.name_ctx(), Some(NameContext { .. })) && self.pattern_ctx.is_none())
             || matches!(self.pattern_ctx, Some(PatternContext { record_pat: Some(_), .. }))
             || matches!(
diff --git a/crates/ide-completion/src/patterns.rs b/crates/ide-completion/src/patterns.rs
index 0e146df712..cc599a02cb 100644
--- a/crates/ide-completion/src/patterns.rs
+++ b/crates/ide-completion/src/patterns.rs
@@ -23,7 +23,6 @@ pub(crate) enum ImmediatePrevSibling {
     IfExpr,
     TraitDefName,
     ImplDefType,
-    Visibility,
 }
 
 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -77,17 +76,6 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi
         _ => node,
     };
     let prev_sibling = non_trivia_sibling(node.into(), Direction::Prev)?.into_node()?;
-    if prev_sibling.kind() == ERROR {
-        let prev_sibling = prev_sibling.first_child()?;
-        let res = match_ast! {
-            match prev_sibling {
-                // vis followed by random ident will always error the parser
-                ast::Visibility(_) => ImmediatePrevSibling::Visibility,
-                _ => return None,
-            }
-        };
-        return Some(res);
-    }
     let res = match_ast! {
         match prev_sibling {
             ast::ExprStmt(it) => {
@@ -442,9 +430,4 @@ mod tests {
         check_prev_sibling(r"fn foo() { if true {} w$0", ImmediatePrevSibling::IfExpr);
         check_prev_sibling(r"fn foo() { if true {}; w$0", None);
     }
-
-    #[test]
-    fn test_vis_prev_sibling() {
-        check_prev_sibling(r"pub w$0", ImmediatePrevSibling::Visibility);
-    }
 }
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 fd9665b614..d07e47c8de 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 patch = (val: unknown) => {
+                const pred = (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 &&
-                            (oldKey === "completion.snippets" || !val.hasOwnProperty("custom"))
+                            (val.hasOwnProperty("enable") || val.hasOwnProperty("custom"))
                         )
                     );
                 };
-                if (patch(val)) {
+                if (pred(val)) {
                     await config.update(newKey, val, target, false);
                     await config.update(oldKey, undefined, target, false);
                 }
-                if (patch(langVal)) {
+                if (pred(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
             ```
 
             ---