diff --git a/crates/hir-def/src/item_scope.rs b/crates/hir-def/src/item_scope.rs index 579f803ea1..a11a92204c 100644 --- a/crates/hir-def/src/item_scope.rs +++ b/crates/hir-def/src/item_scope.rs @@ -5,6 +5,7 @@ use std::collections::hash_map::Entry; use base_db::CrateId; use hir_expand::{name::Name, AstId, MacroCallId}; +use itertools::Itertools; use once_cell::sync::Lazy; use profile::Count; use rustc_hash::{FxHashMap, FxHashSet}; @@ -97,15 +98,14 @@ pub(crate) enum BuiltinShadowMode { impl ItemScope { pub fn entries<'a>(&'a self) -> impl Iterator + 'a { // FIXME: shadowing - let keys: FxHashSet<_> = self - .types + self.types .keys() .chain(self.values.keys()) .chain(self.macros.keys()) .chain(self.unresolved.iter()) - .collect(); - - keys.into_iter().map(move |name| (name, self.get(name))) + .sorted() + .unique() + .map(move |name| (name, self.get(name))) } pub fn declarations(&self) -> impl Iterator + '_ { diff --git a/crates/ide-assists/src/handlers/expand_glob_import.rs b/crates/ide-assists/src/handlers/expand_glob_import.rs index 943c1d90e6..87f5018fb6 100644 --- a/crates/ide-assists/src/handlers/expand_glob_import.rs +++ b/crates/ide-assists/src/handlers/expand_glob_import.rs @@ -36,7 +36,7 @@ use crate::{ // pub struct Baz; // } // -// use foo::{Baz, Bar}; +// use foo::{Bar, Baz}; // // fn qux(bar: Bar, baz: Baz) {} // ``` @@ -281,7 +281,7 @@ mod foo { pub fn f() {} } -use foo::{Baz, Bar, f}; +use foo::{Bar, Baz, f}; fn qux(bar: Bar, baz: Baz) { f(); @@ -351,7 +351,7 @@ mod foo { pub fn f() {} } -use foo::{Baz, Bar, f}; +use foo::{Bar, Baz, f}; fn qux(bar: Bar, baz: Baz) { f(); @@ -440,7 +440,7 @@ mod foo { } } -use foo::{bar::{Baz, Bar, f}, baz::*}; +use foo::{bar::{Bar, Baz, f}, baz::*}; fn qux(bar: Bar, baz: Baz) { f(); @@ -561,7 +561,7 @@ mod foo { use foo::{ bar::{*, f}, - baz::{g, qux::{q, h}} + baz::{g, qux::{h, q}} }; fn qux(bar: Bar, baz: Baz) { diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index e8d48607be..6eaab48a32 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -535,7 +535,7 @@ mod foo { pub struct Baz; } -use foo::{Baz, Bar}; +use foo::{Bar, Baz}; fn qux(bar: Bar, baz: Baz) {} "#####, diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 39cf957137..946134b0ff 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -1271,8 +1271,8 @@ fn main() { st S [] st &mut S [type] st S [] - fn main() [] fn foo(…) [] + fn main() [] "#]], ); check_relevance( @@ -1288,8 +1288,8 @@ fn main() { lc s [type+name+local] st S [type] st S [] - fn main() [] fn foo(…) [] + fn main() [] "#]], ); check_relevance( @@ -1305,8 +1305,8 @@ fn main() { lc ssss [type+local] st S [type] st S [] - fn main() [] fn foo(…) [] + fn main() [] "#]], ); } @@ -1342,10 +1342,10 @@ fn main() { lc &t [type+local] st S [] st &S [type] - st T [] st S [] - fn main() [] + st T [] fn foo(…) [] + fn main() [] md core [] "#]], ) @@ -1388,10 +1388,10 @@ fn main() { lc &mut t [type+local] st S [] st &mut S [type] - st T [] st S [] - fn main() [] + st T [] fn foo(…) [] + fn main() [] md core [] "#]], ) @@ -1483,12 +1483,12 @@ fn main() { expect![[r#" st S [] st &S [type] - st T [] st S [] - fn main() [] + st T [] fn bar() [] fn &bar() [type] fn foo(…) [] + fn main() [] md core [] "#]], ) @@ -1633,8 +1633,8 @@ fn foo() { ev Foo::B [type_could_unify] fn foo() [] en Foo [] - fn baz() [] fn bar() [] + fn baz() [] "#]], ); } @@ -1724,9 +1724,9 @@ fn f() { } "#, expect![[r#" - md std [] st Buffer [] fn f() [] + md std [] tt BufRead (use std::io::BufRead) [requires_import] st BufReader (use std::io::BufReader) [requires_import] st BufWriter (use std::io::BufWriter) [requires_import]