Repository: rust-analyzer/rust-analyzer
Pull request #2597 (2019-12-19 16:04:04)

Handle start imports in import groups


Patch:
diff --git a/crates/ra_hir_def/src/marks.rs b/crates/ra_hir_def/src/marks.rs
index 65239ca0a4..457ba4abec 100644
--- a/crates/ra_hir_def/src/marks.rs
+++ b/crates/ra_hir_def/src/marks.rs
@@ -5,6 +5,7 @@ test_utils::marks!(
     name_res_works_for_broken_modules
     can_import_enum_variant
     glob_enum
+    glob_enum_group
     glob_across_crates
     std_prelude
     macro_rules_from_other_crates_are_visible_with_macro_use
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs
index 062c02063e..3218eaf0a2 100644
--- a/crates/ra_hir_def/src/path/lower/lower_use.rs
+++ b/crates/ra_hir_def/src/path/lower/lower_use.rs
@@ -9,6 +9,7 @@ use hir_expand::{
     name::{AsName, Name},
 };
 use ra_syntax::ast::{self, NameOwner};
+use test_utils::tested_by;
 
 use crate::path::{ModPath, PathKind};
 
@@ -34,6 +35,7 @@ pub(crate) fn lower_use_tree(
         }
     } else {
         let alias = tree.alias().and_then(|a| a.name()).map(|a| a.as_name());
+        let is_glob = tree.has_star();
         if let Some(ast_path) = tree.path() {
             // Handle self in a path.
             // E.g. `use something::{self, <...>}`
@@ -48,11 +50,15 @@ pub(crate) fn lower_use_tree(
                 }
             }
             if let Some(path) = convert_path(prefix, ast_path, hygiene) {
-                let is_glob = tree.has_star();
                 cb(path, &tree, is_glob, alias)
             }
-            // FIXME: report errors somewhere
-            // We get here if we do
+        // FIXME: report errors somewhere
+        // We get here if we do
+        } else if is_glob {
+            tested_by!(glob_enum_group);
+            if let Some(prefix) = prefix {
+                cb(prefix, &tree, is_glob, None)
+            }
         }
     }
 }
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs
index dcca1bace6..9bb3ece6c8 100644
--- a/crates/ra_hir_ty/src/display.rs
+++ b/crates/ra_hir_ty/src/display.rs
@@ -10,7 +10,6 @@ pub struct HirFormatter<'a, 'b, DB> {
     buf: String,
     curr_size: usize,
     max_size: Option<usize>,
-    should_display_default_types: bool,
 }
 
 pub trait HirDisplay {
@@ -20,7 +19,7 @@ pub trait HirDisplay {
     where
         Self: Sized,
     {
-        HirDisplayWrapper(db, self, None, true)
+        HirDisplayWrapper(db, self, None)
     }
 
     fn display_truncated<'a, DB>(
@@ -31,7 +30,7 @@ pub trait HirDisplay {
     where
         Self: Sized,
     {
-        HirDisplayWrapper(db, self, max_size, false)
+        HirDisplayWrapper(db, self, max_size)
     }
 }
 
@@ -73,13 +72,9 @@ where
             false
         }
     }
-
-    pub fn should_display_default_types(&self) -> bool {
-        self.should_display_default_types
-    }
 }
 
-pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<usize>, bool);
+pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<usize>);
 
 impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T>
 where
@@ -93,7 +88,6 @@ where
             buf: String::with_capacity(20),
             curr_size: 0,
             max_size: self.2,
-            should_display_default_types: self.3,
         })
     }
 }
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index 7ca9e6b8a7..3ad913e55e 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -906,38 +906,7 @@ impl HirDisplay for ApplicationTy {
                 write!(f, "{}", name)?;
                 if self.parameters.len() > 0 {
                     write!(f, "<")?;
-
-                    let mut non_default_parameters = Vec::with_capacity(self.parameters.len());
-                    let parameters_to_write = if f.should_display_default_types() {
-                        self.parameters.0.as_ref()
-                    } else {
-                        match self
-                            .ctor
-                            .as_generic_def()
-                            .map(|generic_def_id| f.db.generic_defaults(generic_def_id))
-                            .filter(|defaults| !defaults.is_empty())
-                        {
-                            Option::None => self.parameters.0.as_ref(),
-                            Option::Some(default_parameters) => {
-                                for (i, parameter) in self.parameters.into_iter().enumerate() {
-                                    match (parameter, default_parameters.get(i)) {
-                                        (&Ty::Unknown, _) | (_, None) => {
-                                            non_default_parameters.push(parameter.clone())
-                                        }
-                                        (_, Some(default_parameter))
-                                            if parameter != default_parameter =>
-                                        {
-                                            non_default_parameters.push(parameter.clone())
-                                        }
-                                        _ => (),
-                                    }
-                                }
-                                &non_default_parameters
-                            }
-                        }
-                    };
-
-                    f.write_joined(parameters_to_write, ", ")?;
+                    f.write_joined(&*self.parameters.0, ", ")?;
                     write!(f, ">")?;
                 }
             }
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index a227bf546c..51e3201282 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -250,7 +250,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
     } else {
         return None;
     };
-    Some(ty.display_truncated(db, None).to_string())
+    Some(ty.display(db).to_string())
 }
 
 #[cfg(test)]
@@ -424,23 +424,6 @@ mod tests {
         );
     }
 
-    #[test]
-    fn hover_omits_default_generic_types() {
-        check_hover_result(
-            r#"
-//- /main.rs
-struct Test<K, T = u8> {
-    k: K,
-    t: T,
-}
-
-fn main() {
-    let zz<|> = Test { t: 23, k: 33 };
-}"#,
-            &["Test<i32>"],
-        );
-    }
-
     #[test]
     fn hover_some() {
         let (analysis, position) = single_file_with_position(
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 3154df4572..3730121afe 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -159,32 +159,6 @@ mod tests {
 
     use crate::mock_analysis::single_file;
 
-    #[test]
-    fn default_generic_types_should_not_be_displayed() {
-        let (analysis, file_id) = single_file(
-            r#"
-struct Test<K, T = u8> {
-    k: K,
-    t: T,
-}
-
-fn main() {
-    let zz = Test { t: 23, k: 33 };
-}"#,
-        );
-
-        assert_debug_snapshot!(analysis.inlay_hints(file_id, None).unwrap(), @r###"
-        [
-            InlayHint {
-                range: [69; 71),
-                kind: TypeHint,
-                label: "Test<i32>",
-            },
-        ]
-        "###
-        );
-    }
-
     #[test]
     fn let_statement() {
         let (analysis, file_id) = single_file(


Test patch:
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs
index 5b03fe3650..5e24cb94d6 100644
--- a/crates/ra_hir_def/src/nameres/tests/globs.rs
+++ b/crates/ra_hir_def/src/nameres/tests/globs.rs
@@ -112,3 +112,24 @@ fn glob_enum() {
     "###
     );
 }
+
+#[test]
+fn glob_enum_group() {
+    covers!(glob_enum_group);
+    let map = def_map(
+        "
+        //- /lib.rs
+        enum Foo {
+            Bar, Baz
+        }
+        use self::Foo::{*};
+        ",
+    );
+    assert_snapshot!(map, @r###"
+   ⋮crate
+   ⋮Bar: t v
+   ⋮Baz: t v
+   ⋮Foo: t
+    "###
+    );
+}