Skip to content

Commit 02a3a94

Browse files
committed
Some more minor cleanups
1 parent 5edf7bd commit 02a3a94

File tree

7 files changed

+65
-21
lines changed

7 files changed

+65
-21
lines changed

crates/base-db/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
mod input;
66
mod change;
7-
// FIXME: Is this purely a test util mod? Consider #[cfg(test)] gating it.
87
pub mod fixture;
98
pub mod span;
109

crates/hir-def/src/body/tests.rs

+46-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod block;
22

33
use base_db::{fixture::WithFixture, SourceDatabase};
44
use expect_test::{expect, Expect};
5-
use hir_expand::db::ExpandDatabase;
65

76
use crate::{test_db::TestDB, ModuleDefId};
87

@@ -255,7 +254,6 @@ impl SsrError {
255254
}
256255
"##,
257256
);
258-
println!("{}", db.dump_syntax_contexts());
259257

260258
assert_eq!(db.body_with_source_map(def.into()).1.diagnostics(), &[]);
261259
expect![[r#"
@@ -288,3 +286,49 @@ impl SsrError {
288286
}"#]]
289287
.assert_eq(&body.pretty_print(&db, def))
290288
}
289+
290+
#[test]
291+
fn regression_10300() {
292+
let (db, body, def) = lower(
293+
r#"
294+
//- minicore: concat, panic
295+
mod private {
296+
pub use core::concat;
297+
}
298+
299+
macro_rules! m {
300+
() => {
301+
panic!(concat!($crate::private::concat!("cc")));
302+
};
303+
}
304+
305+
fn f() {
306+
m!();
307+
}
308+
"#,
309+
);
310+
311+
let (_, source_map) = db.body_with_source_map(def.into());
312+
assert_eq!(source_map.diagnostics(), &[]);
313+
314+
for (_, def_map) in body.blocks(&db) {
315+
assert_eq!(def_map.diagnostics(), &[]);
316+
}
317+
318+
expect![[r#"
319+
fn f() {
320+
$crate::panicking::panic_fmt(
321+
builtin#lang(Arguments::new_v1_formatted)(
322+
&[
323+
"\"cc\"",
324+
],
325+
&[],
326+
&[],
327+
unsafe {
328+
builtin#lang(UnsafeArg::new)()
329+
},
330+
),
331+
);
332+
}"#]]
333+
.assert_eq(&body.pretty_print(&db, def))
334+
}

crates/hir-expand/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,13 @@ impl ExpansionInfo {
628628
span: SpanData,
629629
// FIXME: use this for range mapping, so that we can resolve inline format args
630630
_relative_token_offset: Option<TextSize>,
631-
// FIXME: ret ty should be wrapped in InMacroFile
632-
) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + 'a> {
631+
) -> Option<impl Iterator<Item = InMacroFile<SyntaxToken>> + 'a> {
633632
let tokens = self
634633
.exp_map
635634
.ranges_with_span(span)
636635
.flat_map(move |range| self.expanded.value.covering_element(range).into_token());
637636

638-
Some(tokens.map(move |token| InFile::new(self.expanded.file_id.into(), token)))
637+
Some(tokens.map(move |token| InMacroFile::new(self.expanded.file_id, token)))
639638
}
640639

641640
/// Maps up the text range out of the expansion hierarchy back into the original file its from.

crates/hir-ty/src/tests/macros.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ fn infer_macros_expanded() {
6363
}
6464
"#,
6565
expect![[r#"
66-
!0..21 '{Foo(v...2),])}': Foo
66+
!0..17 '{Foo(v...,2,])}': Foo
6767
!1..4 'Foo': Foo({unknown}) -> Foo
68-
!1..20 'Foo(ve...(2),])': Foo
69-
!5..19 'vec![(1),(2),]': {unknown}
68+
!1..16 'Foo(vec![1,2,])': Foo
69+
!5..15 'vec![1,2,]': {unknown}
7070
155..181 '{ ...,2); }': ()
7171
165..166 'x': Foo
7272
"#]],
@@ -96,10 +96,10 @@ fn infer_legacy_textual_scoped_macros_expanded() {
9696
}
9797
"#,
9898
expect![[r#"
99-
!0..21 '{Foo(v...2),])}': Foo
99+
!0..17 '{Foo(v...,2,])}': Foo
100100
!1..4 'Foo': Foo({unknown}) -> Foo
101-
!1..20 'Foo(ve...(2),])': Foo
102-
!5..19 'vec![(1),(2),]': {unknown}
101+
!1..16 'Foo(vec![1,2,])': Foo
102+
!5..15 'vec![1,2,]': {unknown}
103103
194..250 '{ ...,2); }': ()
104104
204..205 'x': Foo
105105
227..228 'y': {unknown}

crates/hir/src/semantics.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,6 @@ impl<'db> SemanticsImpl<'db> {
557557
.span_at(token.text_range().start()),
558558
};
559559

560-
// fetch span information of token in real file, then use that look through expansions of
561-
// calls the token is in and afterwards recursively with the same span.
562-
// what about things where spans change? Due to being joined etc, that is we don't find the
563-
// exact span anymore?
564-
565560
let def_map = sa.resolver.def_map();
566561
let mut stack: SmallVec<[_; 4]> = smallvec![InFile::new(sa.file_id, token)];
567562

@@ -580,7 +575,7 @@ impl<'db> SemanticsImpl<'db> {
580575
let len = stack.len();
581576

582577
// requeue the tokens we got from mapping our current token down
583-
stack.extend(mapped_tokens);
578+
stack.extend(mapped_tokens.map(Into::into));
584579
// if the length changed we have found a mapping for the token
585580
(stack.len() != len).then_some(())
586581
};

crates/ide/src/expand_macro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ fn main() {
340340
expect![[r#"
341341
match_ast!
342342
{
343-
if let Some(it) = ast::TraitDef::cast((container).clone()){}
344-
else if let Some(it) = ast::ImplDef::cast((container).clone()){}
343+
if let Some(it) = ast::TraitDef::cast(container.clone()){}
344+
else if let Some(it) = ast::ImplDef::cast(container.clone()){}
345345
else {
346346
{
347347
continue

crates/test-utils/src/minicore.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! cell: copy, drop
1616
//! clone: sized
1717
//! coerce_unsized: unsize
18+
//! concat:
1819
//! copy: clone
1920
//! default: sized
2021
//! deref_mut: deref
@@ -1353,7 +1354,7 @@ mod panicking {
13531354
mod macros {
13541355
// region:panic
13551356
#[macro_export]
1356-
#[rustc_builtin_macro(std_panic)]
1357+
#[rustc_builtin_macro(core_panic)]
13571358
macro_rules! panic {
13581359
($($arg:tt)*) => {
13591360
/* compiler built-in */
@@ -1406,6 +1407,12 @@ mod macros {
14061407
($file:expr $(,)?) => {{ /* compiler built-in */ }};
14071408
}
14081409
// endregion:include
1410+
1411+
// region:concat
1412+
#[rustc_builtin_macro]
1413+
#[macro_export]
1414+
macro_rules! concat {}
1415+
// endregion:concat
14091416
}
14101417

14111418
// region:non_zero

0 commit comments

Comments
 (0)