Repository: rust-lang/rust-analyzer
Pull request #12402 (2022-05-27 13:47:44)

minor: Freshen up goto feature docs
Fixes https://github.com/rust-lang/rust-analyzer/issues/2541


Patch:
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 5d7a1100cd..0f9f0e0e1c 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -29,8 +29,8 @@ use crate::{
     builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
     db::DefDatabase,
     expr::{
-        dummy_expr_id, Array, BindingAnnotation, Expr, ExprId, FloatTypeWrapper, Label, LabelId,
-        Literal, MatchArm, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
+        dummy_expr_id, Array, BindingAnnotation, Expr, ExprId, Label, LabelId, Literal, MatchArm,
+        Pat, PatId, RecordFieldPat, RecordLitField, Statement,
     },
     intern::Interned,
     item_scope::BuiltinShadowMode,
@@ -968,10 +968,7 @@ impl From<ast::LiteralKind> for Literal {
             // FIXME: these should have actual values filled in, but unsure on perf impact
             LiteralKind::IntNumber(lit) => {
                 if let builtin @ Some(_) = lit.suffix().and_then(BuiltinFloat::from_suffix) {
-                    Literal::Float(
-                        FloatTypeWrapper::new(lit.float_value().unwrap_or(Default::default())),
-                        builtin,
-                    )
+                    Literal::Float(Default::default(), builtin)
                 } else if let builtin @ Some(_) = lit.suffix().and_then(BuiltinInt::from_suffix) {
                     Literal::Int(lit.value().unwrap_or(0) as i128, builtin)
                 } else {
@@ -981,7 +978,7 @@ impl From<ast::LiteralKind> for Literal {
             }
             LiteralKind::FloatNumber(lit) => {
                 let ty = lit.suffix().and_then(BuiltinFloat::from_suffix);
-                Literal::Float(FloatTypeWrapper::new(lit.value().unwrap_or(Default::default())), ty)
+                Literal::Float(Default::default(), ty)
             }
             LiteralKind::ByteString(bs) => {
                 let text = bs.value().map(Box::from).unwrap_or_else(Default::default);
diff --git a/crates/hir-def/src/expr.rs b/crates/hir-def/src/expr.rs
index 97681abab1..fd09e651c9 100644
--- a/crates/hir-def/src/expr.rs
+++ b/crates/hir-def/src/expr.rs
@@ -38,24 +38,6 @@ pub struct Label {
 }
 pub type LabelId = Idx<Label>;
 
-// We convert float values into bits and that's how we don't need to deal with f32 and f64.
-// For PartialEq, bits comparison should work, as ordering is not important
-// https://github.com/rust-lang/rust-analyzer/issues/12380#issuecomment-1137284360
-#[derive(Default, Debug, Clone, Eq, PartialEq)]
-pub struct FloatTypeWrapper(u64);
-
-impl FloatTypeWrapper {
-    pub fn new(value: f64) -> Self {
-        Self(value.to_bits())
-    }
-}
-
-impl std::fmt::Display for FloatTypeWrapper {
-    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-        write!(f, "{}", f64::from_bits(self.0))
-    }
-}
-
 #[derive(Debug, Clone, Eq, PartialEq)]
 pub enum Literal {
     String(Box<str>),
@@ -64,10 +46,7 @@ pub enum Literal {
     Bool(bool),
     Int(i128, Option<BuiltinInt>),
     Uint(u128, Option<BuiltinUint>),
-    // Here we are using a wrapper around float because f32 and f64 do not implement Eq, so they
-    // could not be used directly here, to understand how the wrapper works go to definition of
-    // FloatTypeWrapper
-    Float(FloatTypeWrapper, Option<BuiltinFloat>),
+    Float(u64, Option<BuiltinFloat>), // FIXME: f64 is not Eq
 }
 
 #[derive(Debug, Clone, Eq, PartialEq)]
diff --git a/crates/ide/src/goto_declaration.rs b/crates/ide/src/goto_declaration.rs
index cb2cddc20d..926292c9b3 100644
--- a/crates/ide/src/goto_declaration.rs
+++ b/crates/ide/src/goto_declaration.rs
@@ -10,6 +10,9 @@ use crate::{FilePosition, NavigationTarget, RangeInfo};
 // Feature: Go to Declaration
 //
 // Navigates to the declaration of an identifier.
+//
+// This is currently the same as `Go to Definition` with the exception of outline modules where it
+// will navigate to the `mod name;` item declaration.
 pub(crate) fn goto_declaration(
     db: &RootDatabase,
     position: FilePosition,
diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs
index 30f48819e6..df73879aed 100644
--- a/crates/ide/src/goto_definition.rs
+++ b/crates/ide/src/goto_definition.rs
@@ -15,6 +15,8 @@ use syntax::{ast, AstNode, AstToken, SyntaxKind::*, SyntaxToken, TextRange, T};
 //
 // Navigates to the definition of an identifier.
 //
+// For outline modules, this will navigate to the source file of the module.
+//
 // |===
 // | Editor  | Shortcut
 //
diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs
index a7d6bc2401..1d2909fa28 100644
--- a/crates/ide/src/goto_implementation.rs
+++ b/crates/ide/src/goto_implementation.rs
@@ -11,7 +11,7 @@ use crate::{FilePosition, NavigationTarget, RangeInfo, TryToNav};
 
 // Feature: Go to Implementation
 //
-// Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
+// Navigates to the impl blocks of types.
 //
 // |===
 // | Editor  | Shortcut
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index c347913fb2..110575e85c 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -697,22 +697,7 @@ impl Config {
         match self.data.linkedProjects.as_slice() {
             [] => match self.discovered_projects.as_ref() {
                 Some(discovered_projects) => {
-                    let exclude_dirs: Vec<_> = self
-                        .data
-                        .files_excludeDirs
-                        .iter()
-                        .map(|p| self.root_path.join(p))
-                        .collect();
-                    discovered_projects
-                        .iter()
-                        .filter(|p| {
-                            let (ProjectManifest::ProjectJson(path)
-                            | ProjectManifest::CargoToml(path)) = p;
-                            !exclude_dirs.iter().any(|p| path.starts_with(p))
-                        })
-                        .cloned()
-                        .map(LinkedProject::from)
-                        .collect()
+                    discovered_projects.iter().cloned().map(LinkedProject::from).collect()
                 }
                 None => Vec::new(),
             },
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 28976d837b..4b6dc236b5 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -319,49 +319,17 @@ impl ast::IntNumber {
             Some(suffix)
         }
     }
-
-    pub fn float_value(&self) -> Option<f64> {
-        let (_, text, _) = self.split_into_parts();
-        text.parse::<f64>().ok()
-    }
 }
 
 impl ast::FloatNumber {
-    pub fn split_into_parts(&self) -> (&str, &str) {
+    pub fn suffix(&self) -> Option<&str> {
         let text = self.text();
-        let mut float_text = self.text();
-        let mut suffix = "";
         let mut indices = text.char_indices();
-        if let Some((mut suffix_start, c)) = indices.by_ref().find(|(_, c)| c.is_ascii_alphabetic())
-        {
-            if c == 'e' || c == 'E' {
-                if let Some(suffix_start_tuple) = indices.find(|(_, c)| c.is_ascii_alphabetic()) {
-                    suffix_start = suffix_start_tuple.0;
-
-                    float_text = &text[..suffix_start];
-                    suffix = &text[suffix_start..];
-                }
-            } else {
-                float_text = &text[..suffix_start];
-                suffix = &text[suffix_start..];
-            }
+        let (mut suffix_start, c) = indices.by_ref().find(|(_, c)| c.is_ascii_alphabetic())?;
+        if c == 'e' || c == 'E' {
+            suffix_start = indices.find(|(_, c)| c.is_ascii_alphabetic())?.0;
         }
-
-        (float_text, suffix)
-    }
-
-    pub fn suffix(&self) -> Option<&str> {
-        let (_, suffix) = self.split_into_parts();
-        if suffix.is_empty() {
-            None
-        } else {
-            Some(suffix)
-        }
-    }
-
-    pub fn value(&self) -> Option<f64> {
-        let (text, _) = self.split_into_parts();
-        text.parse::<f64>().ok()
+        Some(&text[suffix_start..])
     }
 }
 


Test patch:
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 07f224da66..5d084ac955 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -3595,72 +3595,6 @@ const FOO$0: u8 = b'\x61';
 
             ---
 
-            This is a doc
-        "#]],
-    );
-    // show float literal
-    check(
-        r#"
-    /// This is a doc
-    const FOO$0: f64 = 1.0234;
-    "#,
-        expect![[r#"
-            *FOO*
-
-            ```rust
-            test
-            ```
-
-            ```rust
-            const FOO: f64 = 1.0234
-            ```
-
-            ---
-
-            This is a doc
-        "#]],
-    );
-    //show float typecasted from int
-    check(
-        r#"
-/// This is a doc
-const FOO$0: f32 = 1f32;
-"#,
-        expect![[r#"
-            *FOO*
-
-            ```rust
-            test
-            ```
-
-            ```rust
-            const FOO: f32 = 1
-            ```
-
-            ---
-
-            This is a doc
-        "#]],
-    );
-    //show f64 typecasted from float
-    check(
-        r#"
-/// This is a doc
-const FOO$0: f64 = 1.0f64;
-"#,
-        expect![[r#"
-            *FOO*
-
-            ```rust
-            test
-            ```
-
-            ```rust
-            const FOO: f64 = 1
-            ```
-
-            ---
-
             This is a doc
         "#]],
     );
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs
index 6d2788d337..5bb925f62b 100644
--- a/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -20,7 +20,7 @@ use lsp_types::{
     notification::DidOpenTextDocument,
     request::{
         CodeActionRequest, Completion, Formatting, GotoTypeDefinition, HoverRequest,
-        WillRenameFiles, WorkspaceSymbol,
+        WillRenameFiles,
     },
     CodeActionContext, CodeActionParams, CompletionParams, DidOpenTextDocumentParams,
     DocumentFormattingParams, FileRename, FormattingOptions, GotoDefinitionParams, HoverParams,
@@ -1056,41 +1056,3 @@ fn main() {}
         }),
     );
 }
-
-#[test]
-fn test_exclude_config_works() {
-    if skip_slow_tests() {
-        return;
-    }
-
-    let server = Project::with_fixture(
-        r#"
-//- /foo/Cargo.toml
-[package]
-name = "foo"
-version = "0.0.0"
-
-//- /foo/src/lib.rs
-pub fn foo() {}
-
-//- /bar/Cargo.toml
-[package]
-name = "bar"
-version = "0.0.0"
-
-//- /bar/src/lib.rs
-pub fn bar() {}
-"#,
-    )
-    .root("foo")
-    .root("bar")
-    .with_config(json!({
-       "files": {
-           "excludeDirs": ["foo", "bar"]
-        }
-    }))
-    .server()
-    .wait_until_workspace_is_loaded();
-
-    server.request::<WorkspaceSymbol>(Default::default(), json!([]));
-}