@@ -2,6 +2,7 @@ mod block;
22
33use base_db:: { fixture:: WithFixture , SourceDatabase } ;
44use expect_test:: { expect, Expect } ;
5+ use hir_expand:: db:: ExpandDatabase ;
56
67use crate :: { test_db:: TestDB , ModuleDefId } ;
78
@@ -143,7 +144,6 @@ mod m {
143144
144145#[ test]
145146fn desugar_builtin_format_args ( ) {
146- // Regression test for a path resolution bug introduced with inner item handling.
147147 let ( db, body, def) = lower (
148148 r#"
149149//- minicore: fmt
@@ -221,3 +221,70 @@ fn main() {
221221 }"# ] ]
222222 . assert_eq ( & body. pretty_print ( & db, def) )
223223}
224+
225+ #[ test]
226+ fn test_macro_hygiene ( ) {
227+ let ( db, body, def) = lower (
228+ r##"
229+ //- minicore: fmt, from
230+ //- /main.rs
231+ mod error;
232+
233+ use crate::error::error;
234+
235+ fn main() {
236+ // _ = forces body expansion instead of block def map expansion
237+ _ = error!("Failed to resolve path `{}`", node.text());
238+ }
239+ //- /error.rs
240+ macro_rules! _error {
241+ ($fmt:expr, $($arg:tt)+) => {$crate::error::intermediate!(format_args!($fmt, $($arg)+))}
242+ }
243+ pub(crate) use _error as error;
244+ macro_rules! _intermediate {
245+ ($arg:expr) => {$crate::error::SsrError::new($arg)}
246+ }
247+ pub(crate) use _intermediate as intermediate;
248+
249+ pub struct SsrError(pub(crate) core::fmt::Arguments);
250+
251+ impl SsrError {
252+ pub(crate) fn new(message: impl Into<core::fmt::Arguments>) -> SsrError {
253+ SsrError(message.into())
254+ }
255+ }
256+ "## ,
257+ ) ;
258+ println ! ( "{}" , db. dump_syntax_contexts( ) ) ;
259+
260+ assert_eq ! ( db. body_with_source_map( def. into( ) ) . 1 . diagnostics( ) , & [ ] ) ;
261+ expect ! [ [ r#"
262+ fn main() {
263+ _ = $crate::error::SsrError::new(
264+ builtin#lang(Arguments::new_v1_formatted)(
265+ &[
266+ "\"Failed to resolve path `", "`\"",
267+ ],
268+ &[
269+ builtin#lang(Argument::new_display)(
270+ &node.text(),
271+ ),
272+ ],
273+ &[
274+ builtin#lang(Placeholder::new)(
275+ 0usize,
276+ ' ',
277+ builtin#lang(Alignment::Unknown),
278+ 0u32,
279+ builtin#lang(Count::Implied),
280+ builtin#lang(Count::Implied),
281+ ),
282+ ],
283+ unsafe {
284+ builtin#lang(UnsafeArg::new)()
285+ },
286+ ),
287+ );
288+ }"# ] ]
289+ . assert_eq ( & body. pretty_print ( & db, def) )
290+ }
0 commit comments