Skip to content

Commit 779d9ee

Browse files
committed
Auto merge of #17967 - Veykril:mbe-tests, r=Veykril
internal: Lay basic ground work for standalone mbe tests Most of our mbe hir-def tests don't actually do anything name res relevant, we can (and should) move those down the stack into `mbe/hir-expand`.
2 parents bae4951 + 4502a60 commit 779d9ee

File tree

15 files changed

+288
-76
lines changed

15 files changed

+288
-76
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir-def/src/macro_expansion_tests/mbe.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ m! { foo# bar }
389389
390390
m! { Foo,# Bar }
391391
"#,
392-
expect![[r##"
392+
expect![[r#"
393393
macro_rules! m {
394394
($($i:ident),*) => ($(mod $i {} )*);
395395
($($i:ident)#*) => ($(fn $i() {} )*);
@@ -404,27 +404,29 @@ fn bar() {}
404404
405405
struct Foo;
406406
struct Bar;
407-
"##]],
407+
"#]],
408408
);
409409
}
410410

411411
#[test]
412412
fn test_match_group_pattern_with_multiple_defs() {
413+
// FIXME: The pretty printer breaks by leaving whitespace here, +syntaxctxt is used to avoid that
413414
check(
414415
r#"
415416
macro_rules! m {
416417
($($i:ident),*) => ( impl Bar { $(fn $i() {})* } );
417418
}
419+
// +syntaxctxt
418420
m! { foo, bar }
419421
"#,
420422
expect![[r#"
421423
macro_rules! m {
422424
($($i:ident),*) => ( impl Bar { $(fn $i() {})* } );
423425
}
424-
impl Bar {
425-
fn foo() {}
426-
fn bar() {}
427-
}
426+
impl#\1# Bar#\1# {#\1#
427+
fn#\1# foo#\0#(#\1#)#\1# {#\1#}#\1#
428+
fn#\1# bar#\0#(#\1#)#\1# {#\1#}#\1#
429+
}#\1#
428430
"#]],
429431
);
430432
}
@@ -480,12 +482,12 @@ macro_rules! m {
480482
}
481483
m!{#abc}
482484
"#,
483-
expect![[r##"
485+
expect![[r#"
484486
macro_rules! m {
485487
($($i:ident)* #abc) => ( fn baz() { $($i ();)* } );
486488
}
487489
fn baz() {}
488-
"##]],
490+
"#]],
489491
)
490492
}
491493

@@ -1189,13 +1191,13 @@ macro_rules! m {
11891191
m! { cfg(target_os = "windows") }
11901192
m! { hello::world }
11911193
"#,
1192-
expect![[r##"
1194+
expect![[r#"
11931195
macro_rules! m {
11941196
($m:meta) => ( #[$m] fn bar() {} )
11951197
}
11961198
#[cfg(target_os = "windows")] fn bar() {}
11971199
#[hello::world] fn bar() {}
1198-
"##]],
1200+
"#]],
11991201
);
12001202
}
12011203

@@ -1213,15 +1215,15 @@ m! {
12131215
*/
12141216
}
12151217
"#,
1216-
expect![[r##"
1218+
expect![[r#"
12171219
macro_rules! m {
12181220
($(#[$m:meta])+) => ( $(#[$m])+ fn bar() {} )
12191221
}
12201222
#[doc = r" Single Line Doc 1"]
12211223
#[doc = r"
12221224
MultiLines Doc
12231225
"] fn bar() {}
1224-
"##]],
1226+
"#]],
12251227
);
12261228
}
12271229

@@ -1234,12 +1236,12 @@ macro_rules! m {
12341236
}
12351237
m! { #[doc = concat!("The `", "bla", "` lang item.")] }
12361238
"#,
1237-
expect![[r##"
1239+
expect![[r#"
12381240
macro_rules! m {
12391241
(#[$m:meta]) => ( #[$m] fn bar() {} )
12401242
}
12411243
#[doc = concat!("The `", "bla", "` lang item.")] fn bar() {}
1242-
"##]],
1244+
"#]],
12431245
);
12441246
}
12451247

@@ -1257,15 +1259,15 @@ m! {
12571259
*/
12581260
}
12591261
"#,
1260-
expect![[r##"
1262+
expect![[r#"
12611263
macro_rules! m {
12621264
($(#[$ m:meta])+) => ( $(#[$m])+ fn bar() {} )
12631265
}
12641266
#[doc = r" 錦瑟無端五十弦,一弦一柱思華年。"]
12651267
#[doc = r"
12661268
莊生曉夢迷蝴蝶,望帝春心託杜鵑。
12671269
"] fn bar() {}
1268-
"##]],
1270+
"#]],
12691271
);
12701272
}
12711273

@@ -1342,10 +1344,10 @@ fn test_tt_composite2() {
13421344
macro_rules! m { ($($tt:tt)*) => { abs!(=> $($tt)*); } }
13431345
m! {#}
13441346
"#,
1345-
expect![[r##"
1347+
expect![[r#"
13461348
macro_rules! m { ($($tt:tt)*) => { abs!(=> $($tt)*); } }
13471349
abs!( = > #);
1348-
"##]],
1350+
"#]],
13491351
);
13501352
}
13511353

crates/hir-def/src/macro_expansion_tests/mbe/regression.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ STRUCT!{struct D3DVSHADERCAPS2_0 {Caps: u8,}}
139139
140140
STRUCT!{#[cfg_attr(target_arch = "x86", repr(packed))] struct D3DCONTENTPROTECTIONCAPS {Caps : u8 ,}}
141141
"#,
142-
expect![[r##"
142+
expect![[r#"
143143
macro_rules! STRUCT {
144144
($(#[$attrs:meta])* struct $name:ident {
145145
$($field:ident: $ftype:ty,)+
@@ -194,7 +194,7 @@ impl Clone for D3DCONTENTPROTECTIONCAPS {
194194
}
195195
}
196196
}
197-
"##]],
197+
"#]],
198198
);
199199
}
200200

@@ -214,7 +214,7 @@ macro_rules! int_base {
214214
}
215215
int_base!{Binary for isize as usize -> Binary}
216216
"#,
217-
expect![[r##"
217+
expect![[r#"
218218
macro_rules! int_base {
219219
($Trait:ident for $T:ident as $U:ident -> $Radix:ident) => {
220220
#[stable(feature = "rust1", since = "1.0.0")]
@@ -230,7 +230,7 @@ macro_rules! int_base {
230230
Binary.fmt_int(*self as usize, f)
231231
}
232232
}
233-
"##]],
233+
"#]],
234234
);
235235
}
236236

@@ -318,7 +318,7 @@ impl_fn_for_zst ! {
318318
}
319319
320320
"#,
321-
expect![[r##"
321+
expect![[r#"
322322
macro_rules! impl_fn_for_zst {
323323
{$( $( #[$attr: meta] )*
324324
struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn =
@@ -410,7 +410,7 @@ impl FnOnce<(char, )> for CharEscapeDefault {
410410
}
411411
}
412412
413-
"##]],
413+
"#]],
414414
);
415415
}
416416

@@ -511,7 +511,7 @@ cfg_if! {
511511
@__apply cfg(all(not(any(not(any(target_os = "solaris", target_os = "illumos")))))),
512512
}
513513
"#,
514-
expect![[r##"
514+
expect![[r#"
515515
macro_rules! cfg_if {
516516
($(if #[cfg($($meta:meta),*)] { $($it:item)* } )else* else { $($it2:item)* })
517517
=> {
@@ -534,7 +534,7 @@ __cfg_if_items! {
534534
}
535535
536536
537-
"##]],
537+
"#]],
538538
);
539539
}
540540

@@ -618,7 +618,7 @@ RIDL!{interface ID3D11Asynchronous(ID3D11AsynchronousVtbl): ID3D11DeviceChild(ID
618618
fn GetDataSize(&mut self) -> UINT
619619
}}
620620
"#,
621-
expect![[r##"
621+
expect![[r#"
622622
#[macro_export]
623623
macro_rules! RIDL {
624624
(interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident)
@@ -639,7 +639,7 @@ impl ID3D11Asynchronous {
639639
((*self .lpVtbl).GetDataSize)(self )
640640
}
641641
}
642-
"##]],
642+
"#]],
643643
);
644644
}
645645

@@ -676,7 +676,7 @@ quick_error ! (
676676
);
677677
678678
"#,
679-
expect![[r##"
679+
expect![[r#"
680680
macro_rules! quick_error {
681681
(SORT [enum $name:ident $( #[$meta:meta] )*]
682682
items [$($( #[$imeta:meta] )*
@@ -697,7 +697,7 @@ macro_rules! quick_error {
697697
}
698698
quick_error!(ENUMINITION[enum Wrapped#[derive(Debug)]]body[]queue[ = > One: UNIT[] = > Two: TUPLE[s: String]]);
699699
700-
"##]],
700+
"#]],
701701
)
702702
}
703703

@@ -746,7 +746,7 @@ delegate_impl ! {
746746
[G, &'a mut G, deref] pub trait Data: GraphBase {@section type type NodeWeight;}
747747
}
748748
"#,
749-
expect![[r##"
749+
expect![[r#"
750750
macro_rules! delegate_impl {
751751
([$self_type:ident, $self_wrap:ty, $self_map:ident]
752752
pub trait $name:ident $(: $sup:ident)* $(+ $more_sup:ident)* {
@@ -785,7 +785,7 @@ macro_rules! delegate_impl {
785785
}
786786
}
787787
impl <> Data for &'amut G where G: Data {}
788-
"##]],
788+
"#]],
789789
);
790790
}
791791

@@ -959,14 +959,14 @@ macro_rules! with_std {
959959
960960
with_std! {mod m;mod f;}
961961
"#,
962-
expect![[r##"
962+
expect![[r#"
963963
macro_rules! with_std {
964964
($($i:item)*) => ($(#[cfg(feature = "std")]$i)*)
965965
}
966966
967967
#[cfg(feature = "std")] mod m;
968968
#[cfg(feature = "std")] mod f;
969-
"##]],
969+
"#]],
970970
)
971971
}
972972

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! This module contains tests for macro expansion. Effectively, it covers `tt`,
2-
//! `mbe`, `proc_macro_api` and `hir_expand` crates. This might seem like a
3-
//! wrong architecture at the first glance, but is intentional.
1+
//! This module contains integration tests for macro expansion with name resolution. Effectively, it
2+
//! covers `tt`, `mbe`, `proc_macro_api` and `hir_expand` crates. This might seem like a wrong
3+
//! architecture at the first glance, but is intentional.
44
//!
55
//! Physically, macro expansion process is intertwined with name resolution. You
66
//! can not expand *just* the syntax. So, to be able to write integration tests

crates/hir-def/src/macro_expansion_tests/proc_macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ fn attribute_macro_attr_censoring() {
1616
#[attr1] #[proc_macros::identity] #[attr2]
1717
struct S;
1818
"#,
19-
expect![[r##"
19+
expect![[r#"
2020
#[attr1] #[proc_macros::identity] #[attr2]
2121
struct S;
2222
2323
#[attr1]
24-
#[attr2] struct S;"##]],
24+
#[attr2] struct S;"#]],
2525
);
2626
}
2727

@@ -39,7 +39,7 @@ fn derive_censoring() {
3939
#[attr2]
4040
struct S;
4141
"#,
42-
expect![[r##"
42+
expect![[r#"
4343
#[attr1]
4444
#[derive(Foo)]
4545
#[derive(proc_macros::DeriveIdentity)]
@@ -49,7 +49,7 @@ struct S;
4949
5050
#[attr1]
5151
#[derive(Bar)]
52-
#[attr2] struct S;"##]],
52+
#[attr2] struct S;"#]],
5353
);
5454
}
5555

@@ -62,14 +62,14 @@ fn attribute_macro_syntax_completion_1() {
6262
#[proc_macros::identity_when_valid]
6363
fn foo() { bar.baz(); blub }
6464
"#,
65-
expect![[r##"
65+
expect![[r#"
6666
#[proc_macros::identity_when_valid]
6767
fn foo() { bar.baz(); blub }
6868
6969
fn foo() {
7070
bar.baz();
7171
blub
72-
}"##]],
72+
}"#]],
7373
);
7474
}
7575

crates/hir-expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub use crate::files::{AstId, ErasedAstId, FileRange, InFile, InMacroFile, InRea
5555

5656
pub use mbe::{DeclarativeMacro, ValueResult};
5757
pub use span::{HirFileId, MacroCallId, MacroFileId};
58+
pub use syntax_bridge::insert_whitespace_into_node;
5859

5960
pub mod tt {
6061
pub use span::Span;

crates/hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub use {
136136
},
137137
hygiene::{marks_rev, SyntaxContextExt},
138138
inert_attr_macro::AttributeTemplate,
139+
insert_whitespace_into_node,
139140
name::Name,
140141
proc_macro::{ProcMacros, ProcMacrosBuilder},
141142
tt, ExpandResult, HirFileId, HirFileIdExt, MacroFileId, MacroFileIdExt,

crates/ide-db/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod generated {
3636
pub mod syntax_helpers {
3737
pub mod format_string;
3838
pub mod format_string_exprs;
39-
pub mod insert_whitespace_into_node;
39+
pub use hir::insert_whitespace_into_node;
4040
pub mod node_ext;
4141

4242
pub use parser::LexedStr;

0 commit comments

Comments
 (0)