Unnamed repository; edit this file 'description' to name the repository.
Some more minor cleanups
Lukas Wirth 2023-12-02
parent 5edf7bd · commit 02a3a94
-rw-r--r--crates/base-db/src/lib.rs1
-rw-r--r--crates/hir-def/src/body/tests.rs48
-rw-r--r--crates/hir-expand/src/lib.rs5
-rw-r--r--crates/hir-ty/src/tests/macros.rs12
-rw-r--r--crates/hir/src/semantics.rs7
-rw-r--r--crates/ide/src/expand_macro.rs4
-rw-r--r--crates/test-utils/src/minicore.rs9
7 files changed, 65 insertions, 21 deletions
diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs
index 38a2641230..cddd5bdf48 100644
--- a/crates/base-db/src/lib.rs
+++ b/crates/base-db/src/lib.rs
@@ -4,7 +4,6 @@
mod input;
mod change;
-// FIXME: Is this purely a test util mod? Consider #[cfg(test)] gating it.
pub mod fixture;
pub mod span;
diff --git a/crates/hir-def/src/body/tests.rs b/crates/hir-def/src/body/tests.rs
index 048f0a13f0..5517abb1ab 100644
--- a/crates/hir-def/src/body/tests.rs
+++ b/crates/hir-def/src/body/tests.rs
@@ -2,7 +2,6 @@ mod block;
use base_db::{fixture::WithFixture, SourceDatabase};
use expect_test::{expect, Expect};
-use hir_expand::db::ExpandDatabase;
use crate::{test_db::TestDB, ModuleDefId};
@@ -255,7 +254,6 @@ impl SsrError {
}
"##,
);
- println!("{}", db.dump_syntax_contexts());
assert_eq!(db.body_with_source_map(def.into()).1.diagnostics(), &[]);
expect![[r#"
@@ -288,3 +286,49 @@ impl SsrError {
}"#]]
.assert_eq(&body.pretty_print(&db, def))
}
+
+#[test]
+fn regression_10300() {
+ let (db, body, def) = lower(
+ r#"
+//- minicore: concat, panic
+mod private {
+ pub use core::concat;
+}
+
+macro_rules! m {
+ () => {
+ panic!(concat!($crate::private::concat!("cc")));
+ };
+}
+
+fn f() {
+ m!();
+}
+"#,
+ );
+
+ let (_, source_map) = db.body_with_source_map(def.into());
+ assert_eq!(source_map.diagnostics(), &[]);
+
+ for (_, def_map) in body.blocks(&db) {
+ assert_eq!(def_map.diagnostics(), &[]);
+ }
+
+ expect![[r#"
+ fn f() {
+ $crate::panicking::panic_fmt(
+ builtin#lang(Arguments::new_v1_formatted)(
+ &[
+ "\"cc\"",
+ ],
+ &[],
+ &[],
+ unsafe {
+ builtin#lang(UnsafeArg::new)()
+ },
+ ),
+ );
+ }"#]]
+ .assert_eq(&body.pretty_print(&db, def))
+}
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index 9caf5513bf..f328431372 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -628,14 +628,13 @@ impl ExpansionInfo {
span: SpanData,
// FIXME: use this for range mapping, so that we can resolve inline format args
_relative_token_offset: Option<TextSize>,
- // FIXME: ret ty should be wrapped in InMacroFile
- ) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + 'a> {
+ ) -> Option<impl Iterator<Item = InMacroFile<SyntaxToken>> + 'a> {
let tokens = self
.exp_map
.ranges_with_span(span)
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
- Some(tokens.map(move |token| InFile::new(self.expanded.file_id.into(), token)))
+ Some(tokens.map(move |token| InMacroFile::new(self.expanded.file_id, token)))
}
/// Maps up the text range out of the expansion hierarchy back into the original file its from.
diff --git a/crates/hir-ty/src/tests/macros.rs b/crates/hir-ty/src/tests/macros.rs
index 1e10a6feca..d16e0eb013 100644
--- a/crates/hir-ty/src/tests/macros.rs
+++ b/crates/hir-ty/src/tests/macros.rs
@@ -63,10 +63,10 @@ fn infer_macros_expanded() {
}
"#,
expect![[r#"
- !0..21 '{Foo(v...2),])}': Foo
+ !0..17 '{Foo(v...,2,])}': Foo
!1..4 'Foo': Foo({unknown}) -> Foo
- !1..20 'Foo(ve...(2),])': Foo
- !5..19 'vec![(1),(2),]': {unknown}
+ !1..16 'Foo(vec![1,2,])': Foo
+ !5..15 'vec![1,2,]': {unknown}
155..181 '{ ...,2); }': ()
165..166 'x': Foo
"#]],
@@ -96,10 +96,10 @@ fn infer_legacy_textual_scoped_macros_expanded() {
}
"#,
expect![[r#"
- !0..21 '{Foo(v...2),])}': Foo
+ !0..17 '{Foo(v...,2,])}': Foo
!1..4 'Foo': Foo({unknown}) -> Foo
- !1..20 'Foo(ve...(2),])': Foo
- !5..19 'vec![(1),(2),]': {unknown}
+ !1..16 'Foo(vec![1,2,])': Foo
+ !5..15 'vec![1,2,]': {unknown}
194..250 '{ ...,2); }': ()
204..205 'x': Foo
227..228 'y': {unknown}
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 38c4f081b7..ed3d3f1a3b 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -557,11 +557,6 @@ impl<'db> SemanticsImpl<'db> {
.span_at(token.text_range().start()),
};
- // fetch span information of token in real file, then use that look through expansions of
- // calls the token is in and afterwards recursively with the same span.
- // what about things where spans change? Due to being joined etc, that is we don't find the
- // exact span anymore?
-
let def_map = sa.resolver.def_map();
let mut stack: SmallVec<[_; 4]> = smallvec![InFile::new(sa.file_id, token)];
@@ -580,7 +575,7 @@ impl<'db> SemanticsImpl<'db> {
let len = stack.len();
// requeue the tokens we got from mapping our current token down
- stack.extend(mapped_tokens);
+ stack.extend(mapped_tokens.map(Into::into));
// if the length changed we have found a mapping for the token
(stack.len() != len).then_some(())
};
diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs
index cca3e68d50..a70f335ada 100644
--- a/crates/ide/src/expand_macro.rs
+++ b/crates/ide/src/expand_macro.rs
@@ -340,8 +340,8 @@ fn main() {
expect![[r#"
match_ast!
{
- if let Some(it) = ast::TraitDef::cast((container).clone()){}
- else if let Some(it) = ast::ImplDef::cast((container).clone()){}
+ if let Some(it) = ast::TraitDef::cast(container.clone()){}
+ else if let Some(it) = ast::ImplDef::cast(container.clone()){}
else {
{
continue
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs
index f2ca9d82ed..8ebc9909b6 100644
--- a/crates/test-utils/src/minicore.rs
+++ b/crates/test-utils/src/minicore.rs
@@ -15,6 +15,7 @@
//! cell: copy, drop
//! clone: sized
//! coerce_unsized: unsize
+//! concat:
//! copy: clone
//! default: sized
//! deref_mut: deref
@@ -1353,7 +1354,7 @@ mod panicking {
mod macros {
// region:panic
#[macro_export]
- #[rustc_builtin_macro(std_panic)]
+ #[rustc_builtin_macro(core_panic)]
macro_rules! panic {
($($arg:tt)*) => {
/* compiler built-in */
@@ -1406,6 +1407,12 @@ mod macros {
($file:expr $(,)?) => {{ /* compiler built-in */ }};
}
// endregion:include
+
+ // region:concat
+ #[rustc_builtin_macro]
+ #[macro_export]
+ macro_rules! concat {}
+ // endregion:concat
}
// region:non_zero