Some more minor cleanups

This commit is contained in:
Lukas Wirth 2023-12-02 16:50:21 +01:00
parent 5edf7bddc6
commit 02a3a9438a
7 changed files with 65 additions and 21 deletions

View File

@ -4,7 +4,6 @@
mod input; mod input;
mod change; mod change;
// FIXME: Is this purely a test util mod? Consider #[cfg(test)] gating it.
pub mod fixture; pub mod fixture;
pub mod span; pub mod span;

View File

@ -2,7 +2,6 @@ mod block;
use base_db::{fixture::WithFixture, SourceDatabase}; use base_db::{fixture::WithFixture, SourceDatabase};
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use hir_expand::db::ExpandDatabase;
use crate::{test_db::TestDB, ModuleDefId}; 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(), &[]); assert_eq!(db.body_with_source_map(def.into()).1.diagnostics(), &[]);
expect![[r#" expect![[r#"
@ -288,3 +286,49 @@ impl SsrError {
}"#]] }"#]]
.assert_eq(&body.pretty_print(&db, def)) .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))
}

View File

@ -628,14 +628,13 @@ impl ExpansionInfo {
span: SpanData, span: SpanData,
// FIXME: use this for range mapping, so that we can resolve inline format args // FIXME: use this for range mapping, so that we can resolve inline format args
_relative_token_offset: Option<TextSize>, _relative_token_offset: Option<TextSize>,
// FIXME: ret ty should be wrapped in InMacroFile ) -> Option<impl Iterator<Item = InMacroFile<SyntaxToken>> + 'a> {
) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + 'a> {
let tokens = self let tokens = self
.exp_map .exp_map
.ranges_with_span(span) .ranges_with_span(span)
.flat_map(move |range| self.expanded.value.covering_element(range).into_token()); .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. /// Maps up the text range out of the expansion hierarchy back into the original file its from.

View File

@ -63,10 +63,10 @@ fn infer_macros_expanded() {
} }
"#, "#,
expect![[r#" expect![[r#"
!0..21 '{Foo(v...2),])}': Foo !0..17 '{Foo(v...,2,])}': Foo
!1..4 'Foo': Foo({unknown}) -> Foo !1..4 'Foo': Foo({unknown}) -> Foo
!1..20 'Foo(ve...(2),])': Foo !1..16 'Foo(vec![1,2,])': Foo
!5..19 'vec![(1),(2),]': {unknown} !5..15 'vec![1,2,]': {unknown}
155..181 '{ ...,2); }': () 155..181 '{ ...,2); }': ()
165..166 'x': Foo 165..166 'x': Foo
"#]], "#]],
@ -96,10 +96,10 @@ fn infer_legacy_textual_scoped_macros_expanded() {
} }
"#, "#,
expect![[r#" expect![[r#"
!0..21 '{Foo(v...2),])}': Foo !0..17 '{Foo(v...,2,])}': Foo
!1..4 'Foo': Foo({unknown}) -> Foo !1..4 'Foo': Foo({unknown}) -> Foo
!1..20 'Foo(ve...(2),])': Foo !1..16 'Foo(vec![1,2,])': Foo
!5..19 'vec![(1),(2),]': {unknown} !5..15 'vec![1,2,]': {unknown}
194..250 '{ ...,2); }': () 194..250 '{ ...,2); }': ()
204..205 'x': Foo 204..205 'x': Foo
227..228 'y': {unknown} 227..228 'y': {unknown}

View File

@ -557,11 +557,6 @@ impl<'db> SemanticsImpl<'db> {
.span_at(token.text_range().start()), .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 def_map = sa.resolver.def_map();
let mut stack: SmallVec<[_; 4]> = smallvec![InFile::new(sa.file_id, token)]; let mut stack: SmallVec<[_; 4]> = smallvec![InFile::new(sa.file_id, token)];
@ -580,7 +575,7 @@ impl<'db> SemanticsImpl<'db> {
let len = stack.len(); let len = stack.len();
// requeue the tokens we got from mapping our current token down // 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 // if the length changed we have found a mapping for the token
(stack.len() != len).then_some(()) (stack.len() != len).then_some(())
}; };

View File

@ -340,8 +340,8 @@ fn main() {
expect![[r#" expect![[r#"
match_ast! match_ast!
{ {
if let Some(it) = ast::TraitDef::cast((container).clone()){} if let Some(it) = ast::TraitDef::cast(container.clone()){}
else if let Some(it) = ast::ImplDef::cast((container).clone()){} else if let Some(it) = ast::ImplDef::cast(container.clone()){}
else { else {
{ {
continue continue

View File

@ -15,6 +15,7 @@
//! cell: copy, drop //! cell: copy, drop
//! clone: sized //! clone: sized
//! coerce_unsized: unsize //! coerce_unsized: unsize
//! concat:
//! copy: clone //! copy: clone
//! default: sized //! default: sized
//! deref_mut: deref //! deref_mut: deref
@ -1353,7 +1354,7 @@ mod panicking {
mod macros { mod macros {
// region:panic // region:panic
#[macro_export] #[macro_export]
#[rustc_builtin_macro(std_panic)] #[rustc_builtin_macro(core_panic)]
macro_rules! panic { macro_rules! panic {
($($arg:tt)*) => { ($($arg:tt)*) => {
/* compiler built-in */ /* compiler built-in */
@ -1406,6 +1407,12 @@ mod macros {
($file:expr $(,)?) => {{ /* compiler built-in */ }}; ($file:expr $(,)?) => {{ /* compiler built-in */ }};
} }
// endregion:include // endregion:include
// region:concat
#[rustc_builtin_macro]
#[macro_export]
macro_rules! concat {}
// endregion:concat
} }
// region:non_zero // region:non_zero