Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21509 from Veykril/push-zwownxpqxrnw
internal: Add tests for rust-lang/rust#146972
Lukas Wirth 4 months ago
parent 88d595e · parent 16bf7bc · commit 39018ac
-rw-r--r--crates/hir-def/src/nameres/tests.rs2
-rw-r--r--crates/hir-def/src/nameres/tests/imports.rs63
-rw-r--r--crates/hir-def/src/nameres/tests/primitives.rs23
3 files changed, 64 insertions, 24 deletions
diff --git a/crates/hir-def/src/nameres/tests.rs b/crates/hir-def/src/nameres/tests.rs
index 23d60d58f0..fe55252e25 100644
--- a/crates/hir-def/src/nameres/tests.rs
+++ b/crates/hir-def/src/nameres/tests.rs
@@ -1,8 +1,8 @@
mod globs;
+mod imports;
mod incremental;
mod macros;
mod mod_resolution;
-mod primitives;
use base_db::RootQueryDb;
use expect_test::{Expect, expect};
diff --git a/crates/hir-def/src/nameres/tests/imports.rs b/crates/hir-def/src/nameres/tests/imports.rs
new file mode 100644
index 0000000000..b1960b785a
--- /dev/null
+++ b/crates/hir-def/src/nameres/tests/imports.rs
@@ -0,0 +1,63 @@
+use super::*;
+
+#[test]
+fn kw_path_renames() {
+ check(
+ r#"
+macro_rules! m {
+ () => {
+ pub use $crate as dollar_crate;
+ pub use $crate::{self as self_dollar_crate};
+ };
+}
+
+pub use self as this;
+pub use crate as krate;
+
+pub use crate::{self as self_krate};
+m!();
+
+mod foo {
+ pub use super as zuper;
+ pub use super::{self as self_zuper};
+}
+"#,
+ expect![[r#"
+ crate
+ - dollar_crate : type (import)
+ - foo : type
+ - krate : type (import)
+ - self_dollar_crate : type (import)
+ - self_krate : type (import)
+ - this : type (import)
+ - (legacy) m : macro!
+
+ crate::foo
+ - self_zuper : type (import)
+ - zuper : type (import)
+ - (legacy) m : macro!
+ "#]],
+ );
+}
+
+#[test]
+fn primitive_reexport() {
+ check(
+ r#"
+//- /lib.rs
+mod foo;
+use foo::int;
+
+//- /foo.rs
+pub use i32 as int;
+"#,
+ expect![[r#"
+ crate
+ - foo : type
+ - int : type (import)
+
+ crate::foo
+ - int : type (import)
+ "#]],
+ );
+}
diff --git a/crates/hir-def/src/nameres/tests/primitives.rs b/crates/hir-def/src/nameres/tests/primitives.rs
deleted file mode 100644
index 861690238d..0000000000
--- a/crates/hir-def/src/nameres/tests/primitives.rs
+++ /dev/null
@@ -1,23 +0,0 @@
-use super::*;
-
-#[test]
-fn primitive_reexport() {
- check(
- r#"
-//- /lib.rs
-mod foo;
-use foo::int;
-
-//- /foo.rs
-pub use i32 as int;
-"#,
- expect![[r#"
- crate
- - foo : type
- - int : type (import)
-
- crate::foo
- - int : type (import)
- "#]],
- );
-}
None => range.len(), Some(size) => { if range.len() < size { range.len() } else { size } } }; if size != Some(new_size) { size = Some(new_size); res = module; } } res } fn block_at_position(&self, def_map: &DefMap, position: FilePosition) -> Option<&DefMap> { // Find the smallest (innermost) function in `def_map` containing the cursor. let mut size = None; let mut fn_def = None; for (_, module) in def_map.modules() { let file_id = module.definition_source(self).file_id; if file_id != position.file_id { continue; } for decl in module.scope.declarations() { if let ModuleDefId::FunctionId(it) = decl { let range = it.lookup(self).source(self).value.syntax().text_range(); if !range.contains(position.offset) { continue; } let new_size = match size { None => range.len(), Some(size) => { if range.len() < size { range.len() } else { size } } }; if size != Some(new_size) { size = Some(new_size); fn_def = Some(it); } } } } // Find the innermost block expression that has a `DefMap`. let def_with_body = fn_def?.into(); let source_map = self.body_with_source_map(def_with_body).1; let scopes = self.expr_scopes(def_with_body); let root_syntax_node = self.parse(position.file_id).syntax_node(); let scope_iter = algo::ancestors_at_offset(&root_syntax_node, position.offset).filter_map(|node| { let block = ast::BlockExpr::cast(node)?; let expr = ast::Expr::from(block); let expr_id = source_map .node_expr(InFile::new(position.file_id.into(), &expr))? .as_expr() .unwrap(); let scope = scopes.scope_for(expr_id).unwrap(); Some(scope) }); for scope in scope_iter { let mut containing_blocks = scopes.scope_chain(Some(scope)).filter_map(|scope| scopes.block(scope)); if let Some(block) = containing_blocks.next().map(|block| block_def_map(self, block)) { return Some(block); } } None } pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> { *self.events.lock().unwrap() = Some(Vec::new()); f(); self.events.lock().unwrap().take().unwrap() } pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> { let events = self.log(f); events .into_iter() .filter_map(|e| match e.kind { // This is pretty horrible, but `Debug` is the only way to inspect // QueryDescriptor at the moment. salsa::EventKind::WillExecute { database_key } => { let ingredient = self .as_dyn_database() .ingredient_debug_name(database_key.ingredient_index()); Some(ingredient.to_string()) } _ => None, }) .collect() } }